Text add fontStype property
This commit is contained in:
parent
e8a5c796bd
commit
c92435f1e0
@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package pub.doric.shader;
|
package pub.doric.shader;
|
||||||
|
|
||||||
|
import android.graphics.Typeface;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
@ -61,6 +62,21 @@ public class TextNode extends ViewNode<TextView> {
|
|||||||
case "maxLines":
|
case "maxLines":
|
||||||
view.setMaxLines(prop.asNumber().toInt());
|
view.setMaxLines(prop.asNumber().toInt());
|
||||||
break;
|
break;
|
||||||
|
case "fontStyle":
|
||||||
|
if (prop.isString()) {
|
||||||
|
if ("bold".equals(prop.asString().value())) {
|
||||||
|
view.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
|
||||||
|
} else if ("italic".equals(prop.asString().value())) {
|
||||||
|
view.setTypeface(Typeface.defaultFromStyle(Typeface.ITALIC));
|
||||||
|
} else if ("bold_italic".equals(prop.asString().value())) {
|
||||||
|
view.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD_ITALIC));
|
||||||
|
} else {
|
||||||
|
view.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
view.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
super.blend(view, name, prop);
|
super.blend(view, name, prop);
|
||||||
break;
|
break;
|
||||||
|
60
doric-demo/src/TextDemo.ts
Normal file
60
doric-demo/src/TextDemo.ts
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
import { Panel, Group, scroller, vlayout, layoutConfig, LayoutSpec, Input, Gravity, log, input, text } from "doric";
|
||||||
|
import { title } from "./utils";
|
||||||
|
@Entry
|
||||||
|
class TextDemo extends Panel {
|
||||||
|
build(root: Group) {
|
||||||
|
scroller(
|
||||||
|
vlayout(
|
||||||
|
[
|
||||||
|
title("Text Demo"),
|
||||||
|
text({
|
||||||
|
text: "This is normal text",
|
||||||
|
}),
|
||||||
|
text({
|
||||||
|
text: "This is normal text",
|
||||||
|
textSize: 20,
|
||||||
|
}),
|
||||||
|
text({
|
||||||
|
text: "This is normal text",
|
||||||
|
textSize: 30,
|
||||||
|
}),
|
||||||
|
text({
|
||||||
|
text: "This is bold text",
|
||||||
|
fontStyle: "bold",
|
||||||
|
}),
|
||||||
|
text({
|
||||||
|
text: "This is bold text",
|
||||||
|
textSize: 30,
|
||||||
|
fontStyle: "bold"
|
||||||
|
}),
|
||||||
|
text({
|
||||||
|
text: "This is italic text",
|
||||||
|
fontStyle: "italic"
|
||||||
|
}),
|
||||||
|
text({
|
||||||
|
text: "This is italic text",
|
||||||
|
textSize: 30,
|
||||||
|
fontStyle: "italic"
|
||||||
|
}),
|
||||||
|
text({
|
||||||
|
text: "This is bold_italic text",
|
||||||
|
fontStyle: "bold_italic"
|
||||||
|
}),
|
||||||
|
text({
|
||||||
|
text: "This is bold_italic text",
|
||||||
|
textSize: 30,
|
||||||
|
fontStyle: "bold_italic"
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
{
|
||||||
|
space: 10,
|
||||||
|
layoutConfig: layoutConfig().most().configHeight(LayoutSpec.FIT)
|
||||||
|
}
|
||||||
|
),
|
||||||
|
{
|
||||||
|
layoutConfig: layoutConfig().most()
|
||||||
|
}
|
||||||
|
).in(root)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -36,7 +36,12 @@ - (void)blendView:(UILabel *)view forPropName:(NSString *)name propValue:(id)pro
|
|||||||
if ([name isEqualToString:@"text"]) {
|
if ([name isEqualToString:@"text"]) {
|
||||||
view.text = prop;
|
view.text = prop;
|
||||||
} else if ([name isEqualToString:@"textSize"]) {
|
} else if ([name isEqualToString:@"textSize"]) {
|
||||||
view.font = [UIFont systemFontOfSize:[(NSNumber *) prop floatValue]];
|
UIFont *font = view.font;
|
||||||
|
if (font) {
|
||||||
|
view.font = [view.font fontWithSize:[(NSNumber *) prop floatValue]];
|
||||||
|
} else {
|
||||||
|
view.font = [UIFont systemFontOfSize:[(NSNumber *) prop floatValue]];
|
||||||
|
}
|
||||||
} else if ([name isEqualToString:@"textColor"]) {
|
} else if ([name isEqualToString:@"textColor"]) {
|
||||||
view.textColor = DoricColor(prop);
|
view.textColor = DoricColor(prop);
|
||||||
} else if ([name isEqualToString:@"textAlignment"]) {
|
} else if ([name isEqualToString:@"textAlignment"]) {
|
||||||
@ -50,6 +55,23 @@ - (void)blendView:(UILabel *)view forPropName:(NSString *)name propValue:(id)pro
|
|||||||
view.textAlignment = alignment;
|
view.textAlignment = alignment;
|
||||||
} else if ([name isEqualToString:@"maxLines"]) {
|
} else if ([name isEqualToString:@"maxLines"]) {
|
||||||
view.numberOfLines = [prop integerValue];
|
view.numberOfLines = [prop integerValue];
|
||||||
|
} else if ([name isEqualToString:@"fontStyle"]) {
|
||||||
|
UIFont *font = view.font;
|
||||||
|
if (!font) {
|
||||||
|
font = [UIFont systemFontOfSize:[UIFont systemFontSize]];
|
||||||
|
}
|
||||||
|
UIFontDescriptor *fontDescriptor = nil;
|
||||||
|
if ([@"bold" isEqualToString:prop]) {
|
||||||
|
fontDescriptor = [font.fontDescriptor fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitBold];
|
||||||
|
} else if ([@"italic" isEqualToString:prop]) {
|
||||||
|
fontDescriptor = [font.fontDescriptor fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitItalic];
|
||||||
|
} else if ([@"bold_italic" isEqualToString:prop]) {
|
||||||
|
fontDescriptor = [font.fontDescriptor fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitBold | UIFontDescriptorTraitItalic];
|
||||||
|
}
|
||||||
|
if (fontDescriptor) {
|
||||||
|
font = [UIFont fontWithDescriptor:fontDescriptor size:0];
|
||||||
|
}
|
||||||
|
view.font = font;
|
||||||
} else {
|
} else {
|
||||||
[super blendView:view forPropName:name propValue:prop];
|
[super blendView:view forPropName:name propValue:prop];
|
||||||
}
|
}
|
||||||
|
@ -506,6 +506,8 @@ class Gravity {
|
|||||||
}
|
}
|
||||||
Gravity.origin = new Gravity;
|
Gravity.origin = new Gravity;
|
||||||
Gravity.Center = Gravity.origin.center();
|
Gravity.Center = Gravity.origin.center();
|
||||||
|
Gravity.CenterX = Gravity.origin.centerX();
|
||||||
|
Gravity.CenterY = Gravity.origin.centerY();
|
||||||
Gravity.Left = Gravity.origin.left();
|
Gravity.Left = Gravity.origin.left();
|
||||||
Gravity.Right = Gravity.origin.right();
|
Gravity.Right = Gravity.origin.right();
|
||||||
Gravity.Top = Gravity.origin.top();
|
Gravity.Top = Gravity.origin.top();
|
||||||
@ -1180,6 +1182,10 @@ __decorate$3([
|
|||||||
Property,
|
Property,
|
||||||
__metadata$3("design:type", Gravity)
|
__metadata$3("design:type", Gravity)
|
||||||
], Text.prototype, "textAlignment", void 0);
|
], Text.prototype, "textAlignment", void 0);
|
||||||
|
__decorate$3([
|
||||||
|
Property,
|
||||||
|
__metadata$3("design:type", String)
|
||||||
|
], Text.prototype, "fontStyle", void 0);
|
||||||
function text(config) {
|
function text(config) {
|
||||||
const ret = new Text;
|
const ret = new Text;
|
||||||
ret.layoutConfig = layoutConfig().fit();
|
ret.layoutConfig = layoutConfig().fit();
|
||||||
|
@ -1965,6 +1965,8 @@ class Gravity {
|
|||||||
}
|
}
|
||||||
Gravity.origin = new Gravity;
|
Gravity.origin = new Gravity;
|
||||||
Gravity.Center = Gravity.origin.center();
|
Gravity.Center = Gravity.origin.center();
|
||||||
|
Gravity.CenterX = Gravity.origin.centerX();
|
||||||
|
Gravity.CenterY = Gravity.origin.centerY();
|
||||||
Gravity.Left = Gravity.origin.left();
|
Gravity.Left = Gravity.origin.left();
|
||||||
Gravity.Right = Gravity.origin.right();
|
Gravity.Right = Gravity.origin.right();
|
||||||
Gravity.Top = Gravity.origin.top();
|
Gravity.Top = Gravity.origin.top();
|
||||||
@ -2639,6 +2641,10 @@ __decorate$3([
|
|||||||
Property,
|
Property,
|
||||||
__metadata$3("design:type", Gravity)
|
__metadata$3("design:type", Gravity)
|
||||||
], Text.prototype, "textAlignment", void 0);
|
], Text.prototype, "textAlignment", void 0);
|
||||||
|
__decorate$3([
|
||||||
|
Property,
|
||||||
|
__metadata$3("design:type", String)
|
||||||
|
], Text.prototype, "fontStyle", void 0);
|
||||||
function text(config) {
|
function text(config) {
|
||||||
const ret = new Text;
|
const ret = new Text;
|
||||||
ret.layoutConfig = layoutConfig().fit();
|
ret.layoutConfig = layoutConfig().fit();
|
||||||
|
4
doric-js/index.d.ts
vendored
4
doric-js/index.d.ts
vendored
@ -432,6 +432,7 @@ declare module 'doric/lib/src/widget/text' {
|
|||||||
textSize?: number;
|
textSize?: number;
|
||||||
maxLines?: number;
|
maxLines?: number;
|
||||||
textAlignment?: Gravity;
|
textAlignment?: Gravity;
|
||||||
|
fontStyle?: "normal" | "bold" | "italic" | "bold_italic";
|
||||||
}
|
}
|
||||||
export class Text extends View implements IText {
|
export class Text extends View implements IText {
|
||||||
text?: string;
|
text?: string;
|
||||||
@ -439,6 +440,7 @@ declare module 'doric/lib/src/widget/text' {
|
|||||||
textSize?: number;
|
textSize?: number;
|
||||||
maxLines?: number;
|
maxLines?: number;
|
||||||
textAlignment?: Gravity;
|
textAlignment?: Gravity;
|
||||||
|
fontStyle?: "normal" | "bold" | "italic" | "bold_italic";
|
||||||
}
|
}
|
||||||
export function text(config: IText): Text;
|
export function text(config: IText): Text;
|
||||||
}
|
}
|
||||||
@ -901,6 +903,8 @@ declare module 'doric/lib/src/util/gravity' {
|
|||||||
centerY(): Gravity;
|
centerY(): Gravity;
|
||||||
toModel(): number;
|
toModel(): number;
|
||||||
static Center: Gravity;
|
static Center: Gravity;
|
||||||
|
static CenterX: Gravity;
|
||||||
|
static CenterY: Gravity;
|
||||||
static Left: Gravity;
|
static Left: Gravity;
|
||||||
static Right: Gravity;
|
static Right: Gravity;
|
||||||
static Top: Gravity;
|
static Top: Gravity;
|
||||||
|
2
doric-js/lib/src/util/gravity.d.ts
vendored
2
doric-js/lib/src/util/gravity.d.ts
vendored
@ -18,6 +18,8 @@ export declare class Gravity implements Modeling {
|
|||||||
toModel(): number;
|
toModel(): number;
|
||||||
private static origin;
|
private static origin;
|
||||||
static Center: Gravity;
|
static Center: Gravity;
|
||||||
|
static CenterX: Gravity;
|
||||||
|
static CenterY: Gravity;
|
||||||
static Left: Gravity;
|
static Left: Gravity;
|
||||||
static Right: Gravity;
|
static Right: Gravity;
|
||||||
static Top: Gravity;
|
static Top: Gravity;
|
||||||
|
@ -62,6 +62,8 @@ export class Gravity {
|
|||||||
}
|
}
|
||||||
Gravity.origin = new Gravity;
|
Gravity.origin = new Gravity;
|
||||||
Gravity.Center = Gravity.origin.center();
|
Gravity.Center = Gravity.origin.center();
|
||||||
|
Gravity.CenterX = Gravity.origin.centerX();
|
||||||
|
Gravity.CenterY = Gravity.origin.centerY();
|
||||||
Gravity.Left = Gravity.origin.left();
|
Gravity.Left = Gravity.origin.left();
|
||||||
Gravity.Right = Gravity.origin.right();
|
Gravity.Right = Gravity.origin.right();
|
||||||
Gravity.Top = Gravity.origin.top();
|
Gravity.Top = Gravity.origin.top();
|
||||||
|
2
doric-js/lib/src/widget/text.d.ts
vendored
2
doric-js/lib/src/widget/text.d.ts
vendored
@ -7,6 +7,7 @@ export interface IText extends IView {
|
|||||||
textSize?: number;
|
textSize?: number;
|
||||||
maxLines?: number;
|
maxLines?: number;
|
||||||
textAlignment?: Gravity;
|
textAlignment?: Gravity;
|
||||||
|
fontStyle?: "normal" | "bold" | "italic" | "bold_italic";
|
||||||
}
|
}
|
||||||
export declare class Text extends View implements IText {
|
export declare class Text extends View implements IText {
|
||||||
text?: string;
|
text?: string;
|
||||||
@ -14,5 +15,6 @@ export declare class Text extends View implements IText {
|
|||||||
textSize?: number;
|
textSize?: number;
|
||||||
maxLines?: number;
|
maxLines?: number;
|
||||||
textAlignment?: Gravity;
|
textAlignment?: Gravity;
|
||||||
|
fontStyle?: "normal" | "bold" | "italic" | "bold_italic";
|
||||||
}
|
}
|
||||||
export declare function text(config: IText): Text;
|
export declare function text(config: IText): Text;
|
||||||
|
@ -48,6 +48,10 @@ __decorate([
|
|||||||
Property,
|
Property,
|
||||||
__metadata("design:type", Gravity)
|
__metadata("design:type", Gravity)
|
||||||
], Text.prototype, "textAlignment", void 0);
|
], Text.prototype, "textAlignment", void 0);
|
||||||
|
__decorate([
|
||||||
|
Property,
|
||||||
|
__metadata("design:type", String)
|
||||||
|
], Text.prototype, "fontStyle", void 0);
|
||||||
export function text(config) {
|
export function text(config) {
|
||||||
const ret = new Text;
|
const ret = new Text;
|
||||||
ret.layoutConfig = layoutConfig().fit();
|
ret.layoutConfig = layoutConfig().fit();
|
||||||
|
@ -99,6 +99,7 @@ export class Gravity implements Modeling {
|
|||||||
static Top = Gravity.origin.top()
|
static Top = Gravity.origin.top()
|
||||||
static Bottom = Gravity.origin.bottom()
|
static Bottom = Gravity.origin.bottom()
|
||||||
}
|
}
|
||||||
|
|
||||||
export function gravity() {
|
export function gravity() {
|
||||||
return new Gravity
|
return new Gravity
|
||||||
}
|
}
|
@ -24,6 +24,7 @@ export interface IText extends IView {
|
|||||||
textSize?: number
|
textSize?: number
|
||||||
maxLines?: number
|
maxLines?: number
|
||||||
textAlignment?: Gravity
|
textAlignment?: Gravity
|
||||||
|
fontStyle?: "normal" | "bold" | "italic" | "bold_italic"
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Text extends View implements IText {
|
export class Text extends View implements IText {
|
||||||
@ -41,6 +42,9 @@ export class Text extends View implements IText {
|
|||||||
|
|
||||||
@Property
|
@Property
|
||||||
textAlignment?: Gravity
|
textAlignment?: Gravity
|
||||||
|
|
||||||
|
@Property
|
||||||
|
fontStyle?: "normal" | "bold" | "italic" | "bold_italic"
|
||||||
}
|
}
|
||||||
|
|
||||||
export function text(config: IText) {
|
export function text(config: IText) {
|
||||||
|
@ -40,6 +40,9 @@ export class DoricTextNode extends DoricViewNode {
|
|||||||
v.style.alignItems = "center"
|
v.style.alignItems = "center"
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
case "fontStyle":
|
||||||
|
v.style.fontWeight = ""
|
||||||
|
break
|
||||||
default:
|
default:
|
||||||
super.blendProps(v, propName, prop)
|
super.blendProps(v, propName, prop)
|
||||||
break
|
break
|
||||||
|
Reference in New Issue
Block a user