diff --git a/src/cascadia/TerminalSettingsEditor/ProfileViewModel.cpp b/src/cascadia/TerminalSettingsEditor/ProfileViewModel.cpp index 2dc89d90b98..2ccba06e25e 100644 --- a/src/cascadia/TerminalSettingsEditor/ProfileViewModel.cpp +++ b/src/cascadia/TerminalSettingsEditor/ProfileViewModel.cpp @@ -81,6 +81,10 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation { _NotifyChanges(L"CurrentPathTranslationStyle"); } + else if (viewModelProperty == L"Padding") + { + _NotifyChanges(L"LeftPadding", L"TopPadding", L"RightPadding", L"BottomPadding"); + } }); // Do the same for the starting directory @@ -103,6 +107,147 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation _defaultAppearanceViewModel.IsDefault(true); } + void ProfileViewModel::LeftPadding(double value) noexcept + { + const hstring& padding = _GetNewPadding(PaddingDirection::Left, value); + + Padding(padding); + } + + double ProfileViewModel::LeftPadding() const noexcept + { + return _GetPaddingValue(PaddingDirection::Left); + } + + void ProfileViewModel::TopPadding(double value) noexcept + { + const hstring& padding = _GetNewPadding(PaddingDirection::Top, value); + + Padding(padding); + } + + double ProfileViewModel::TopPadding() const noexcept + { + return _GetPaddingValue(PaddingDirection::Top); + } + + void ProfileViewModel::RightPadding(double value) noexcept + { + const hstring& padding = _GetNewPadding(PaddingDirection::Right, value); + + Padding(padding); + } + + double ProfileViewModel::RightPadding() const noexcept + { + return _GetPaddingValue(PaddingDirection::Right); + } + + void ProfileViewModel::BottomPadding(double value) noexcept + { + const hstring& padding = _GetNewPadding(PaddingDirection::Bottom, value); + + Padding(padding); + } + + double ProfileViewModel::BottomPadding() const noexcept + { + return _GetPaddingValue(PaddingDirection::Bottom); + } + + winrt::hstring ProfileViewModel::_GetNewPadding(PaddingDirection paddingDirection, double newPaddingValue) const + { + std::array values{}; + std::wstring_view padding{ Padding() }; + uint32_t paddingIndex = static_cast(paddingDirection); + + try + { + uint32_t index = 0; + for (const auto& token : til::split_iterator{ padding, L',' }) + { + auto curVal = std::stod(std::wstring{ token }); + + if (paddingIndex == index) + { + curVal = newPaddingValue; + } + + values[index++] = curVal; + + if (index >= values.size()) + { + break; + } + } + } + catch (...) + { + values.fill(0); + LOG_CAUGHT_EXCEPTION(); + } + + const auto result = fmt::format(FMT_COMPILE(L"{:.6f}"), fmt::join(values, L",")); + + return winrt::hstring{ result }; + } + + double ProfileViewModel::_GetPaddingValue(PaddingDirection paddingDirection) const + { + std::wstring_view padding{ Padding() }; + uint32_t paddingIndex = static_cast(paddingDirection); + std::array paddingValues{}; + double paddingValue = 0.; + uint32_t index = 0; + + try + { + for (const auto& token : til::split_iterator{ padding, L',' }) + { + auto curVal = std::stod(std::wstring{ token }); + + paddingValues[index++] = curVal; + + if (index >= paddingValues.size()) + { + break; + } + } + } + catch (...) + { + paddingValue = 0.; + LOG_CAUGHT_EXCEPTION(); + } + + // Padding: 8 + if (index == 1) + { + paddingValue = paddingValues[0]; + } + // Padding: 8, 4 + else if (index == 2) + { + if (paddingDirection == PaddingDirection::Left || + paddingDirection == PaddingDirection::Right) + { + paddingValue = paddingValues[0]; + } + else if (paddingDirection == PaddingDirection::Top || + paddingDirection == PaddingDirection::Bottom) + { + paddingValue = paddingValues[1]; + } + } + // Padding: 8, 4, 8, 4 + else + { + paddingValue = paddingValues[paddingIndex]; + } + + return paddingValue; + } + Model::TerminalSettings ProfileViewModel::TermSettings() const { return Model::TerminalSettings::CreateForPreview(_appSettings, _profile); diff --git a/src/cascadia/TerminalSettingsEditor/ProfileViewModel.h b/src/cascadia/TerminalSettingsEditor/ProfileViewModel.h index 3e3be7286a5..ff6da726d3a 100644 --- a/src/cascadia/TerminalSettingsEditor/ProfileViewModel.h +++ b/src/cascadia/TerminalSettingsEditor/ProfileViewModel.h @@ -51,10 +51,14 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation Opacity(static_cast(value) / 100.0f); }; - void SetPadding(double value) - { - Padding(to_hstring(value)); - } + void LeftPadding(double value) noexcept; + double LeftPadding() const noexcept; + void TopPadding(double value) noexcept; + double TopPadding() const noexcept; + void RightPadding(double value) noexcept; + double RightPadding() const noexcept; + void BottomPadding(double value) noexcept; + double BottomPadding() const noexcept; winrt::hstring EvaluatedIcon() const { @@ -148,6 +152,17 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation Model::CascadiaSettings _appSettings; Editor::AppearanceViewModel _unfocusedAppearanceViewModel; + + enum class PaddingDirection + { + Left = 0, + Top = 1, + Right = 2, + Bottom = 3 + }; + + winrt::hstring _GetNewPadding(PaddingDirection paddingDirection, double newPaddingValue) const; + double _GetPaddingValue(PaddingDirection paddingDirection) const; }; struct DeleteProfileEventArgs : diff --git a/src/cascadia/TerminalSettingsEditor/ProfileViewModel.idl b/src/cascadia/TerminalSettingsEditor/ProfileViewModel.idl index f3d1bd44633..c843a61836a 100644 --- a/src/cascadia/TerminalSettingsEditor/ProfileViewModel.idl +++ b/src/cascadia/TerminalSettingsEditor/ProfileViewModel.idl @@ -42,7 +42,6 @@ namespace Microsoft.Terminal.Settings.Editor void SetupAppearances(Windows.Foundation.Collections.IObservableVector schemesList); void SetAcrylicOpacityPercentageValue(Double value); - void SetPadding(Double value); Boolean IsBellStyleFlagSet(UInt32 flag); void SetBellStyleAudible(Windows.Foundation.IReference on); @@ -58,6 +57,11 @@ namespace Microsoft.Terminal.Settings.Editor IInspectable CurrentScrollState; Windows.Foundation.Collections.IObservableVector ScrollStateList { get; }; + Double LeftPadding { get; set; }; + Double TopPadding { get; set; }; + Double RightPadding { get; set; }; + Double BottomPadding { get; set; }; + IInspectable CurrentPathTranslationStyle; Windows.Foundation.Collections.IObservableVector PathTranslationStyleList { get; }; diff --git a/src/cascadia/TerminalSettingsEditor/Profiles_Appearance.xaml b/src/cascadia/TerminalSettingsEditor/Profiles_Appearance.xaml index 9212612edd7..f7c9bd68797 100644 --- a/src/cascadia/TerminalSettingsEditor/Profiles_Appearance.xaml +++ b/src/cascadia/TerminalSettingsEditor/Profiles_Appearance.xaml @@ -29,6 +29,24 @@ + + @@ -107,20 +125,66 @@ - - - - - - - - + SettingOverrideSource="{x:Bind Profile.PaddingOverrideSource, Mode=OneWay}" + Style="{StaticResource ExpanderSettingContainerStyle}"> + + + + + + + + + + + + + + + + + + + + + + + + +