From 5a64ea5d06218524feebbd428f9ee9b6cb38a3f9 Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Wed, 4 Oct 2023 11:21:14 -0700 Subject: [PATCH 01/27] editing/deleting works --- .../TerminalSettingsEditor/Appearances.cpp | 32 +++++++++++++++++++ .../TerminalSettingsEditor/Appearances.h | 32 +++++++++++++++++++ .../TerminalSettingsEditor/Appearances.idl | 15 +++++++++ .../TerminalSettingsEditor/Appearances.xaml | 18 +++++++++++ .../Resources/en-US/Resources.resw | 16 ++++++++++ 5 files changed, 113 insertions(+) diff --git a/src/cascadia/TerminalSettingsEditor/Appearances.cpp b/src/cascadia/TerminalSettingsEditor/Appearances.cpp index 8a3c9f943a2..90dd1e0ced1 100644 --- a/src/cascadia/TerminalSettingsEditor/Appearances.cpp +++ b/src/cascadia/TerminalSettingsEditor/Appearances.cpp @@ -4,6 +4,7 @@ #include "pch.h" #include "Appearances.h" #include "Appearances.g.cpp" +#include "AxisKeyValuePair.g.cpp" #include "EnumEntry.h" #include @@ -62,6 +63,15 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation } }); + _FontAxesVector = winrt::single_threaded_observable_vector(); + if (const auto fontAxesMap = _appearance.SourceProfile().FontInfo().FontAxes()) + { + for (const auto axis : fontAxesMap) + { + _FontAxesVector.Append(winrt::make(axis.Key(), axis.Value(), fontAxesMap)); + } + } + // Cache the original BG image path. If the user clicks "Use desktop // wallpaper", then un-checks it, this is the string we'll restore to // them. @@ -348,6 +358,8 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation biButton.IsChecked(biButton.Tag().as() == biAlignmentVal); } + FontAxesCVS().Source(Appearance().FontAxesVector()); + _ViewModelChangedRevoker = Appearance().PropertyChanged(winrt::auto_revoke, [=](auto&&, const PropertyChangedEventArgs& args) { const auto settingName{ args.PropertyName() }; if (settingName == L"CursorShape") @@ -470,6 +482,26 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation } } + void Appearances::AxisKeyValuePairDelete_Click(const IInspectable& sender, const RoutedEventArgs& /*e*/) + { + if (const auto& button{ sender.try_as() }) + { + if (const auto& tag{ button.Tag().try_as() }) + { + for (const auto axisKeyValuePair : Appearance().FontAxesVector()) + { + if (axisKeyValuePair.as().AxisKey() == tag) + { + uint32_t index; + Appearance().FontAxesVector().IndexOf(axisKeyValuePair, index); + Appearance().FontAxesVector().RemoveAt(index); + break; + } + } + } + } + } + bool Appearances::IsVintageCursor() const { return Appearance().CursorShape() == Core::CursorStyle::Vintage; diff --git a/src/cascadia/TerminalSettingsEditor/Appearances.h b/src/cascadia/TerminalSettingsEditor/Appearances.h index bc34e62978c..e4f4a3b156b 100644 --- a/src/cascadia/TerminalSettingsEditor/Appearances.h +++ b/src/cascadia/TerminalSettingsEditor/Appearances.h @@ -17,6 +17,7 @@ Author(s): #pragma once #include "Font.g.h" +#include "AxisKeyValuePair.g.h" #include "Appearances.g.h" #include "AppearanceViewModel.g.h" #include "Utils.h" @@ -54,6 +55,34 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation std::optional _hasPowerlineCharacters; }; + struct AxisKeyValuePair : AxisKeyValuePairT + { + AxisKeyValuePair(winrt::hstring axisKey, float axisValue, const Windows::Foundation::Collections::IMap& baseMap) : + _AxisKey{ axisKey }, + _AxisValue{ axisValue }, + _baseMap{ baseMap } {} + + winrt::hstring AxisKey() { return _AxisKey; } + float AxisValue() { return _AxisValue; } + + void AxisValue(float axisValue) { + _baseMap.Remove(_AxisKey); + _AxisValue = axisValue; + _baseMap.Insert(_AxisKey, _AxisValue); + } + + void AxisKey(winrt::hstring axisKey) { + _baseMap.Remove(_AxisKey); + _AxisKey = axisKey; + _baseMap.Insert(_AxisKey, _AxisValue); + } + + private: + winrt::hstring _AxisKey; + float _AxisValue; + Windows::Foundation::Collections::IMap _baseMap{ nullptr }; + }; + struct AppearanceViewModel : AppearanceViewModelT, ViewModelHelper { public: @@ -100,6 +129,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation OBSERVABLE_PROJECTED_SETTING(_appearance, IntenseTextStyle); OBSERVABLE_PROJECTED_SETTING(_appearance, AdjustIndistinguishableColors); WINRT_OBSERVABLE_PROPERTY(Windows::Foundation::Collections::IObservableVector, SchemesList, _propertyChangedHandlers, nullptr); + WINRT_OBSERVABLE_PROPERTY(Windows::Foundation::Collections::IObservableVector, FontAxesVector, _propertyChangedHandlers, nullptr); private: Model::AppearanceConfig _appearance; @@ -124,6 +154,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation fire_and_forget BackgroundImage_Click(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& e); void BIAlignment_Click(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& e); void FontFace_SelectionChanged(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::Controls::SelectionChangedEventArgs& e); + void AxisKeyValuePairDelete_Click(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& e); // manually bind FontWeight Windows::Foundation::IInspectable CurrentFontWeight() const; @@ -160,4 +191,5 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation namespace winrt::Microsoft::Terminal::Settings::Editor::factory_implementation { BASIC_FACTORY(Appearances); + BASIC_FACTORY(AxisKeyValuePair); } diff --git a/src/cascadia/TerminalSettingsEditor/Appearances.idl b/src/cascadia/TerminalSettingsEditor/Appearances.idl index 55ff2be721d..964cab54c0f 100644 --- a/src/cascadia/TerminalSettingsEditor/Appearances.idl +++ b/src/cascadia/TerminalSettingsEditor/Appearances.idl @@ -13,6 +13,8 @@ import "ColorSchemesPageViewModel.idl"; OBSERVABLE_PROJECTED_SETTING(Type, Name); \ Object Name##OverrideSource { get; } +#define COMMA , + namespace Microsoft.Terminal.Settings.Editor { runtimeclass Font : Windows.Foundation.IStringable @@ -22,6 +24,17 @@ namespace Microsoft.Terminal.Settings.Editor Boolean HasPowerlineCharacters { get; }; } + // We have to make this because we cannot bind an IObservableMap to a ListView in XAML (in c++) + // So instead we make an IVector of these AxisKeyValuePair objects + + // if wanna generalize this, make this an interface instead of runtimeclass + runtimeclass AxisKeyValuePair { + AxisKeyValuePair(String axisKey, Single axisValue, Windows.Foundation.Collections.IMap baseMap); + // make these iinspectable to generalize + String AxisKey; + Single AxisValue; + } + runtimeclass AppearanceViewModel : Windows.UI.Xaml.Data.INotifyPropertyChanged { Boolean IsDefault; @@ -37,6 +50,8 @@ namespace Microsoft.Terminal.Settings.Editor ColorSchemeViewModel CurrentColorScheme; Windows.Foundation.Collections.IObservableVector SchemesList; + Windows.Foundation.Collections.IObservableVector FontAxesVector; + OBSERVABLE_PROJECTED_APPEARANCE_SETTING(String, FontFace); OBSERVABLE_PROJECTED_APPEARANCE_SETTING(Single, FontSize); OBSERVABLE_PROJECTED_APPEARANCE_SETTING(Double, LineHeight); diff --git a/src/cascadia/TerminalSettingsEditor/Appearances.xaml b/src/cascadia/TerminalSettingsEditor/Appearances.xaml index e37cdd2e1bf..0670c6e96a3 100644 --- a/src/cascadia/TerminalSettingsEditor/Appearances.xaml +++ b/src/cascadia/TerminalSettingsEditor/Appearances.xaml @@ -37,6 +37,8 @@ Background="{x:Bind local:Converters.ColorToBrush(Color)}" CornerRadius="1" /> + @@ -287,6 +289,22 @@ + + + + + + + + + + + + + + diff --git a/src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw b/src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw index 0a68197f584..bce27af80cc 100644 --- a/src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw +++ b/src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw @@ -710,6 +710,10 @@ Browse... Button label that opens a file picker in a new window. The "..." is standard to mean it will open a new window. + + Add new + Button label that adds a new font axis for the current font. + Background image opacity Name for a control to choose the opacity of the image presented on the background of the app. diff --git a/src/cascadia/TerminalSettingsModel/FontConfig.cpp b/src/cascadia/TerminalSettingsModel/FontConfig.cpp index fafdf0976bc..3a9fe6c0b43 100644 --- a/src/cascadia/TerminalSettingsModel/FontConfig.cpp +++ b/src/cascadia/TerminalSettingsModel/FontConfig.cpp @@ -30,6 +30,17 @@ winrt::com_ptr FontConfig::CopyFontInfo(const FontConfig* source, wi MTSM_FONT_SETTINGS(FONT_SETTINGS_COPY) #undef FONT_SETTINGS_COPY + // We cannot simply copy the font axes and features with `fontInfo->_FontAxes = source->_FontAxes;` + // since that'll just create a reference; we have to manually copy the values. + if (source->_FontAxes) + { + fontInfo->_FontAxes = winrt::single_threaded_map(); + for (const auto kVPair : source->_FontAxes.value()) + { + fontInfo->_FontAxes.value().Insert(kVPair.Key(), kVPair.Value()); + } + } + return fontInfo; } From eac2fd221d8f34da3088defc6548b4343b89a22a Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Thu, 5 Oct 2023 10:29:54 -0700 Subject: [PATCH 03/27] spelling and format --- .../TerminalSettingsEditor/Appearances.h | 6 +++-- .../TerminalSettingsEditor/Appearances.idl | 3 --- .../TerminalSettingsEditor/Appearances.xaml | 26 +++++++++---------- .../TerminalSettingsModel/FontConfig.cpp | 4 +-- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/cascadia/TerminalSettingsEditor/Appearances.h b/src/cascadia/TerminalSettingsEditor/Appearances.h index a31e5dccff5..f65629315d9 100644 --- a/src/cascadia/TerminalSettingsEditor/Appearances.h +++ b/src/cascadia/TerminalSettingsEditor/Appearances.h @@ -65,13 +65,15 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation winrt::hstring AxisKey() { return _AxisKey; } float AxisValue() { return _AxisValue; } - void AxisValue(float axisValue) { + void AxisValue(float axisValue) + { _baseMap.Remove(_AxisKey); _AxisValue = axisValue; _baseMap.Insert(_AxisKey, _AxisValue); } - void AxisKey(winrt::hstring axisKey) { + void AxisKey(winrt::hstring axisKey) + { _baseMap.Remove(_AxisKey); _AxisKey = axisKey; _baseMap.Insert(_AxisKey, _AxisValue); diff --git a/src/cascadia/TerminalSettingsEditor/Appearances.idl b/src/cascadia/TerminalSettingsEditor/Appearances.idl index 0260914a50c..8db0461511a 100644 --- a/src/cascadia/TerminalSettingsEditor/Appearances.idl +++ b/src/cascadia/TerminalSettingsEditor/Appearances.idl @@ -26,11 +26,8 @@ namespace Microsoft.Terminal.Settings.Editor // We have to make this because we cannot bind an IObservableMap to a ListView in XAML (in c++) // So instead we make an IVector of these AxisKeyValuePair objects - - // if wanna generalize this, make this an interface instead of runtimeclass runtimeclass AxisKeyValuePair { AxisKeyValuePair(String axisKey, Single axisValue, Windows.Foundation.Collections.IMap baseMap); - // make these iinspectable to generalize String AxisKey; Single AxisValue; } diff --git a/src/cascadia/TerminalSettingsEditor/Appearances.xaml b/src/cascadia/TerminalSettingsEditor/Appearances.xaml index d4183b6406e..bbfaa1cf7f3 100644 --- a/src/cascadia/TerminalSettingsEditor/Appearances.xaml +++ b/src/cascadia/TerminalSettingsEditor/Appearances.xaml @@ -37,8 +37,8 @@ Background="{x:Bind local:Converters.ColorToBrush(Color)}" CornerRadius="1" /> - + @@ -292,8 +292,8 @@ - @@ -304,15 +304,15 @@ - - - @@ -323,8 +323,8 @@