Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add separate padding settings for left, top, right and bottom #17909

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions src/cascadia/TerminalSettingsEditor/ProfileViewModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
{
_NotifyChanges(L"HideIcon");
}
else if (viewModelProperty == L"Padding")
{
_NotifyChanges(L"LeftPadding", L"TopPadding", L"RightPadding", L"BottomPadding");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the directional padding setters Padding(padding) will call _notifyChanges(L "Padding") and _notifyChanges(L "HasPadding"). If I call _notifyChanges for all directional paddings here, it works, including the ClearPadding case.

}
});

// Do the same for the starting directory
Expand All @@ -98,6 +102,115 @@ 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<double, 4> values{};
std::wstring_view remaining{ Padding() };
uint32_t paddingIndex = static_cast<uint32_t>(paddingDirection);

try
{
for (uint32_t index = 0; !remaining.empty() && index < values.size(); ++index)
{
const std::wstring token{ til::prefix_split(remaining, L',') };
auto curVal = std::stod(token);

if (paddingIndex == index)
{
curVal = newPaddingValue;
}

values[index] = curVal;
}
}
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My only concern is that this pair of functions will mis-handle 1-part and 2-part paddings:

padding 8 should be parsed as 8,8,8,8; padding 8,4 should be parsed as 8,4,8,4

everything else, I'm totally ready to sign off!

{
std::wstring_view remaining{ Padding() };
uint32_t paddingIndex = static_cast<uint32_t>(paddingDirection);
double paddingValue = 0.;

try
{
for (uint32_t index = 0; !remaining.empty(); ++index)
{
const std::wstring token{ til::prefix_split(remaining, L',') };
auto curVal = std::stod(token);

if (paddingIndex == index)
{
paddingValue = curVal;
break;
}
}
}
catch (...)
{
paddingValue = 0.;
LOG_CAUGHT_EXCEPTION();
}

return paddingValue;
}

Model::TerminalSettings ProfileViewModel::TermSettings() const
{
return Model::TerminalSettings::CreateForPreview(_appSettings, _profile);
Expand Down
23 changes: 19 additions & 4 deletions src/cascadia/TerminalSettingsEditor/ProfileViewModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,14 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
Opacity(static_cast<float>(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
{
Expand Down Expand Up @@ -140,6 +144,17 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation

Model::CascadiaSettings _appSettings;
Editor::AppearanceViewModel _unfocusedAppearanceViewModel;

enum class PaddingDirection
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used this enum just to clarify the intention.

{
Left = 0,
Top = 1,
Right = 2,
Bottom = 3
};

winrt::hstring _GetNewPadding(PaddingDirection paddingDirection, double newPaddingValue) const;
double _GetPaddingValue(PaddingDirection paddingDirection) const;
};

struct DeleteProfileEventArgs :
Expand Down
7 changes: 5 additions & 2 deletions src/cascadia/TerminalSettingsEditor/ProfileViewModel.idl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ namespace Microsoft.Terminal.Settings.Editor
void SetupAppearances(Windows.Foundation.Collections.IObservableVector<ColorSchemeViewModel> schemesList);

void SetAcrylicOpacityPercentageValue(Double value);
void SetPadding(Double value);

Boolean IsBellStyleFlagSet(UInt32 flag);
void SetBellStyleAudible(Windows.Foundation.IReference<Boolean> on);
Expand All @@ -57,6 +56,10 @@ namespace Microsoft.Terminal.Settings.Editor
IInspectable CurrentScrollState;
Windows.Foundation.Collections.IObservableVector<Microsoft.Terminal.Settings.Editor.EnumEntry> ScrollStateList { get; };

Double LeftPadding { get; set; };
Double TopPadding { get; set; };
Double RightPadding { get; set; };
Double BottomPadding { get; set; };
Boolean CanDeleteProfile { get; };
Boolean FocusDeleteButton;
Boolean IsBaseLayer;
Expand All @@ -74,7 +77,7 @@ namespace Microsoft.Terminal.Settings.Editor
Boolean ShowMarksAvailable { get; };
Boolean AutoMarkPromptsAvailable { get; };
Boolean RepositionCursorWithMouseAvailable { get; };

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

String EvaluatedIcon { get; };

void CreateUnfocusedAppearance();
Expand Down
92 changes: 78 additions & 14 deletions src/cascadia/TerminalSettingsEditor/Profiles_Appearance.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@
<TextBlock FontFamily="{x:Bind Name}"
Text="{x:Bind LocalizedName}" />
</DataTemplate>

<Style x:Key="PaddingNumberBoxStyle"
TargetType="muxc:NumberBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="muxc:NumberBox">
<Grid x:Name="Root">
<TextBox x:Name="InputBox"
Padding="0,6"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Text="{Binding Value, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}"
TextAlignment="Center" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
</Page.Resources>

Expand Down Expand Up @@ -107,20 +125,66 @@
<local:SettingContainer x:Uid="Profile_Padding"
ClearSettingValue="{x:Bind Profile.ClearPadding}"
HasSettingValue="{x:Bind Profile.HasPadding, Mode=OneWay}"
SettingOverrideSource="{x:Bind Profile.PaddingOverrideSource, Mode=OneWay}">
<Grid Style="{StaticResource CustomSliderControlGridStyle}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Slider x:Name="PaddingSlider"
x:Uid="Profile_PaddingSlider"
Grid.Column="0"
Value="{x:Bind mtu:Converters.MaxValueFromPaddingString(Profile.Padding), BindBack=Profile.SetPadding, Mode=TwoWay}" />
<TextBlock Grid.Column="1"
Style="{StaticResource SliderValueLabelStyle}"
Text="{Binding ElementName=PaddingSlider, Path=Value, Mode=OneWay}" />
</Grid>
SettingOverrideSource="{x:Bind Profile.PaddingOverrideSource, Mode=OneWay}"
Style="{StaticResource ExpanderSettingContainerStyle}">
<Border Margin="0,12,0,12"
Padding="2,0,2,0"
HorizontalAlignment="Left"
BorderBrush="{ThemeResource SystemControlForegroundBaseMediumLowBrush}"
BorderThickness="1"
CornerRadius="8">
<Grid>

<Grid.RowDefinitions>
<RowDefinition Height="48" />
<RowDefinition Height="48" />
<RowDefinition Height="48" />
</Grid.RowDefinitions>

<Grid.ColumnDefinitions>
<ColumnDefinition Width="72" />
<ColumnDefinition Width="72" />
<ColumnDefinition Width="72" />
</Grid.ColumnDefinitions>

<muxc:NumberBox Grid.Row="1"
Grid.Column="0"
LargeChange="10"
Maximum="100"
Minimum="1"
SmallChange="1"
Style="{StaticResource PaddingNumberBoxStyle}"
Value="{x:Bind Profile.LeftPadding, Mode=TwoWay}" />

<muxc:NumberBox Grid.Row="0"
Grid.Column="1"
LargeChange="10"
Maximum="100"
Minimum="1"
SmallChange="1"
Style="{StaticResource PaddingNumberBoxStyle}"
Value="{x:Bind Profile.TopPadding, Mode=TwoWay}" />

<muxc:NumberBox Grid.Row="1"
Grid.Column="2"
LargeChange="10"
Maximum="100"
Minimum="1"
SmallChange="1"
Style="{StaticResource PaddingNumberBoxStyle}"
Value="{x:Bind Profile.RightPadding, Mode=TwoWay}" />

<muxc:NumberBox Grid.Row="2"
Grid.Column="1"
LargeChange="10"
Maximum="100"
Minimum="1"
SmallChange="1"
Style="{StaticResource PaddingNumberBoxStyle}"
Value="{x:Bind Profile.BottomPadding, Mode=TwoWay}" />

</Grid>
</Border>
</local:SettingContainer>

<!-- Scrollbar Visibility -->
Expand Down
Loading