|
@@ -7,34 +7,32 @@ using PixiEditor.Extensions.CommonApi.FlyUI.Properties;
|
|
|
using PixiEditor.Extensions.Extensions;
|
|
|
using PixiEditor.Extensions.FlyUI.Converters;
|
|
|
using FontStyle = PixiEditor.Extensions.CommonApi.FlyUI.Properties.FontStyle;
|
|
|
+using FontWeight = PixiEditor.Extensions.CommonApi.FlyUI.Properties.FontWeight;
|
|
|
|
|
|
namespace PixiEditor.Extensions.FlyUI.Elements;
|
|
|
|
|
|
-public class Text : StatelessElement, IPropertyDeserializable
|
|
|
+public class Text : LayoutElement
|
|
|
{
|
|
|
private TextWrap _textWrap = TextWrap.None;
|
|
|
private string _value = null!;
|
|
|
- private FontStyle _fontStyle = FontStyle.Normal;
|
|
|
- private double _fontSize = 12;
|
|
|
-
|
|
|
+ private TextStyle textStyle = TextStyle.Default;
|
|
|
+
|
|
|
public string Value { get => _value; set => SetField(ref _value, value); }
|
|
|
public TextWrap TextWrap { get => _textWrap; set => SetField(ref _textWrap, value); }
|
|
|
- public FontStyle FontStyle { get => _fontStyle; set => SetField(ref _fontStyle, value); }
|
|
|
- public double FontSize { get => _fontSize; set => SetField(ref _fontSize, value); }
|
|
|
|
|
|
+ public TextStyle TextStyle { get => textStyle; set => SetField(ref textStyle, value); }
|
|
|
public Text()
|
|
|
{
|
|
|
}
|
|
|
|
|
|
- public Text(string value = "", TextWrap textWrap = TextWrap.None, FontStyle fontStyle = FontStyle.Normal, double fontSize = 12)
|
|
|
+ public Text(string value = "", TextWrap textWrap = TextWrap.None, TextStyle? textStyle = null)
|
|
|
{
|
|
|
Value = value;
|
|
|
TextWrap = textWrap;
|
|
|
- FontStyle = fontStyle;
|
|
|
- FontSize = fontSize;
|
|
|
+ TextStyle = textStyle ?? TextStyle.Default;
|
|
|
}
|
|
|
|
|
|
- public override Control BuildNative()
|
|
|
+ protected override Control CreateNativeControl()
|
|
|
{
|
|
|
TextBlock textBlock = new();
|
|
|
Binding valueBinding = new()
|
|
@@ -53,36 +51,77 @@ public class Text : StatelessElement, IPropertyDeserializable
|
|
|
Binding fontStyleBinding = new()
|
|
|
{
|
|
|
Source = this,
|
|
|
- Path = nameof(FontStyle),
|
|
|
+ Path = "TextStyle.FontStyle",
|
|
|
Converter = new EnumToEnumConverter<FontStyle, Avalonia.Media.FontStyle>(),
|
|
|
};
|
|
|
|
|
|
Binding fontSizeBinding = new()
|
|
|
{
|
|
|
Source = this,
|
|
|
- Path = nameof(FontSize),
|
|
|
+ Path = "TextStyle.FontSize",
|
|
|
+ };
|
|
|
+
|
|
|
+ Binding fontWeightBinding = new()
|
|
|
+ {
|
|
|
+ Source = this,
|
|
|
+ Path = "TextStyle.FontWeight",
|
|
|
+ Converter = new EnumToEnumConverter<FontWeight, Avalonia.Media.FontWeight>(),
|
|
|
+ };
|
|
|
+
|
|
|
+ Binding fontFamilyBinding = new()
|
|
|
+ {
|
|
|
+ Source = this,
|
|
|
+ Path = "TextStyle.FontFamily",
|
|
|
+ };
|
|
|
+
|
|
|
+ Binding colorBinding = new()
|
|
|
+ {
|
|
|
+ Source = this,
|
|
|
+ Path = "TextStyle.Color",
|
|
|
+ Converter = new ColorToAvaloniaBrushConverter(),
|
|
|
};
|
|
|
|
|
|
textBlock.Bind(TextBlock.TextProperty, valueBinding);
|
|
|
textBlock.Bind(TextBlock.TextWrappingProperty, textWrapBinding);
|
|
|
- textBlock.Bind(TextBlock.FontStyleProperty, fontStyleBinding);
|
|
|
- textBlock.Bind(TextBlock.FontSizeProperty, fontSizeBinding);
|
|
|
+ if (TextStyle.FontStyle != null)
|
|
|
+ {
|
|
|
+ textBlock.Bind(TextBlock.FontStyleProperty, fontStyleBinding);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (TextStyle.FontSize != null)
|
|
|
+ {
|
|
|
+ textBlock.Bind(TextBlock.FontSizeProperty, fontSizeBinding);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (TextStyle.FontWeight != null)
|
|
|
+ {
|
|
|
+ textBlock.Bind(TextBlock.FontWeightProperty, fontWeightBinding);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (TextStyle.FontFamily != null)
|
|
|
+ {
|
|
|
+ textBlock.Bind(TextBlock.FontFamilyProperty, fontFamilyBinding);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (TextStyle.Color != null)
|
|
|
+ {
|
|
|
+ textBlock.Bind(TextBlock.ForegroundProperty, colorBinding);
|
|
|
+ }
|
|
|
+
|
|
|
return textBlock;
|
|
|
}
|
|
|
|
|
|
- public virtual IEnumerable<object> GetProperties()
|
|
|
+ protected override IEnumerable<object> GetControlProperties()
|
|
|
{
|
|
|
yield return Value;
|
|
|
yield return TextWrap;
|
|
|
- yield return FontStyle;
|
|
|
- yield return FontSize;
|
|
|
+ yield return TextStyle;
|
|
|
}
|
|
|
|
|
|
- public virtual void DeserializeProperties(ImmutableList<object> values)
|
|
|
+ protected override void DeserializeControlProperties(List<object> values)
|
|
|
{
|
|
|
Value = (string)values.ElementAtOrDefault(0);
|
|
|
TextWrap = (TextWrap)values.ElementAtOrDefault(1);
|
|
|
- FontStyle = (FontStyle)values.ElementAtOrDefault(2);
|
|
|
- FontSize = (double)values.ElementAtOrDefault(3, 12.0);
|
|
|
+ TextStyle = (TextStyle)values.ElementAtOrDefault(2, TextStyle.Default);
|
|
|
}
|
|
|
}
|