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 3 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
116 changes: 114 additions & 2 deletions src/cascadia/TerminalSettingsEditor/ProfileViewModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,52 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
Opacity(static_cast<float>(value) / 100.0f);
};

void SetPadding(double value)
void SetLeftPadding(double value)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe SetXXXPadding(double value) functions can be overloaded but idk how to make it work with XAML.

{
Padding(to_hstring(value));
const hstring& padding = _GetNewPadding(PaddingDirection::Left, value);

Padding(padding);
Copy link
Member

Choose a reason for hiding this comment

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

Oh, I understand now. This will properly propagate the change notification through to Padding. You may still need to do the other notifications yourself.

Copy link
Member

Choose a reason for hiding this comment

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

That will allow you to turn this into a setter and a getter with normal two-way binding.

}

double GetLeftPadding(const winrt::hstring& padding)
{
return _GetPaddingValue(padding, PaddingDirection::Left);
}

void SetTopPadding(double value)
{
const hstring& padding = _GetNewPadding(PaddingDirection::Top, value);

Padding(padding);
}

double GetTopPadding(const winrt::hstring& padding)
{
return _GetPaddingValue(padding, PaddingDirection::Top);
}

void SetRightPadding(double value)
{
const hstring& padding = _GetNewPadding(PaddingDirection::Right, value);

Padding(padding);
}

double GetRightPadding(const winrt::hstring& padding)
{
return _GetPaddingValue(padding, PaddingDirection::Right);
}

void SetBottomPadding(double value)
{
const hstring& padding = _GetNewPadding(PaddingDirection::Bottom, value);

Padding(padding);
}

double GetBottomPadding(const winrt::hstring& padding)
{
return _GetPaddingValue(padding, PaddingDirection::Bottom);
}

winrt::hstring EvaluatedIcon() const
Expand Down Expand Up @@ -140,6 +183,75 @@ 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
{
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 _GetPaddingValue(const winrt::hstring& padding, PaddingDirection paddingDirection) const
{
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;
}
};

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

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

void SetLeftPadding(Double value);
Double GetLeftPadding(String padding);
void SetTopPadding(Double value);
Double GetTopPadding(String padding);
void SetRightPadding(Double value);
Double GetRightPadding(String padding);
void SetBottomPadding(Double value);
Double GetBottomPadding(String padding);

Boolean IsBellStyleFlagSet(UInt32 flag);
void SetBellStyleAudible(Windows.Foundation.IReference<Boolean> on);
void SetBellStyleWindow(Windows.Foundation.IReference<Boolean> on);
Expand Down Expand Up @@ -74,7 +82,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.GetLeftPadding(Profile.Padding), BindBack=Profile.SetLeftPadding, 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.GetTopPadding(Profile.Padding), BindBack=Profile.SetTopPadding, 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.GetRightPadding(Profile.Padding), BindBack=Profile.SetRightPadding, 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.GetBottomPadding(Profile.Padding), BindBack=Profile.SetBottomPadding, Mode=TwoWay}" />

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

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