From f79276b21bd34fb23adca1108fe836668998b0e9 Mon Sep 17 00:00:00 2001 From: Leonard Hecker Date: Tue, 20 Sep 2022 19:36:48 +0200 Subject: [PATCH] Fix font size rounding in the settings UI (#14040) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes an issue with c51bb3a, where some fractional font sizes are displayed as something like 13.600000000001. Closes #14024 ## Validation Steps Performed * Enter a font size of 13.6 and save * NumberBox displays "13.6" ✅ --- src/cascadia/TerminalSettingsEditor/Appearances.cpp | 11 +++++++++++ src/cascadia/TerminalSettingsEditor/Appearances.xaml | 3 ++- src/cascadia/TerminalSettingsEditor/pch.h | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/cascadia/TerminalSettingsEditor/Appearances.cpp b/src/cascadia/TerminalSettingsEditor/Appearances.cpp index e9760b88606..49d3082350e 100644 --- a/src/cascadia/TerminalSettingsEditor/Appearances.cpp +++ b/src/cascadia/TerminalSettingsEditor/Appearances.cpp @@ -91,6 +91,17 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation { InitializeComponent(); + { + using namespace winrt::Windows::Globalization::NumberFormatting; + // > .NET rounds to 12 significant digits when displaying doubles, so we will [...] + // ...obviously not do that, because this is an UI element for humans. This prevents + // issues when displaying 32-bit floats, because WinUI is unaware about their existence. + SignificantDigitsNumberRounder rounder; + rounder.SignificantDigits(6); + // BODGY: Depends on WinUI internals. + _fontSizeBox().NumberFormatter().as().NumberRounder(rounder); + } + INITIALIZE_BINDABLE_ENUM_SETTING(CursorShape, CursorStyle, winrt::Microsoft::Terminal::Core::CursorStyle, L"Profile_CursorShape", L"Content"); INITIALIZE_BINDABLE_ENUM_SETTING(AdjustIndistinguishableColors, AdjustIndistinguishableColors, winrt::Microsoft::Terminal::Core::AdjustTextMode, L"Profile_AdjustIndistinguishableColors", L"Content"); INITIALIZE_BINDABLE_ENUM_SETTING_REVERSE_ORDER(BackgroundImageStretchMode, BackgroundImageStretchMode, winrt::Windows::UI::Xaml::Media::Stretch, L"Profile_BackgroundImageStretchMode", L"Content"); diff --git a/src/cascadia/TerminalSettingsEditor/Appearances.xaml b/src/cascadia/TerminalSettingsEditor/Appearances.xaml index 2b00dbe545c..2e348581216 100644 --- a/src/cascadia/TerminalSettingsEditor/Appearances.xaml +++ b/src/cascadia/TerminalSettingsEditor/Appearances.xaml @@ -93,7 +93,8 @@ HasSettingValue="{x:Bind Appearance.HasFontSize, Mode=OneWay}" SettingOverrideSource="{x:Bind Appearance.FontSizeOverrideSource, Mode=OneWay}" Visibility="{x:Bind Appearance.IsDefault, Mode=OneWay}"> - #include #include +#include #include #include #include