Optimize and simplify CalculationResult to be able to update the FontSize and the DisplayMargin without fully updating the Style. (#217)

- Merge the 3 CalculationResultStyle(S|M|L) in App.xaml
- Only modify CalculationResult::*FontSize in Calculator.xaml instead of fully updating the style of the control.
- Create a new property MaxFontSize in order to be able to update it without being forced to fully update the Style (because m_startingFontSize was set in OnApplyTemplate)
- Modify how DisplayMargin is managed to prevent the textblock Margin to shift when we update its value (without fully updating the Style).
This commit is contained in:
Rudy Huyn
2019-04-05 13:04:39 -07:00
committed by Daniel Belcher
parent e7eace57f8
commit af41a183a7
7 changed files with 60 additions and 308 deletions

View File

@@ -134,10 +134,6 @@
<!-- Standard Operators Standard/Scientific in Fill/Full -->
<x:Double x:Key="CalcOperatorCaptionSize">15</x:Double>
<x:Double x:Key="CalcResultFontSizeL">72</x:Double>
<x:Double x:Key="CalcResultFontSizeM">46</x:Double>
<x:Double x:Key="CalcResultFontSizeS">28</x:Double>
<!-- Base style for calc buttons -->
<Style x:Key="CalcButtonStyle" TargetType="Controls:CalculatorButton">
<Setter Property="MinWidth" Value="24"/>
@@ -360,7 +356,7 @@
<Setter Property="ZoomMode" Value="Disabled"/>
</Style>
<Style x:Key="CalculationResultStyleL" TargetType="Controls:CalculationResult">
<Style x:Key="CalculationResultStyle" TargetType="Controls:CalculationResult">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Foreground" Value="{ThemeResource SystemControlPageTextBaseHighBrush}"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
@@ -447,181 +443,6 @@
</Setter.Value>
</Setter>
</Style>
<Style x:Key="CalculationResultStyleM" TargetType="Controls:CalculationResult">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Foreground" Value="{ThemeResource SystemControlPageTextBaseHighBrush}"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="VerticalAlignment" Value="Stretch"/>
<Setter Property="HorizontalContentAlignment" Value="Right"/>
<Setter Property="VerticalContentAlignment" Value="Top"/>
<Setter Property="IsTextScaleFactorEnabled" Value="False"/>
<Setter Property="UseSystemFocusVisuals" Value="True"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Controls:CalculationResult">
<Grid x:Name="border" Background="{TemplateBinding Background}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="12"/>
<ColumnDefinition/>
<ColumnDefinition Width="12"/>
</Grid.ColumnDefinitions>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="ActiveStates">
<VisualState x:Name="Active">
<VisualState.Setters>
<Setter Target="normalOutput.IsTextSelectionEnabled" Value="True"/>
<Setter Target="normalOutput.FontWeight" Value="SemiBold"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Normal"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<ScrollViewer x:Name="textContainer"
Grid.Column="1"
Padding="0,0,0,0"
Style="{ThemeResource ResultsScrollerSnapped}"
AutomationProperties.AccessibilityView="Raw">
<TextBlock x:Name="normalOutput"
Margin="{TemplateBinding DisplayMargin}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Foreground="{TemplateBinding Foreground}"
FontSize="{TemplateBinding FontSize}"
FontWeight="Light"
AutomationProperties.AccessibilityView="Raw"
Text="{TemplateBinding DisplayValue}"
TextAlignment="{TemplateBinding HorizontalContentAlignment}"
TextWrapping="NoWrap"/>
</ScrollViewer>
<HyperlinkButton x:Name="scrollLeft"
Grid.Column="0"
Width="20"
MinWidth="20"
MinHeight="24"
Margin="-4,0,-4,0"
Padding="0,-3,0,4"
VerticalAlignment="Top"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
Foreground="{ThemeResource SystemControlForegroundAccentBrush}"
BorderThickness="0"
Visibility="Collapsed">
<FontIcon x:Name="scrollLeftText"
FontFamily="{ThemeResource SymbolThemeFontFamily}"
FontSize="12"
Glyph="&#xE26C;"/>
</HyperlinkButton>
<HyperlinkButton x:Name="scrollRight"
Grid.Column="2"
Width="20"
MinWidth="20"
MinHeight="24"
Margin="-4,0,-4,0"
Padding="0,-3,0,4"
VerticalAlignment="Top"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
Foreground="{ThemeResource SystemControlForegroundAccentBrush}"
BorderThickness="0"
Visibility="Collapsed">
<FontIcon x:Name="scrollRightText"
FontFamily="{ThemeResource SymbolThemeFontFamily}"
FontSize="12"
Glyph="&#xE26B;"/>
</HyperlinkButton>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="CalculationResultStyleS" TargetType="Controls:CalculationResult">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Foreground" Value="{ThemeResource SystemControlPageTextBaseHighBrush}"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="VerticalAlignment" Value="Stretch"/>
<Setter Property="HorizontalContentAlignment" Value="Right"/>
<Setter Property="VerticalContentAlignment" Value="Top"/>
<Setter Property="MinHeight" Value="12"/>
<Setter Property="IsTextScaleFactorEnabled" Value="False"/>
<Setter Property="UseSystemFocusVisuals" Value="True"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Controls:CalculationResult">
<Grid x:Name="border" Background="{TemplateBinding Background}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="12"/>
<ColumnDefinition/>
<ColumnDefinition Width="12"/>
</Grid.ColumnDefinitions>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="ActiveStates">
<VisualState x:Name="Active">
<VisualState.Setters>
<Setter Target="normalOutput.FontWeight" Value="SemiBold"/>
<Setter Target="normalOutput.IsTextSelectionEnabled" Value="True"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Normal"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<ScrollViewer x:Name="textContainer"
Grid.Column="1"
Padding="0,0,0,0"
Style="{ThemeResource ResultsScrollerSnapped}"
AutomationProperties.AccessibilityView="Raw">
<TextBlock x:Name="normalOutput"
Margin="{TemplateBinding DisplayMargin}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Foreground="{TemplateBinding Foreground}"
FontSize="{TemplateBinding FontSize}"
FontWeight="Light"
AutomationProperties.AccessibilityView="Raw"
Text="{TemplateBinding DisplayValue}"
TextAlignment="{TemplateBinding HorizontalContentAlignment}"
TextWrapping="NoWrap"/>
</ScrollViewer>
<HyperlinkButton x:Name="scrollLeft"
Grid.Column="0"
Width="20"
MinWidth="20"
MinHeight="24"
Margin="-4,0,-4,0"
Padding="0,-3,0,4"
VerticalAlignment="Top"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
Foreground="{ThemeResource SystemControlForegroundAccentBrush}"
BorderThickness="0"
Visibility="Collapsed">
<FontIcon x:Name="scrollLeftText"
FontFamily="{ThemeResource SymbolThemeFontFamily}"
FontSize="12"
Glyph="&#xE26C;"/>
</HyperlinkButton>
<HyperlinkButton x:Name="scrollRight"
Grid.Column="2"
Width="20"
MinWidth="20"
MinHeight="24"
Margin="-4,0,-4,0"
Padding="0,-3,0,4"
VerticalAlignment="Top"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
Foreground="{ThemeResource SystemControlForegroundAccentBrush}"
BorderThickness="0"
Visibility="Collapsed">
<FontIcon x:Name="scrollRightText"
FontFamily="{ThemeResource SymbolThemeFontFamily}"
FontSize="12"
Glyph="&#xE26B;"/>
</HyperlinkButton>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="CaptionButtonStyle" TargetType="Button">
<Setter Property="Foreground" Value="{ThemeResource SystemControlForegroundBaseHighBrush}"/>