Skip to content

Commit

Permalink
Simplified AppendPercentageSign
Browse files Browse the repository at this point in the history
  • Loading branch information
lhecker committed Mar 5, 2024
1 parent 697d15f commit 98468f9
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 16 deletions.
1 change: 0 additions & 1 deletion src/cascadia/TerminalSettingsEditor/Appearances.idl
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ namespace Microsoft.Terminal.Settings.Editor
Windows.Foundation.Collections.IObservableVector<Microsoft.Terminal.Settings.Editor.EnumEntry> FontWeightList { get; };

IInspectable CurrentFontFace { get; };
Windows.UI.Xaml.Controls.Slider BIOpacitySlider { get; };

IInspectable CurrentIntenseTextStyle;
Windows.Foundation.Collections.IObservableVector<Microsoft.Terminal.Settings.Editor.EnumEntry> IntenseTextStyleList { get; };
Expand Down
5 changes: 2 additions & 3 deletions src/cascadia/TerminalSettingsEditor/Appearances.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -730,13 +730,12 @@
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Slider x:Name="BIOpacitySlider"
x:Uid="Profile_BackgroundImageOpacitySlider"
<Slider x:Uid="Profile_BackgroundImageOpacitySlider"
Grid.Column="0"
Value="{x:Bind mtu:Converters.PercentageToPercentageValue(Appearance.BackgroundImageOpacity), BindBack=Appearance.SetBackgroundImageOpacityFromPercentageValue, Mode=TwoWay}" />
<TextBlock Grid.Column="1"
Style="{StaticResource SliderValueLabelStyle}"
Text="{x:Bind mtu:Converters.AppendPercentageSign(BIOpacitySlider.Value), Mode=OneWay}" />
Text="{x:Bind mtu:Converters.PercentageToPercentageString(Appearance.BackgroundImageOpacity), Mode=OneWay}" />
</Grid>
</local:SettingContainer>
</StackPanel>
Expand Down
2 changes: 0 additions & 2 deletions src/cascadia/TerminalSettingsEditor/Profiles_Appearance.idl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,5 @@ namespace Microsoft.Terminal.Settings.Editor
Profiles_Appearance();
ProfileViewModel Profile { get; };
IHostedInWindow WindowRoot { get; };

Windows.UI.Xaml.Controls.Slider OpacitySlider { get; };
}
}
5 changes: 2 additions & 3 deletions src/cascadia/TerminalSettingsEditor/Profiles_Appearance.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,12 @@
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Slider x:Name="OpacitySlider"
x:Uid="Profile_OpacitySlider"
<Slider x:Uid="Profile_OpacitySlider"
Grid.Column="0"
Value="{x:Bind mtu:Converters.PercentageToPercentageValue(Profile.Opacity), BindBack=Profile.SetAcrylicOpacityPercentageValue, Mode=TwoWay}" />
<TextBlock Grid.Column="1"
Style="{StaticResource SliderValueLabelStyle}"
Text="{x:Bind mtu:Converters.AppendPercentageSign(OpacitySlider.Value), Mode=OneWay}" />
Text="{x:Bind mtu:Converters.PercentageToPercentageString(Profile.Opacity), Mode=OneWay}" />
</Grid>
</StackPanel>
</local:SettingContainer>
Expand Down
10 changes: 5 additions & 5 deletions src/cascadia/UIHelpers/Converters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ namespace winrt::Microsoft::Terminal::UI::implementation
return value / 100.0;
}

winrt::hstring Converters::PercentageToPercentageString(double value)
{
return winrt::hstring{ fmt::format(FMT_COMPILE(L"{:.0f}%"), value * 100.0) };
}

// Strings
bool Converters::StringsAreNotEqual(const winrt::hstring& expected, const winrt::hstring& actual)
{
Expand All @@ -46,11 +51,6 @@ namespace winrt::Microsoft::Terminal::UI::implementation
}

// Misc
winrt::hstring Converters::AppendPercentageSign(double value)
{
return winrt::hstring{ fmt::format(FMT_COMPILE(L"{}%"), value) };
}

winrt::Windows::UI::Text::FontWeight Converters::DoubleToFontWeight(double value)
{
return winrt::Windows::UI::Text::FontWeight{ base::ClampedNumeric<uint16_t>(value) };
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/UIHelpers/Converters.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ namespace winrt::Microsoft::Terminal::UI::implementation
// Numbers
static double PercentageToPercentageValue(double value);
static double PercentageValueToPercentage(double value);
static winrt::hstring PercentageToPercentageString(double value);

// Strings
static bool StringsAreNotEqual(const winrt::hstring& expected, const winrt::hstring& actual);
static winrt::Windows::UI::Xaml::Visibility StringNotEmptyToVisibility(const winrt::hstring& value);
static winrt::hstring StringOrEmptyIfPlaceholder(const winrt::hstring& placeholder, const winrt::hstring& value);

// Misc
static winrt::hstring AppendPercentageSign(double value);
static winrt::Windows::UI::Text::FontWeight DoubleToFontWeight(double value);
static winrt::Windows::UI::Xaml::Media::SolidColorBrush ColorToBrush(winrt::Windows::UI::Color color);
static double FontWeightToDouble(winrt::Windows::UI::Text::FontWeight fontWeight);
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/UIHelpers/Converters.idl
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ namespace Microsoft.Terminal.UI
// Numbers
static Double PercentageToPercentageValue(Double value);
static Double PercentageValueToPercentage(Double value);
static String PercentageToPercentageString(Double value);

// Strings
static Boolean StringsAreNotEqual(String expected, String actual);
static Windows.UI.Xaml.Visibility StringNotEmptyToVisibility(String value);
static String StringOrEmptyIfPlaceholder(String placeholder, String value);

// Misc
static String AppendPercentageSign(Double value);
static Windows.UI.Text.FontWeight DoubleToFontWeight(Double value);
static Windows.UI.Xaml.Media.SolidColorBrush ColorToBrush(Windows.UI.Color color);
static Double FontWeightToDouble(Windows.UI.Text.FontWeight fontWeight);
Expand Down

0 comments on commit 98468f9

Please sign in to comment.