From 5618cc03e46c044f083c3880be44ad072a7dffb0 Mon Sep 17 00:00:00 2001 From: Brett Story Date: Sun, 15 May 2022 11:03:02 -0500 Subject: [PATCH 1/5] Utilizing TextLayout's LineHeight in TextBox and TextPresenter --- samples/ControlCatalog/Pages/TextBoxPage.xaml | 6 +++++ .../Presenters/TextPresenter.cs | 25 +++++++++++++++---- src/Avalonia.Controls/TextBox.cs | 19 ++++++++++++-- .../Controls/TextBox.xaml | 1 + .../Controls/TextBox.xaml | 1 + 5 files changed, 45 insertions(+), 7 deletions(-) diff --git a/samples/ControlCatalog/Pages/TextBoxPage.xaml b/samples/ControlCatalog/Pages/TextBoxPage.xaml index dec5f74da8..e3d0c5e4e2 100644 --- a/samples/ControlCatalog/Pages/TextBoxPage.xaml +++ b/samples/ControlCatalog/Pages/TextBoxPage.xaml @@ -66,6 +66,12 @@ FontFamily="Comic Sans MS" InputMethod.IsInputMethodEnabled="False" Foreground="Red"/> + diff --git a/src/Avalonia.Controls/Presenters/TextPresenter.cs b/src/Avalonia.Controls/Presenters/TextPresenter.cs index 07061940b5..b0f8752d65 100644 --- a/src/Avalonia.Controls/Presenters/TextPresenter.cs +++ b/src/Avalonia.Controls/Presenters/TextPresenter.cs @@ -33,7 +33,7 @@ namespace Avalonia.Controls.Presenters public static readonly StyledProperty CaretBrushProperty = AvaloniaProperty.Register(nameof(CaretBrush)); - + public static readonly DirectProperty SelectionStartProperty = TextBox.SelectionStartProperty.AddOwner( o => o.SelectionStart, @@ -43,7 +43,7 @@ namespace Avalonia.Controls.Presenters TextBox.SelectionEndProperty.AddOwner( o => o.SelectionEnd, (o, v) => o.SelectionEnd = v); - + /// /// Defines the property. /// @@ -65,6 +65,12 @@ namespace Avalonia.Controls.Presenters public static readonly StyledProperty TextWrappingProperty = TextBlock.TextWrappingProperty.AddOwner(); + /// + /// Defines the property. + /// + public static readonly StyledProperty LineHeightProperty = + AvaloniaProperty.Register(nameof(LineHeight), defaultValue: double.NaN); + /// /// Defines the property. /// @@ -179,6 +185,15 @@ namespace Avalonia.Controls.Presenters get => GetValue(TextWrappingProperty); set => SetValue(TextWrappingProperty, value); } + + /// + /// Gets or sets the line height. By default, this is set to , which determines the appropriate height automatically. + /// + public double LineHeight + { + get => GetValue(LineHeightProperty); + set => SetValue(LineHeightProperty, value); + } /// /// Gets or sets the text alignment. @@ -253,7 +268,7 @@ namespace Avalonia.Controls.Presenters get => GetValue(CaretBrushProperty); set => SetValue(CaretBrushProperty, value); } - + public int SelectionStart { get @@ -281,7 +296,7 @@ namespace Avalonia.Controls.Presenters SetAndRaise(SelectionEndProperty, ref _selectionEnd, value); } } - + protected override bool BypassFlowDirectionPolicies => true; /// @@ -301,7 +316,7 @@ namespace Avalonia.Controls.Presenters var textLayout = new TextLayout(text, typeface, FontSize, foreground, TextAlignment, TextWrapping, maxWidth: maxWidth, maxHeight: maxHeight, textStyleOverrides: textStyleOverrides, - flowDirection: FlowDirection); + flowDirection: FlowDirection, lineHeight: LineHeight); return textLayout; } diff --git a/src/Avalonia.Controls/TextBox.cs b/src/Avalonia.Controls/TextBox.cs index 45e66828c1..2d14ff0f79 100644 --- a/src/Avalonia.Controls/TextBox.cs +++ b/src/Avalonia.Controls/TextBox.cs @@ -79,8 +79,8 @@ namespace Avalonia.Controls AvaloniaProperty.Register(nameof(MaxLength), defaultValue: 0); public static readonly StyledProperty MaxLinesProperty = - AvaloniaProperty.Register(nameof(MaxLines), defaultValue: 0); - + AvaloniaProperty.Register(nameof(MaxLines), defaultValue: 0); + public static readonly DirectProperty TextProperty = TextBlock.TextProperty.AddOwnerWithDataValidation( o => o.Text, @@ -105,6 +105,12 @@ namespace Avalonia.Controls public static readonly StyledProperty TextWrappingProperty = TextBlock.TextWrappingProperty.AddOwner(); + + /// + /// Defines see property. + /// + public static readonly StyledProperty LineHeightProperty = + AvaloniaProperty.Register(nameof(LineHeight), defaultValue: double.NaN); public static readonly StyledProperty WatermarkProperty = AvaloniaProperty.Register(nameof(Watermark)); @@ -358,6 +364,15 @@ namespace Avalonia.Controls get { return GetValue(MaxLinesProperty); } set { SetValue(MaxLinesProperty, value); } } + + /// + /// Gets or sets the line height. By default, this is set to , which determines the appropriate height automatically. + /// + public double LineHeight + { + get { return GetValue(LineHeightProperty); } + set { SetValue(LineHeightProperty, value); } + } [Content] public string? Text diff --git a/src/Avalonia.Themes.Default/Controls/TextBox.xaml b/src/Avalonia.Themes.Default/Controls/TextBox.xaml index 6e3898a828..1885d3b65b 100644 --- a/src/Avalonia.Themes.Default/Controls/TextBox.xaml +++ b/src/Avalonia.Themes.Default/Controls/TextBox.xaml @@ -76,6 +76,7 @@ SelectionEnd="{TemplateBinding SelectionEnd}" TextAlignment="{TemplateBinding TextAlignment}" TextWrapping="{TemplateBinding TextWrapping}" + LineHeight="{TemplateBinding LineHeight}" PasswordChar="{TemplateBinding PasswordChar}" RevealPassword="{TemplateBinding RevealPassword}" SelectionBrush="{TemplateBinding SelectionBrush}" diff --git a/src/Avalonia.Themes.Fluent/Controls/TextBox.xaml b/src/Avalonia.Themes.Fluent/Controls/TextBox.xaml index 095a2ef51f..40d9b11f7c 100644 --- a/src/Avalonia.Themes.Fluent/Controls/TextBox.xaml +++ b/src/Avalonia.Themes.Fluent/Controls/TextBox.xaml @@ -89,6 +89,7 @@ SelectionEnd="{TemplateBinding SelectionEnd}" TextAlignment="{TemplateBinding TextAlignment}" TextWrapping="{TemplateBinding TextWrapping}" + LineHeight="{TemplateBinding LineHeight}" PasswordChar="{TemplateBinding PasswordChar}" RevealPassword="{TemplateBinding RevealPassword}" SelectionBrush="{TemplateBinding SelectionBrush}" From dbf25230b4ef61d6fd7c2209a4541c5e8824b8be Mon Sep 17 00:00:00 2001 From: Brett Story Date: Sun, 15 May 2022 18:16:11 -0500 Subject: [PATCH 2/5] Utilizing AddOwner for LineHeight on TextBox --- src/Avalonia.Controls/TextBox.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Avalonia.Controls/TextBox.cs b/src/Avalonia.Controls/TextBox.cs index 2d14ff0f79..30a3eb7863 100644 --- a/src/Avalonia.Controls/TextBox.cs +++ b/src/Avalonia.Controls/TextBox.cs @@ -107,10 +107,10 @@ namespace Avalonia.Controls TextBlock.TextWrappingProperty.AddOwner(); /// - /// Defines see property. + /// Defines see property. /// public static readonly StyledProperty LineHeightProperty = - AvaloniaProperty.Register(nameof(LineHeight), defaultValue: double.NaN); + TextPresenter.LineHeightProperty.AddOwner(); public static readonly StyledProperty WatermarkProperty = AvaloniaProperty.Register(nameof(Watermark)); @@ -366,7 +366,7 @@ namespace Avalonia.Controls } /// - /// Gets or sets the line height. By default, this is set to , which determines the appropriate height automatically. + /// Gets or sets the line height. /// public double LineHeight { From 8b9883e0d3f26957d9c8f78d31aa3a9e31dc3318 Mon Sep 17 00:00:00 2001 From: Brett Story Date: Mon, 16 May 2022 15:18:36 -0500 Subject: [PATCH 3/5] TextBox and TestPresenter use AddOwner from TextBlock for LineHeight --- src/Avalonia.Controls/Presenters/TextPresenter.cs | 2 +- src/Avalonia.Controls/TextBox.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Controls/Presenters/TextPresenter.cs b/src/Avalonia.Controls/Presenters/TextPresenter.cs index b0f8752d65..218ac2d3ed 100644 --- a/src/Avalonia.Controls/Presenters/TextPresenter.cs +++ b/src/Avalonia.Controls/Presenters/TextPresenter.cs @@ -69,7 +69,7 @@ namespace Avalonia.Controls.Presenters /// Defines the property. /// public static readonly StyledProperty LineHeightProperty = - AvaloniaProperty.Register(nameof(LineHeight), defaultValue: double.NaN); + TextBlock.LineHeightProperty.AddOwner(); /// /// Defines the property. diff --git a/src/Avalonia.Controls/TextBox.cs b/src/Avalonia.Controls/TextBox.cs index 30a3eb7863..e40ce8fa73 100644 --- a/src/Avalonia.Controls/TextBox.cs +++ b/src/Avalonia.Controls/TextBox.cs @@ -110,7 +110,7 @@ namespace Avalonia.Controls /// Defines see property. /// public static readonly StyledProperty LineHeightProperty = - TextPresenter.LineHeightProperty.AddOwner(); + TextBlock.LineHeightProperty.AddOwner(); public static readonly StyledProperty WatermarkProperty = AvaloniaProperty.Register(nameof(Watermark)); From b26dc168274f9d5eb49f190296e569ecc86ea690 Mon Sep 17 00:00:00 2001 From: Brett Story Date: Mon, 16 May 2022 15:20:05 -0500 Subject: [PATCH 4/5] Fixing AddOwner on LineHeight for TextPresenter --- src/Avalonia.Controls/Presenters/TextPresenter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/Presenters/TextPresenter.cs b/src/Avalonia.Controls/Presenters/TextPresenter.cs index 218ac2d3ed..ea9ae7bb0f 100644 --- a/src/Avalonia.Controls/Presenters/TextPresenter.cs +++ b/src/Avalonia.Controls/Presenters/TextPresenter.cs @@ -69,7 +69,7 @@ namespace Avalonia.Controls.Presenters /// Defines the property. /// public static readonly StyledProperty LineHeightProperty = - TextBlock.LineHeightProperty.AddOwner(); + TextBlock.LineHeightProperty.AddOwner(); /// /// Defines the property. From 4c039cbf7ceda4005c5e9015fcf7b83a01ce8eee Mon Sep 17 00:00:00 2001 From: Max Katz Date: Mon, 16 May 2022 22:46:24 -0400 Subject: [PATCH 5/5] Move Fluent/Default themes out of main package --- build/CoreLibraries.props | 2 -- samples/BindingDemo/BindingDemo.csproj | 1 + samples/ControlCatalog/ControlCatalog.csproj | 2 ++ samples/IntegrationTestApp/IntegrationTestApp.csproj | 3 ++- samples/PlatformSanityChecks/PlatformSanityChecks.csproj | 1 + samples/Previewer/Previewer.csproj | 3 +++ samples/RenderDemo/RenderDemo.csproj | 1 + samples/Sandbox/Sandbox.csproj | 1 + samples/VirtualizationDemo/VirtualizationDemo.csproj | 1 + .../interop/Direct3DInteropSample/Direct3DInteropSample.csproj | 1 + samples/interop/NativeEmbedSample/NativeEmbedSample.csproj | 1 + 11 files changed, 14 insertions(+), 3 deletions(-) diff --git a/build/CoreLibraries.props b/build/CoreLibraries.props index 314d38190a..9448a31d73 100644 --- a/build/CoreLibraries.props +++ b/build/CoreLibraries.props @@ -3,8 +3,6 @@ - - diff --git a/samples/BindingDemo/BindingDemo.csproj b/samples/BindingDemo/BindingDemo.csproj index 2c6ff74e5e..bd6054327f 100644 --- a/samples/BindingDemo/BindingDemo.csproj +++ b/samples/BindingDemo/BindingDemo.csproj @@ -5,6 +5,7 @@ + diff --git a/samples/ControlCatalog/ControlCatalog.csproj b/samples/ControlCatalog/ControlCatalog.csproj index 7cbd8a3f9c..e5f07c90c3 100644 --- a/samples/ControlCatalog/ControlCatalog.csproj +++ b/samples/ControlCatalog/ControlCatalog.csproj @@ -25,6 +25,8 @@ + + diff --git a/samples/IntegrationTestApp/IntegrationTestApp.csproj b/samples/IntegrationTestApp/IntegrationTestApp.csproj index e8338adae6..4284399357 100644 --- a/samples/IntegrationTestApp/IntegrationTestApp.csproj +++ b/samples/IntegrationTestApp/IntegrationTestApp.csproj @@ -1,4 +1,4 @@ - + WinExe net6.0 @@ -18,6 +18,7 @@ + diff --git a/samples/PlatformSanityChecks/PlatformSanityChecks.csproj b/samples/PlatformSanityChecks/PlatformSanityChecks.csproj index 9660d2a90d..4f7f06b529 100644 --- a/samples/PlatformSanityChecks/PlatformSanityChecks.csproj +++ b/samples/PlatformSanityChecks/PlatformSanityChecks.csproj @@ -7,6 +7,7 @@ + diff --git a/samples/Previewer/Previewer.csproj b/samples/Previewer/Previewer.csproj index c1d14cba26..98560e9ab0 100644 --- a/samples/Previewer/Previewer.csproj +++ b/samples/Previewer/Previewer.csproj @@ -9,6 +9,9 @@ + + + diff --git a/samples/RenderDemo/RenderDemo.csproj b/samples/RenderDemo/RenderDemo.csproj index 18a4ee5662..3c62af1eaf 100644 --- a/samples/RenderDemo/RenderDemo.csproj +++ b/samples/RenderDemo/RenderDemo.csproj @@ -12,6 +12,7 @@ + diff --git a/samples/Sandbox/Sandbox.csproj b/samples/Sandbox/Sandbox.csproj index f3c38cd96e..eab654acb6 100644 --- a/samples/Sandbox/Sandbox.csproj +++ b/samples/Sandbox/Sandbox.csproj @@ -10,6 +10,7 @@ + diff --git a/samples/VirtualizationDemo/VirtualizationDemo.csproj b/samples/VirtualizationDemo/VirtualizationDemo.csproj index 2c6ff74e5e..bd6054327f 100644 --- a/samples/VirtualizationDemo/VirtualizationDemo.csproj +++ b/samples/VirtualizationDemo/VirtualizationDemo.csproj @@ -5,6 +5,7 @@ + diff --git a/samples/interop/Direct3DInteropSample/Direct3DInteropSample.csproj b/samples/interop/Direct3DInteropSample/Direct3DInteropSample.csproj index cd9963a2e5..81b94b4d09 100644 --- a/samples/interop/Direct3DInteropSample/Direct3DInteropSample.csproj +++ b/samples/interop/Direct3DInteropSample/Direct3DInteropSample.csproj @@ -22,6 +22,7 @@ + diff --git a/samples/interop/NativeEmbedSample/NativeEmbedSample.csproj b/samples/interop/NativeEmbedSample/NativeEmbedSample.csproj index c25442b52c..2f3ea85e46 100644 --- a/samples/interop/NativeEmbedSample/NativeEmbedSample.csproj +++ b/samples/interop/NativeEmbedSample/NativeEmbedSample.csproj @@ -9,6 +9,7 @@ +