diff --git a/src/cascadia/TerminalSettingsEditor/Appearances.idl b/src/cascadia/TerminalSettingsEditor/Appearances.idl index 0859e00349d..45f07acaa44 100644 --- a/src/cascadia/TerminalSettingsEditor/Appearances.idl +++ b/src/cascadia/TerminalSettingsEditor/Appearances.idl @@ -122,7 +122,6 @@ namespace Microsoft.Terminal.Settings.Editor Windows.Foundation.Collections.IObservableVector FontWeightList { get; }; IInspectable CurrentFontFace { get; }; - Windows.UI.Xaml.Controls.Slider BIOpacitySlider { get; }; IInspectable CurrentIntenseTextStyle; Windows.Foundation.Collections.IObservableVector IntenseTextStyleList { get; }; diff --git a/src/cascadia/TerminalSettingsEditor/Appearances.xaml b/src/cascadia/TerminalSettingsEditor/Appearances.xaml index 1c6dc506052..35236fc509b 100644 --- a/src/cascadia/TerminalSettingsEditor/Appearances.xaml +++ b/src/cascadia/TerminalSettingsEditor/Appearances.xaml @@ -739,13 +739,12 @@ - + Text="{x:Bind mtu:Converters.PercentageToPercentageString(Appearance.BackgroundImageOpacity), Mode=OneWay}" /> diff --git a/src/cascadia/TerminalSettingsEditor/Profiles_Appearance.idl b/src/cascadia/TerminalSettingsEditor/Profiles_Appearance.idl index 931edbe5197..9cbe8c1a64e 100644 --- a/src/cascadia/TerminalSettingsEditor/Profiles_Appearance.idl +++ b/src/cascadia/TerminalSettingsEditor/Profiles_Appearance.idl @@ -10,7 +10,5 @@ namespace Microsoft.Terminal.Settings.Editor Profiles_Appearance(); ProfileViewModel Profile { get; }; IHostedInWindow WindowRoot { get; }; - - Windows.UI.Xaml.Controls.Slider OpacitySlider { get; }; } } diff --git a/src/cascadia/TerminalSettingsEditor/Profiles_Appearance.xaml b/src/cascadia/TerminalSettingsEditor/Profiles_Appearance.xaml index d996c5cd483..9212612edd7 100644 --- a/src/cascadia/TerminalSettingsEditor/Profiles_Appearance.xaml +++ b/src/cascadia/TerminalSettingsEditor/Profiles_Appearance.xaml @@ -76,13 +76,12 @@ - + Text="{x:Bind mtu:Converters.PercentageToPercentageString(Profile.Opacity), Mode=OneWay}" /> diff --git a/src/cascadia/UIHelpers/Converters.cpp b/src/cascadia/UIHelpers/Converters.cpp index 4fadb445d18..997f0e5ec7d 100644 --- a/src/cascadia/UIHelpers/Converters.cpp +++ b/src/cascadia/UIHelpers/Converters.cpp @@ -7,58 +7,84 @@ namespace winrt::Microsoft::Terminal::UI::implementation { - winrt::hstring Converters::AppendPercentageSign(double value) + // Booleans + bool Converters::InvertBoolean(bool value) { - return to_hstring(gsl::narrow_cast(std::lrint(value))) + L"%"; + return !value; } - winrt::Windows::UI::Xaml::Media::SolidColorBrush Converters::ColorToBrush(const winrt::Windows::UI::Color& color) + winrt::Windows::UI::Xaml::Visibility Converters::InvertedBooleanToVisibility(bool value) { - return Windows::UI::Xaml::Media::SolidColorBrush(color); + return value ? winrt::Windows::UI::Xaml::Visibility::Collapsed : winrt::Windows::UI::Xaml::Visibility::Visible; } - winrt::Windows::UI::Text::FontWeight Converters::DoubleToFontWeight(double value) + // Numbers + double Converters::PercentageToPercentageValue(double value) { - return winrt::Windows::UI::Text::FontWeight{ base::ClampedNumeric(value) }; + return value * 100.0; } - double Converters::FontWeightToDouble(const winrt::Windows::UI::Text::FontWeight& fontWeight) + double Converters::PercentageValueToPercentage(double value) { - return fontWeight.Weight; + return value / 100.0; } - bool Converters::InvertBoolean(bool value) + winrt::hstring Converters::PercentageToPercentageString(double value) { - return !value; + return winrt::hstring{ fmt::format(FMT_COMPILE(L"{:.0f}%"), value * 100.0) }; } - winrt::Windows::UI::Xaml::Visibility Converters::InvertedBooleanToVisibility(bool value) + // Strings + bool Converters::StringsAreNotEqual(const winrt::hstring& expected, const winrt::hstring& actual) { - return value ? winrt::Windows::UI::Xaml::Visibility::Collapsed : winrt::Windows::UI::Xaml::Visibility::Visible; + return expected != actual; + } + + winrt::Windows::UI::Xaml::Visibility Converters::StringNotEmptyToVisibility(const winrt::hstring& value) + { + return value.empty() ? winrt::Windows::UI::Xaml::Visibility::Collapsed : winrt::Windows::UI::Xaml::Visibility::Visible; + } + + winrt::hstring Converters::StringOrEmptyIfPlaceholder(const winrt::hstring& placeholder, const winrt::hstring& value) + { + return placeholder == value ? L"" : value; + } + + // Misc + winrt::Windows::UI::Text::FontWeight Converters::DoubleToFontWeight(double value) + { + return winrt::Windows::UI::Text::FontWeight{ base::ClampedNumeric(value) }; + } + + winrt::Windows::UI::Xaml::Media::SolidColorBrush Converters::ColorToBrush(const winrt::Windows::UI::Color color) + { + return Windows::UI::Xaml::Media::SolidColorBrush(color); + } + + double Converters::FontWeightToDouble(const winrt::Windows::UI::Text::FontWeight fontWeight) + { + return fontWeight.Weight; } double Converters::MaxValueFromPaddingString(const winrt::hstring& paddingString) { - const auto singleCharDelim = L','; - std::wstringstream tokenStream(paddingString.c_str()); - std::wstring token; + std::wstring_view remaining{ paddingString }; double maxVal = 0; - size_t* idx = nullptr; // Get padding values till we run out of delimiter separated values in the stream // Non-numeral values detected will default to 0 - // std::getline will not throw exception unless flags are set on the wstringstream // std::stod will throw invalid_argument exception if the input is an invalid double value // std::stod will throw out_of_range exception if the input value is more than DBL_MAX try { - while (std::getline(tokenStream, token, singleCharDelim)) + while (!remaining.empty()) { + const std::wstring token{ til::prefix_split(remaining, L',') }; // std::stod internally calls wcstod which handles whitespace prefix (which is ignored) // & stops the scan when first char outside the range of radix is encountered // We'll be permissive till the extent that stod function allows us to be by default // Ex. a value like 100.3#535w2 will be read as 100.3, but ;df25 will fail - const auto curVal = std::stod(token, idx); + const auto curVal = std::stod(token); if (curVal > maxVal) { maxVal = curVal; @@ -74,35 +100,4 @@ namespace winrt::Microsoft::Terminal::UI::implementation return maxVal; } - - int Converters::PercentageToPercentageValue(double value) - { - return base::ClampMul(value, 100u); - } - - double Converters::PercentageValueToPercentage(double value) - { - return base::ClampDiv(value, 100); - } - - bool Converters::StringsAreNotEqual(const winrt::hstring& expected, const winrt::hstring& actual) - { - return expected != actual; - } - winrt::Windows::UI::Xaml::Visibility Converters::StringNotEmptyToVisibility(const winrt::hstring& value) - { - return value.empty() ? winrt::Windows::UI::Xaml::Visibility::Collapsed : winrt::Windows::UI::Xaml::Visibility::Visible; - } - - // Method Description: - // - Returns the value string, unless it matches the placeholder in which case the empty string. - // Arguments: - // - placeholder - the placeholder string. - // - value - the value string. - // Return Value: - // - The value string, unless it matches the placeholder in which case the empty string. - winrt::hstring Converters::StringOrEmptyIfPlaceholder(const winrt::hstring& placeholder, const winrt::hstring& value) - { - return placeholder == value ? L"" : value; - } } diff --git a/src/cascadia/UIHelpers/Converters.h b/src/cascadia/UIHelpers/Converters.h index 366703e4fe7..6fda669605b 100644 --- a/src/cascadia/UIHelpers/Converters.h +++ b/src/cascadia/UIHelpers/Converters.h @@ -9,19 +9,25 @@ namespace winrt::Microsoft::Terminal::UI::implementation { struct Converters { - Converters() = default; - static winrt::hstring AppendPercentageSign(double value); - static winrt::Windows::UI::Text::FontWeight DoubleToFontWeight(double value); - static winrt::Windows::UI::Xaml::Media::SolidColorBrush ColorToBrush(const winrt::Windows::UI::Color& color); - static double FontWeightToDouble(const winrt::Windows::UI::Text::FontWeight& fontWeight); + // Booleans static bool InvertBoolean(bool value); static winrt::Windows::UI::Xaml::Visibility InvertedBooleanToVisibility(bool value); - static double MaxValueFromPaddingString(const winrt::hstring& paddingString); - static int PercentageToPercentageValue(double value); + + // 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::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); + static double MaxValueFromPaddingString(const winrt::hstring& paddingString); }; } diff --git a/src/cascadia/UIHelpers/Converters.idl b/src/cascadia/UIHelpers/Converters.idl index 99e70886c7f..2c9ef90e39d 100644 --- a/src/cascadia/UIHelpers/Converters.idl +++ b/src/cascadia/UIHelpers/Converters.idl @@ -12,8 +12,9 @@ namespace Microsoft.Terminal.UI static Windows.UI.Xaml.Visibility InvertedBooleanToVisibility(Boolean value); // Numbers - static Int32 PercentageToPercentageValue(Double value); + static Double PercentageToPercentageValue(Double value); static Double PercentageValueToPercentage(Double value); + static String PercentageToPercentageString(Double value); // Strings static Boolean StringsAreNotEqual(String expected, String actual); @@ -21,7 +22,6 @@ namespace Microsoft.Terminal.UI 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);