|
|
|
@ -20,6 +20,12 @@ namespace Avalonia.Controls |
|
|
|
public static readonly StyledProperty<IBrush> BackgroundProperty = |
|
|
|
Border.BackgroundProperty.AddOwner<TextBlock>(); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Defines the <see cref="Padding"/> property.
|
|
|
|
/// </summary>
|
|
|
|
public static readonly StyledProperty<Thickness> PaddingProperty = |
|
|
|
Decorator.PaddingProperty.AddOwner<TextBlock>(); |
|
|
|
|
|
|
|
// TODO: Define these attached properties elsewhere (e.g. on a Text class) and AddOwner
|
|
|
|
// them into TextBlock.
|
|
|
|
|
|
|
|
@ -29,7 +35,7 @@ namespace Avalonia.Controls |
|
|
|
public static readonly AttachedProperty<FontFamily> FontFamilyProperty = |
|
|
|
AvaloniaProperty.RegisterAttached<TextBlock, Control, FontFamily>( |
|
|
|
nameof(FontFamily), |
|
|
|
defaultValue: FontFamily.Default, |
|
|
|
defaultValue: FontFamily.Default, |
|
|
|
inherits: true); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -110,20 +116,31 @@ namespace Avalonia.Controls |
|
|
|
static TextBlock() |
|
|
|
{ |
|
|
|
ClipToBoundsProperty.OverrideDefaultValue<TextBlock>(true); |
|
|
|
|
|
|
|
AffectsRender<TextBlock>( |
|
|
|
BackgroundProperty, |
|
|
|
ForegroundProperty, |
|
|
|
FontWeightProperty, |
|
|
|
FontSizeProperty, |
|
|
|
FontStyleProperty); |
|
|
|
BackgroundProperty, ForegroundProperty, FontSizeProperty, |
|
|
|
FontWeightProperty, FontStyleProperty, TextWrappingProperty, |
|
|
|
TextTrimmingProperty, TextAlignmentProperty, FontFamilyProperty, |
|
|
|
TextDecorationsProperty, TextProperty, PaddingProperty); |
|
|
|
|
|
|
|
AffectsMeasure<TextBlock>( |
|
|
|
FontSizeProperty, FontWeightProperty, FontStyleProperty, |
|
|
|
FontFamilyProperty, TextTrimmingProperty, TextProperty, |
|
|
|
PaddingProperty); |
|
|
|
|
|
|
|
Observable.Merge( |
|
|
|
TextProperty.Changed, |
|
|
|
ForegroundProperty.Changed, |
|
|
|
TextAlignmentProperty.Changed, |
|
|
|
TextWrappingProperty.Changed, |
|
|
|
TextTrimmingProperty.Changed, |
|
|
|
FontSizeProperty.Changed, |
|
|
|
FontStyleProperty.Changed, |
|
|
|
FontWeightProperty.Changed |
|
|
|
).AddClassHandler<TextBlock>((x, _) => x.OnTextPropertiesChanged()); |
|
|
|
FontWeightProperty.Changed, |
|
|
|
FontFamilyProperty.Changed, |
|
|
|
TextDecorationsProperty.Changed, |
|
|
|
PaddingProperty.Changed |
|
|
|
).AddClassHandler<TextBlock>((x, _) => x.InvalidateTextLayout()); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -145,6 +162,15 @@ namespace Avalonia.Controls |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the padding to place around the <see cref="Text"/>.
|
|
|
|
/// </summary>
|
|
|
|
public Thickness Padding |
|
|
|
{ |
|
|
|
get { return GetValue(PaddingProperty); } |
|
|
|
set { SetValue(PaddingProperty, value); } |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets a brush used to paint the control's background.
|
|
|
|
/// </summary>
|
|
|
|
@ -363,7 +389,9 @@ namespace Avalonia.Controls |
|
|
|
context.FillRectangle(background, new Rect(Bounds.Size)); |
|
|
|
} |
|
|
|
|
|
|
|
TextLayout?.Draw(context.PlatformImpl, new Point()); |
|
|
|
var padding = Padding; |
|
|
|
|
|
|
|
TextLayout?.Draw(context.PlatformImpl, new Point(padding.Left, padding.Top)); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -412,6 +440,10 @@ namespace Avalonia.Controls |
|
|
|
return new Size(); |
|
|
|
} |
|
|
|
|
|
|
|
var padding = Padding; |
|
|
|
|
|
|
|
availableSize = availableSize.Deflate(padding); |
|
|
|
|
|
|
|
if (_constraint != availableSize) |
|
|
|
{ |
|
|
|
InvalidateTextLayout(); |
|
|
|
@ -419,19 +451,17 @@ namespace Avalonia.Controls |
|
|
|
|
|
|
|
_constraint = availableSize; |
|
|
|
|
|
|
|
return TextLayout?.Bounds.Size ?? Size.Empty; |
|
|
|
var measuredSize = TextLayout?.Bounds.Size ?? Size.Empty; |
|
|
|
|
|
|
|
return measuredSize.Inflate(padding); |
|
|
|
} |
|
|
|
|
|
|
|
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e) |
|
|
|
{ |
|
|
|
base.OnAttachedToLogicalTree(e); |
|
|
|
InvalidateTextLayout(); |
|
|
|
InvalidateMeasure(); |
|
|
|
} |
|
|
|
|
|
|
|
private void OnTextPropertiesChanged() |
|
|
|
{ |
|
|
|
InvalidateTextLayout(); |
|
|
|
|
|
|
|
InvalidateMeasure(); |
|
|
|
} |
|
|
|
} |
|
|
|
|