Add a slider for the padding setting in the SUI (#8851)

Replaces the textbox used for the padding setting with a slider

References #8764
This commit is contained in:
PankajBhojwani 2021-01-25 18:22:24 -08:00 committed by GitHub
parent 7b6958405e
commit b50df20cfe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 107 additions and 4 deletions

View file

@ -39,6 +39,11 @@ namespace Microsoft.Terminal.Settings.Editor
StringIsEmptyConverter();
};
runtimeclass PaddingConverter : [default] Windows.UI.Xaml.Data.IValueConverter
{
PaddingConverter();
};
runtimeclass StringIsNotDesktopConverter : [default] Windows.UI.Xaml.Data.IValueConverter
{
StringIsNotDesktopConverter();

View file

@ -53,6 +53,9 @@
<ClInclude Include="StringIsEmptyConverter.h">
<DependentUpon>Converters.idl</DependentUpon>
</ClInclude>
<ClInclude Include="PaddingConverter.h">
<DependentUpon>Converters.idl</DependentUpon>
</ClInclude>
<ClInclude Include="StringIsNotDesktopConverter.h">
<DependentUpon>Converters.idl</DependentUpon>
</ClInclude>
@ -135,6 +138,9 @@
<ClCompile Include="StringIsEmptyConverter.cpp">
<DependentUpon>Converters.idl</DependentUpon>
</ClCompile>
<ClCompile Include="PaddingConverter.cpp">
<DependentUpon>Converters.idl</DependentUpon>
</ClCompile>
<ClCompile Include="StringIsNotDesktopConverter.cpp">
<DependentUpon>Converters.idl</DependentUpon>
</ClCompile>

View file

@ -0,0 +1,65 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include "pch.h"
#include "PaddingConverter.h"
#include "PaddingConverter.g.cpp"
using namespace winrt::Windows;
using namespace winrt::Windows::UI::Xaml;
using namespace winrt::Windows::UI::Text;
namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
{
Foundation::IInspectable PaddingConverter::Convert(Foundation::IInspectable const& value,
Windows::UI::Xaml::Interop::TypeName const& /* targetType */,
Foundation::IInspectable const& /* parameter */,
hstring const& /* language */)
{
const auto& padding = winrt::unbox_value<hstring>(value);
const wchar_t singleCharDelim = L',';
std::wstringstream tokenStream(padding.c_str());
std::wstring token;
double maxVal = 0;
size_t* idx = nullptr;
// Get padding values till we run out of delimiter separated values in the stream
// Non-numeral values detected will default to 0
// std::getline will not throw exception unless flags are set on the wstringstream
// std::stod will throw invalid_argument exception if the input is an invalid double value
// std::stod will throw out_of_range exception if the input value is more than DBL_MAX
try
{
while (std::getline(tokenStream, token, singleCharDelim))
{
// std::stod internally calls wcstod which handles whitespace prefix (which is ignored)
// & stops the scan when first char outside the range of radix is encountered
// We'll be permissive till the extent that stod function allows us to be by default
// Ex. a value like 100.3#535w2 will be read as 100.3, but ;df25 will fail
const auto curVal = std::stod(token, idx);
if (curVal > maxVal)
{
maxVal = curVal;
}
}
}
catch (...)
{
// If something goes wrong, even if due to a single bad padding value, we'll return default 0 padding
maxVal = 0;
LOG_CAUGHT_EXCEPTION();
}
return winrt::box_value<double>(maxVal);
}
Foundation::IInspectable PaddingConverter::ConvertBack(Foundation::IInspectable const& value,
Windows::UI::Xaml::Interop::TypeName const& /* targetType */,
Foundation::IInspectable const& /*parameter*/,
hstring const& /* language */)
{
const auto padding{ winrt::unbox_value<double>(value) };
return winrt::box_value(winrt::to_hstring(padding));
}
}

View file

@ -0,0 +1,9 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#pragma once
#include "PaddingConverter.g.h"
#include "../inc/cppwinrt_utils.h"
DECLARE_CONVERTER(winrt::Microsoft::Terminal::Settings::Editor, PaddingConverter);

View file

@ -206,6 +206,9 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
_BIAlignmentButtons.at(6) = BIAlign_BottomLeft();
_BIAlignmentButtons.at(7) = BIAlign_Bottom();
_BIAlignmentButtons.at(8) = BIAlign_BottomRight();
Profile_Padding().Text(RS_(L"Profile_Padding/Header"));
ToolTipService::SetToolTip(Padding_Presenter(), box_value(RS_(L"Profile_Padding/[using:Windows.UI.Xaml.Controls]ToolTipService/ToolTip")));
}
void Profiles::OnNavigatedTo(const NavigationEventArgs& e)

View file

@ -30,6 +30,7 @@ the MIT License. See LICENSE in the project root for license information. -->
<local:FontWeightConverter x:Key="FontWeightConverter"/>
<local:InvertedBooleanToVisibilityConverter x:Key="InvertedBooleanToVisibilityConverter"/>
<local:StringIsEmptyConverter x:Key="StringIsEmptyConverter"/>
<local:PaddingConverter x:Key="PaddingConverter"/>
<local:StringIsNotDesktopConverter x:Key="StringIsNotDesktopConverter"/>
<local:DesktopWallpaperToEmptyStringConverter x:Key="DesktopWallpaperToEmptyStringConverter"/>
@ -555,11 +556,25 @@ the MIT License. See LICENSE in the project root for license information. -->
<TextBlock x:Uid="Profile_WindowHeader" Style="{StaticResource SubtitleTextBlockStyle}"/>
<!--Padding-->
<ContentPresenter Style="{StaticResource SettingContainerStyle}"
<ContentPresenter x:Name="Padding_Presenter"
Style="{StaticResource SettingContainerStyle}"
Margin="0">
<TextBox x:Uid="Profile_Padding"
Text="{x:Bind State.Profile.Padding, Mode=TwoWay}"
Style="{StaticResource TextBoxSettingStyle}"/>
<StackPanel x:Name="PaddingControl">
<TextBlock x:Name="Profile_Padding"
Style="{StaticResource SliderHeaderStyle}"/>
<Grid Style="{StaticResource CustomSliderControlGridStyle}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Slider x:Name="PaddingSlider"
Grid.Column="0"
Value="{x:Bind State.Profile.Padding, Converter={StaticResource PaddingConverter}, Mode=TwoWay}"/>
<TextBlock Grid.Column="1"
Text="{Binding ElementName=PaddingSlider, Path=Value, Mode=OneWay}"
Style="{StaticResource SliderValueLabelStyle}"/>
</Grid>
</StackPanel>
</ContentPresenter>
<!--Scrollbar Visibility-->