-
Notifications
You must be signed in to change notification settings - Fork 700
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(textblock): On Wasm, the Padding were not part of the key used fo…
…r the measurement caching. Fixes #4945
- Loading branch information
1 parent
9c6b8d2
commit 32b27b1
Showing
5 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...sApp/UITests.Shared/Windows_UI_Xaml_Controls/TextBlockControl/TextBlock_MeasureCache.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<Page | ||
x:Class="UITests.Windows_UI_Xaml_Controls.TextBlockControl.TextBlock_MeasureCache" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:muxc="using:Microsoft.UI.Xaml.Controls" | ||
xmlns:wasm="http://uno.ui/wasm" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d wasm" | ||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> | ||
|
||
<StackPanel Spacing="6"> | ||
<TextBlock>This test only works on WASM.</TextBlock> | ||
<TextBox x:Name="input" Header="Text" /> | ||
<ComboBox | ||
x:Name="padding" | ||
Header="Padding"> | ||
<ComboBoxItem>0</ComboBoxItem> | ||
<ComboBoxItem IsSelected="True">10</ComboBoxItem> | ||
<ComboBoxItem>20</ComboBoxItem> | ||
</ComboBox> | ||
<ComboBox | ||
x:Name="fontSize" | ||
Header="Font Size"> | ||
<ComboBoxItem>10</ComboBoxItem> | ||
<ComboBoxItem IsSelected="True">20</ComboBoxItem> | ||
<ComboBoxItem>30</ComboBoxItem> | ||
</ComboBox> | ||
<ComboBox | ||
x:Name="fontWeight" | ||
Header="Font Weight"> | ||
<ComboBoxItem>ExtraLight</ComboBoxItem> | ||
<ComboBoxItem IsSelected="True">Normal</ComboBoxItem> | ||
<ComboBoxItem>ExtraBold</ComboBoxItem> | ||
</ComboBox> | ||
<ComboBox | ||
x:Name="characterSpacing" | ||
Header="Character Spacing"> | ||
<ComboBoxItem IsSelected="True">0</ComboBoxItem> | ||
<ComboBoxItem>20</ComboBoxItem> | ||
<ComboBoxItem>50</ComboBoxItem> | ||
</ComboBox> | ||
<ComboBox | ||
x:Name="style" | ||
Header="Style"> | ||
<ComboBoxItem IsSelected="True">Normal</ComboBoxItem> | ||
<ComboBoxItem>Oblique</ComboBoxItem> | ||
<ComboBoxItem>Italic</ComboBoxItem> | ||
</ComboBox> | ||
<Border Background="LightPink" x:Name="textBorder" HorizontalAlignment="Center"> | ||
<TextBlock | ||
x:Name="text" | ||
Text="{Binding Text, ElementName=input}" | ||
Padding="{Binding SelectedItem.Content, ElementName=padding}" | ||
FontSize="{Binding SelectedItem.Content, ElementName=fontSize}" | ||
FontWeight="Binding SelectedItem.Content, ElementName=fontWeight}" | ||
CharacterSpacing="{Binding SelectedItem.Content, ElementName=characterSpacing}" | ||
FontStyle="{Binding SelectedItem.Content, ElementName=style}" | ||
/> | ||
</Border> | ||
<wasm:TextBlock> | ||
<!-- Since this text is complex, it shouldn't influence the caching metrics --> | ||
(WASM ONLY) Cache: Hits=<Run x:Name="hits">0</Run>, Misses=<Run x:Name="misses">0</Run>.<LineBreak /> | ||
Size=<Run x:Name="width" />x<Run x:Name="height" /> | ||
</wasm:TextBlock> | ||
</StackPanel> | ||
</Page> |
45 changes: 45 additions & 0 deletions
45
...p/UITests.Shared/Windows_UI_Xaml_Controls/TextBlockControl/TextBlock_MeasureCache.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System.Threading.Tasks; | ||
using Windows.UI.Xaml.Controls; | ||
using Uno.UI.Samples.Controls; | ||
using Uno.UI; | ||
|
||
namespace UITests.Windows_UI_Xaml_Controls.TextBlockControl | ||
{ | ||
[Sample] | ||
public sealed partial class TextBlock_MeasureCache : Page | ||
{ | ||
public TextBlock_MeasureCache() | ||
{ | ||
this.InitializeComponent(); | ||
|
||
#if __WASM__ | ||
long? initialHits = default; | ||
long? initialMisses = default; | ||
|
||
textBorder.SizeChanged += (sender, e) => { UpdateCacheMetrics(); }; | ||
padding.SelectionChanged += (sender, e) => { UpdateCacheMetrics(); }; | ||
fontSize.SelectionChanged += (sender, e) => { UpdateCacheMetrics(); }; | ||
fontWeight.SelectionChanged += (sender, e) => { UpdateCacheMetrics(); }; | ||
characterSpacing.SelectionChanged += (sender, e) => { UpdateCacheMetrics(); }; | ||
style.SelectionChanged += (sender, e) => { UpdateCacheMetrics(); }; | ||
|
||
async void UpdateCacheMetrics() | ||
{ | ||
if (initialHits == null) | ||
{ | ||
initialHits = UnoMetrics.TextBlock.MeasureCacheHits; | ||
initialMisses = UnoMetrics.TextBlock.MeasureCacheMisses; | ||
input.Text = "Uno is awesome."; | ||
} | ||
await Task.Delay(10); // give time to UI to update | ||
width.Text = textBorder.ActualWidth.ToString("F2"); | ||
height.Text = textBorder.ActualHeight.ToString("F2"); | ||
hits.Text = (UnoMetrics.TextBlock.MeasureCacheHits - initialHits).ToString(); | ||
misses.Text = (UnoMetrics.TextBlock.MeasureCacheMisses - initialMisses).ToString(); | ||
} | ||
|
||
UpdateCacheMetrics(); | ||
#endif | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters