From 0c14a0fbc2984103ce580367776d7c33a2a80e45 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Wed, 28 Feb 2024 13:08:45 +0200 Subject: [PATCH 1/5] fix: Fix AutoSuggestBox QueryIcon size --- .../Given_AutoSuggestBox.cs | 29 +++++++++++++++++++ .../Controls/AutoSuggestBox/AutoSuggestBox.cs | 9 ++++-- .../UI/Xaml/Controls/Icons/SymbolIcon.cs | 20 +++++++++++-- 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_AutoSuggestBox.cs b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_AutoSuggestBox.cs index b65514392f24..2a33bd5725ba 100644 --- a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_AutoSuggestBox.cs +++ b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_AutoSuggestBox.cs @@ -18,6 +18,9 @@ using static Private.Infrastructure.TestServices; using static Microsoft.UI.Xaml.Controls.AutoSuggestionBoxTextChangeReason; +using SamplesApp.UITests; +using Uno.UI.RuntimeTests.Helpers; +using Windows.Foundation; namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls { @@ -25,6 +28,32 @@ namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls [RunsOnUIThread] public class Given_AutoSuggestBox { +#if !WINAPPSDK + [TestMethod] + [UnoWorkItem("https://github.com/unoplatform/uno/issues/15662")] + public async Task When_SymbolIcon_Verify_Size() + { + var SUT = new AutoSuggestBox() + { + QueryIcon = new SymbolIcon(Symbol.Home), + }; + + await UITestHelper.Load(SUT); + +#if __SKIA__ || __WASM__ + var tb = SUT.FindChildren().Single(tb => tb.Text.Length == 1 && tb.Text[0] == (char)Symbol.Home); +#else + var tb = (TextBlock)SUT.EnumerateAllChildren(c => c is TextBlock tb && tb.Text.Length == 1 && tb.Text[0] == (char)Symbol.Home).Single(); +#endif + + Assert.AreEqual(12, tb.FontSize); + + var tbBounds = tb.GetAbsoluteBounds(); + + Assert.AreEqual(new Size(12, 12), new Size(tbBounds.Width, tbBounds.Height)); + } +#endif + #if !WINAPPSDK // GetTemplateChild is protected in UWP while public in Uno. [TestMethod] public async Task When_Text_Changed_Should_Reflect_In_DataTemplate_TextBox() diff --git a/src/Uno.UI/UI/Xaml/Controls/AutoSuggestBox/AutoSuggestBox.cs b/src/Uno.UI/UI/Xaml/Controls/AutoSuggestBox/AutoSuggestBox.cs index 7863d7543c77..729ec22ac26a 100644 --- a/src/Uno.UI/UI/Xaml/Controls/AutoSuggestBox/AutoSuggestBox.cs +++ b/src/Uno.UI/UI/Xaml/Controls/AutoSuggestBox/AutoSuggestBox.cs @@ -349,8 +349,13 @@ private void UpdateQueryButton() return; } - _queryButton.Content = QueryIcon; - _queryButton.Visibility = QueryIcon == null ? Visibility.Collapsed : Visibility.Visible; + var queryIcon = QueryIcon; + if (queryIcon is SymbolIcon symbolIcon) + { + symbolIcon.SetFontSize(0); + } + _queryButton.Content = queryIcon; + _queryButton.Visibility = queryIcon == null ? Visibility.Collapsed : Visibility.Visible; } private void UpdateTextBox() diff --git a/src/Uno.UI/UI/Xaml/Controls/Icons/SymbolIcon.cs b/src/Uno.UI/UI/Xaml/Controls/Icons/SymbolIcon.cs index 71c0cb1d1c68..d0f3fe60ebe8 100644 --- a/src/Uno.UI/UI/Xaml/Controls/Icons/SymbolIcon.cs +++ b/src/Uno.UI/UI/Xaml/Controls/Icons/SymbolIcon.cs @@ -12,7 +12,7 @@ namespace Microsoft.UI.Xaml.Controls; /// public sealed partial class SymbolIcon : IconElement { - private const double DefaultFontSize = 20.0; + private double _fontSize = 20.0; private readonly TextBlock _textBlock; @@ -63,7 +63,12 @@ private void SynchronizeProperties() _textBlock.TextAlignment = Microsoft.UI.Xaml.TextAlignment.Center; _textBlock.HorizontalAlignment = HorizontalAlignment.Stretch; _textBlock.VerticalAlignment = VerticalAlignment.Center; - _textBlock.FontSize = DefaultFontSize; + + if (_fontSize > 0) + { + _textBlock.FontSize = _fontSize; + } + _textBlock.FontStyle = FontStyle.Normal; _textBlock.FontFamily = GetSymbolFontFamily(); _textBlock.IsTextScaleFactorEnabled = false; @@ -73,6 +78,17 @@ private void SynchronizeProperties() _textBlock.Foreground = Foreground; } + internal void SetFontSize(double fontSize) + { + _fontSize = fontSize; + if (fontSize == 0) + { + _textBlock.ClearValue(TextBlock.FontSizeProperty); + } + + InvalidateMeasure(); + } + private void SetSymbolText() => _textBlock.Text = new string((char)Symbol, 1); private static FontFamily GetSymbolFontFamily() => From 848b410540918ad18a7b96865be89ebd48c2e532 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Wed, 5 Jun 2024 16:01:49 +0300 Subject: [PATCH 2/5] chore: Fix build error --- .../Tests/Windows_UI_Xaml_Controls/Given_AutoSuggestBox.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_AutoSuggestBox.cs b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_AutoSuggestBox.cs index 2a33bd5725ba..2d89da6a28ef 100644 --- a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_AutoSuggestBox.cs +++ b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_AutoSuggestBox.cs @@ -22,6 +22,12 @@ using Uno.UI.RuntimeTests.Helpers; using Windows.Foundation; +#if __IOS__ +using UIKit; +#elif __MACOS__ +using AppKit; +#endif + namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls { [TestClass] From 1f9401232745a7ec880deeb22f0599a54d9bd45c Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Wed, 5 Jun 2024 16:35:46 +0300 Subject: [PATCH 3/5] chore: Fix build --- .../Tests/Windows_UI_Xaml_Controls/Given_AutoSuggestBox.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_AutoSuggestBox.cs b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_AutoSuggestBox.cs index 2d89da6a28ef..beb016fee0b5 100644 --- a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_AutoSuggestBox.cs +++ b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_AutoSuggestBox.cs @@ -49,7 +49,7 @@ public async Task When_SymbolIcon_Verify_Size() #if __SKIA__ || __WASM__ var tb = SUT.FindChildren().Single(tb => tb.Text.Length == 1 && tb.Text[0] == (char)Symbol.Home); #else - var tb = (TextBlock)SUT.EnumerateAllChildren(c => c is TextBlock tb && tb.Text.Length == 1 && tb.Text[0] == (char)Symbol.Home).Single(); + var tb = (TextBlock)SUT.EnumerateAllChildren(c => c is TextBlock textBlock && textBlock.Text.Length == 1 && textBlock.Text[0] == (char)Symbol.Home).Single(); #endif Assert.AreEqual(12, tb.FontSize); From 6c38f1584e6f15b7570f8da591b469c26c1835eb Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Wed, 5 Jun 2024 19:42:54 +0300 Subject: [PATCH 4/5] chore: Fix build --- .../Tests/Windows_UI_Xaml_Controls/Given_AutoSuggestBox.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_AutoSuggestBox.cs b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_AutoSuggestBox.cs index beb016fee0b5..b4871efc3d7d 100644 --- a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_AutoSuggestBox.cs +++ b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_AutoSuggestBox.cs @@ -49,7 +49,7 @@ public async Task When_SymbolIcon_Verify_Size() #if __SKIA__ || __WASM__ var tb = SUT.FindChildren().Single(tb => tb.Text.Length == 1 && tb.Text[0] == (char)Symbol.Home); #else - var tb = (TextBlock)SUT.EnumerateAllChildren(c => c is TextBlock textBlock && textBlock.Text.Length == 1 && textBlock.Text[0] == (char)Symbol.Home).Single(); + var tb = (TextBlock)SUT.EnumerateAllChildren().SingleOrDefault(c => c is TextBlock textBlock && textBlock.Text.Length == 1 && textBlock.Text[0] == (char)Symbol.Home); #endif Assert.AreEqual(12, tb.FontSize); From ed2f4120df963ffba875fc8ad51cf7ae01e90998 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Thu, 6 Jun 2024 13:47:18 +0300 Subject: [PATCH 5/5] chore: Adjust test --- .../Tests/Windows_UI_Xaml_Controls/Given_AutoSuggestBox.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_AutoSuggestBox.cs b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_AutoSuggestBox.cs index b4871efc3d7d..446807e45143 100644 --- a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_AutoSuggestBox.cs +++ b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_AutoSuggestBox.cs @@ -56,7 +56,14 @@ public async Task When_SymbolIcon_Verify_Size() var tbBounds = tb.GetAbsoluteBounds(); +#if __WASM__ + Assert.AreEqual(new Size(13, 12), new Size(tbBounds.Width, tbBounds.Height)); +#elif __ANDROID__ + Assert.AreEqual(new Size(12, 14), new Size(tbBounds.Width, tbBounds.Height)); +#else + // 12, 12 is the right behavior here. Assert.AreEqual(new Size(12, 12), new Size(tbBounds.Width, tbBounds.Height)); +#endif } #endif