mirror of
https://github.com/microsoft/terminal.git
synced 2025-12-10 18:43:54 -06:00
Add separate padding settings for left, top, right and bottom (#17909)
Left, Top, Right and Bottom paddings can be set separetely in `Appearance`. I tried to make it as close as possible to one of the suggestions in #9127. I hope it doesn't look that bad. Closes #9127
This commit is contained in:
parent
a41f915eda
commit
86a624517e
@ -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<double, 4> values{};
|
||||
std::wstring_view padding{ Padding() };
|
||||
uint32_t paddingIndex = static_cast<uint32_t>(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<uint32_t>(paddingDirection);
|
||||
std::array<double, 4> 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);
|
||||
|
||||
@ -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
|
||||
{
|
||||
@ -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 :
|
||||
|
||||
@ -42,7 +42,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);
|
||||
@ -58,6 +57,11 @@ 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; };
|
||||
|
||||
IInspectable CurrentPathTranslationStyle;
|
||||
Windows.Foundation.Collections.IObservableVector<Microsoft.Terminal.Settings.Editor.EnumEntry> PathTranslationStyleList { get; };
|
||||
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -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 -->
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user