mirror of
https://github.com/microsoft/terminal.git
synced 2026-02-10 14:04:43 +00:00
Add FontWeightComboBox (and interact w/ slider)
This commit is contained in:
32
src/cascadia/TerminalSettingsEditor/FontWeightConverter.cpp
Normal file
32
src/cascadia/TerminalSettingsEditor/FontWeightConverter.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
#include "pch.h"
|
||||
#include "FontWeightConverter.h"
|
||||
#include "FontWeightConverter.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 FontWeightConverter::Convert(Foundation::IInspectable const& value,
|
||||
Windows::UI::Xaml::Interop::TypeName const& /* targetType */,
|
||||
Foundation::IInspectable const& /* parameter */,
|
||||
hstring const& /* language */)
|
||||
{
|
||||
const auto weight{ winrt::unbox_value<FontWeight>(value) };
|
||||
return winrt::box_value<double>(weight.Weight);
|
||||
}
|
||||
|
||||
Foundation::IInspectable FontWeightConverter::ConvertBack(Foundation::IInspectable const& value,
|
||||
Windows::UI::Xaml::Interop::TypeName const& /* targetType */,
|
||||
Foundation::IInspectable const& /*parameter*/,
|
||||
hstring const& /* language */)
|
||||
{
|
||||
const auto sliderVal{ winrt::unbox_value<double>(value) };
|
||||
FontWeight weight{ base::ClampedNumeric<uint16_t>(sliderVal) };
|
||||
return winrt::box_value<FontWeight>(weight);
|
||||
}
|
||||
}
|
||||
30
src/cascadia/TerminalSettingsEditor/FontWeightConverter.h
Normal file
30
src/cascadia/TerminalSettingsEditor/FontWeightConverter.h
Normal file
@@ -0,0 +1,30 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "FontWeightConverter.g.h"
|
||||
#include "Utils.h"
|
||||
|
||||
namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
|
||||
{
|
||||
struct FontWeightConverter : FontWeightConverterT<FontWeightConverter>
|
||||
{
|
||||
FontWeightConverter() = default;
|
||||
|
||||
Windows::Foundation::IInspectable Convert(Windows::Foundation::IInspectable const& value,
|
||||
Windows::UI::Xaml::Interop::TypeName const& targetType,
|
||||
Windows::Foundation::IInspectable const& parameter,
|
||||
hstring const& language);
|
||||
|
||||
Windows::Foundation::IInspectable ConvertBack(Windows::Foundation::IInspectable const& value,
|
||||
Windows::UI::Xaml::Interop::TypeName const& targetType,
|
||||
Windows::Foundation::IInspectable const& parameter,
|
||||
hstring const& language);
|
||||
};
|
||||
}
|
||||
|
||||
namespace winrt::Microsoft::Terminal::Settings::Editor::factory_implementation
|
||||
{
|
||||
BASIC_FACTORY(FontWeightConverter);
|
||||
}
|
||||
10
src/cascadia/TerminalSettingsEditor/FontWeightConverter.idl
Normal file
10
src/cascadia/TerminalSettingsEditor/FontWeightConverter.idl
Normal file
@@ -0,0 +1,10 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
namespace Microsoft.Terminal.Settings.Editor
|
||||
{
|
||||
runtimeclass FontWeightConverter : [default] Windows.UI.Xaml.Data.IValueConverter
|
||||
{
|
||||
FontWeightConverter();
|
||||
};
|
||||
}
|
||||
@@ -6,9 +6,13 @@
|
||||
#include "Profiles.g.cpp"
|
||||
#include "EnumEntry.h"
|
||||
|
||||
#include <LibraryResources.h>
|
||||
|
||||
using namespace winrt::Windows::UI::Text;
|
||||
using namespace winrt::Windows::UI::Xaml;
|
||||
using namespace winrt::Windows::UI::Xaml::Navigation;
|
||||
using namespace winrt::Windows::Foundation;
|
||||
using namespace winrt::Windows::Foundation::Collections;
|
||||
using namespace winrt::Windows::Storage;
|
||||
using namespace winrt::Windows::Storage::AccessCache;
|
||||
using namespace winrt::Windows::Storage::Pickers;
|
||||
@@ -16,6 +20,8 @@ using namespace winrt::Microsoft::Terminal::Settings::Model;
|
||||
|
||||
namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
|
||||
{
|
||||
static const auto CustomFontWeight{ winrt::make<EnumEntry>(RS_(L"Profile_FontWeightCustom/Content"), winrt::box_value<uint16_t>(0u)) };
|
||||
|
||||
Profiles::Profiles()
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -26,6 +32,10 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
|
||||
INITIALIZE_BINDABLE_ENUM_SETTING(CloseOnExitMode, CloseOnExitMode, winrt::Microsoft::Terminal::Settings::Model::CloseOnExitMode, L"Profile_CloseOnExit", L"Content");
|
||||
INITIALIZE_BINDABLE_ENUM_SETTING(BellStyle, BellStyle, winrt::Microsoft::Terminal::Settings::Model::BellStyle, L"Profile_BellStyle", L"Content");
|
||||
INITIALIZE_BINDABLE_ENUM_SETTING(ScrollState, ScrollbarState, winrt::Microsoft::Terminal::TerminalControl::ScrollbarState, L"Profile_ScrollbarVisibility", L"Content");
|
||||
|
||||
// manually add Custom FontWeight option. Don't add it to the Map
|
||||
INITIALIZE_BINDABLE_ENUM_SETTING(FontWeight, FontWeight, uint16_t, L"Profile_FontWeight", L"Content");
|
||||
_FontWeightList.Append(CustomFontWeight);
|
||||
}
|
||||
|
||||
void Profiles::OnNavigatedTo(const NavigationEventArgs& e)
|
||||
@@ -84,4 +94,56 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
bool Profiles::_IsCustomFontWeight(const Windows::UI::Text::FontWeight& weight)
|
||||
{
|
||||
if (weight == FontWeights::Thin() ||
|
||||
weight == FontWeights::ExtraLight() ||
|
||||
weight == FontWeights::Light() ||
|
||||
weight == FontWeights::SemiLight() ||
|
||||
weight == FontWeights::Normal() ||
|
||||
weight == FontWeights::Medium() ||
|
||||
weight == FontWeights::SemiBold() ||
|
||||
weight == FontWeights::Bold() ||
|
||||
weight == FontWeights::ExtraBold() ||
|
||||
weight == FontWeights::Black() ||
|
||||
weight == FontWeights::ExtraBlack())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
IInspectable Profiles::CurrentFontWeight()
|
||||
{
|
||||
// if no value was found, we have a custom value, and we show the slider.
|
||||
const auto maybeEnumEntry{ _FontWeightMap.TryLookup(_State.Profile().FontWeight().Weight) };
|
||||
FontWeightSlider().Visibility(maybeEnumEntry ? Visibility::Collapsed : Visibility::Visible);
|
||||
return winrt::box_value<Editor::EnumEntry>(maybeEnumEntry ? maybeEnumEntry : CustomFontWeight);
|
||||
}
|
||||
|
||||
void Profiles::CurrentFontWeight(const IInspectable& enumEntry)
|
||||
{
|
||||
if (auto ee = enumEntry.try_as<Editor::EnumEntry>())
|
||||
{
|
||||
const auto weight{ winrt::unbox_value<uint16_t>(ee.EnumValue()) };
|
||||
const Windows::UI::Text::FontWeight setting{ weight };
|
||||
if (_IsCustomFontWeight(setting))
|
||||
{
|
||||
// Custom FontWeight is selected using the slider
|
||||
// Initialize the value to what is currently set
|
||||
FontWeightSlider().Visibility(Visibility::Visible);
|
||||
FontWeightSlider().Value(_State.Profile().FontWeight().Weight);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Otherwise, the selected ComboBox item has an associated fontWeight
|
||||
FontWeightSlider().Visibility(Visibility::Collapsed);
|
||||
_State.Profile().FontWeight(setting);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,12 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
|
||||
// This crashes on click, for some reason
|
||||
//fire_and_forget StartingDirectory_Click(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::RoutedEventArgs const& e);
|
||||
|
||||
// manually bind FontWeight
|
||||
winrt::Windows::Foundation::IInspectable CurrentFontWeight();
|
||||
void CurrentFontWeight(const winrt::Windows::Foundation::IInspectable& enumEntry);
|
||||
GETSET_PROPERTY(winrt::Windows::Foundation::Collections::IObservableVector<winrt::Microsoft::Terminal::Settings::Editor::EnumEntry>, FontWeightList);
|
||||
|
||||
|
||||
GETSET_PROPERTY(Editor::ProfilePageNavigationState, State, nullptr);
|
||||
GETSET_BINDABLE_ENUM_SETTING(CursorShape, winrt::Microsoft::Terminal::TerminalControl::CursorStyle, State().Profile, CursorShape);
|
||||
GETSET_BINDABLE_ENUM_SETTING(BackgroundImageStretchMode, winrt::Windows::UI::Xaml::Media::Stretch, State().Profile, BackgroundImageStretchMode);
|
||||
@@ -45,6 +51,11 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
|
||||
GETSET_BINDABLE_ENUM_SETTING(CloseOnExitMode, winrt::Microsoft::Terminal::Settings::Model::CloseOnExitMode, State().Profile, CloseOnExit);
|
||||
GETSET_BINDABLE_ENUM_SETTING(BellStyle, winrt::Microsoft::Terminal::Settings::Model::BellStyle, State().Profile, BellStyle);
|
||||
GETSET_BINDABLE_ENUM_SETTING(ScrollState, winrt::Microsoft::Terminal::TerminalControl::ScrollbarState, State().Profile, ScrollState);
|
||||
|
||||
private:
|
||||
winrt::Windows::Foundation::Collections::IMap<uint16_t, winrt::Microsoft::Terminal::Settings::Editor::EnumEntry> _FontWeightMap;
|
||||
|
||||
static bool _IsCustomFontWeight(const Windows::UI::Text::FontWeight& weight);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -33,5 +33,8 @@ namespace Microsoft.Terminal.Settings.Editor
|
||||
|
||||
IInspectable CurrentScrollState;
|
||||
Windows.Foundation.Collections.IObservableVector<Microsoft.Terminal.Settings.Editor.EnumEntry> ScrollStateList { get; };
|
||||
|
||||
IInspectable CurrentFontWeight;
|
||||
Windows.Foundation.Collections.IObservableVector<Microsoft.Terminal.Settings.Editor.EnumEntry> FontWeightList { get; };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,10 @@ the MIT License. See LICENSE in the project root for license information. -->
|
||||
<RadioButton Content="{x:Bind EnumName, Mode=OneWay}"/>
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate x:DataType="local:EnumEntry" x:Key="EnumComboBoxItemTemplate">
|
||||
<TextBlock Text="{x:Bind EnumName, Mode=OneWay}"/>
|
||||
</DataTemplate>
|
||||
|
||||
<local:ColorToBrushConverter x:Key="ColorToBrushConverter"/>
|
||||
<local:PercentageConverter x:Key="PercentageConverter"/>
|
||||
<local:FontWeightConverter x:Key="FontWeightConverter"/>
|
||||
@@ -80,7 +84,21 @@ the MIT License. See LICENSE in the project root for license information. -->
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Column="0" Grid.Row="1" Margin="0,0,100,0">
|
||||
<Controls:NumberBox x:Uid="Profile_FontSize" Margin="0,0,0,20" FontSize="15" Value="{x:Bind State.Profile.FontSize, Mode=TwoWay}" SpinButtonPlacementMode="Compact" SmallChange="1" LargeChange="10" ToolTipService.Placement="Mouse" />
|
||||
<Slider x:Uid="Profile_FontWeight" Minimum="1" Maximum="999" Value="{x:Bind State.Profile.FontWeight, Converter={StaticResource FontWeightConverter}, Mode=TwoWay}"/>
|
||||
<StackPanel>
|
||||
<ComboBox x:Uid="Profile_FontWeight"
|
||||
x:Name="FontWeightComboBox"
|
||||
Margin="0,0,0,20"
|
||||
ItemsSource="{x:Bind FontWeightList, Mode=OneWay}"
|
||||
SelectedItem="{x:Bind CurrentFontWeight, Mode=TwoWay}"
|
||||
ItemTemplate="{StaticResource EnumComboBoxItemTemplate}"
|
||||
FontSize="15"
|
||||
ToolTipService.Placement="Mouse"/>
|
||||
<Slider x:Name="FontWeightSlider"
|
||||
Minimum="1" Maximum="999"
|
||||
Value="{x:Bind State.Profile.FontWeight,
|
||||
Converter={StaticResource FontWeightConverter},
|
||||
Mode=TwoWay}"/>
|
||||
</StackPanel>
|
||||
<TextBox x:Uid="Profile_Padding" Margin="0,0,0,20" FontSize="15" Text="{x:Bind State.Profile.Padding, Mode=TwoWay}" ToolTipService.Placement="Mouse"/>
|
||||
<Controls:RadioButtons x:Uid="Profile_CursorShape"
|
||||
ItemsSource="{x:Bind CursorShapeList, Mode=OneWay}"
|
||||
|
||||
@@ -684,4 +684,40 @@
|
||||
<data name="Globals_DisableDynamicProfiles.[using:Windows.UI.Xaml.Controls]ToolTipService.ToolTip" xml:space="preserve">
|
||||
<value>Enables all of the dynamic profile generators, adding their profiles to the list of profiles on startup.</value>
|
||||
</data>
|
||||
<data name="Profile_FontWeightBlack.Content" xml:space="preserve">
|
||||
<value>Black</value>
|
||||
</data>
|
||||
<data name="Profile_FontWeightBold.Content" xml:space="preserve">
|
||||
<value>Bold</value>
|
||||
</data>
|
||||
<data name="Profile_FontWeightCustom.Content" xml:space="preserve">
|
||||
<value>Custom</value>
|
||||
</data>
|
||||
<data name="Profile_FontWeightExtra-black.Content" xml:space="preserve">
|
||||
<value>Extra-Black</value>
|
||||
</data>
|
||||
<data name="Profile_FontWeightExtra-bold.Content" xml:space="preserve">
|
||||
<value>Extra-Bold</value>
|
||||
</data>
|
||||
<data name="Profile_FontWeightExtra-light.Content" xml:space="preserve">
|
||||
<value>Extra-Light</value>
|
||||
</data>
|
||||
<data name="Profile_FontWeightLight.Content" xml:space="preserve">
|
||||
<value>Light</value>
|
||||
</data>
|
||||
<data name="Profile_FontWeightMedium.Content" xml:space="preserve">
|
||||
<value>Medium</value>
|
||||
</data>
|
||||
<data name="Profile_FontWeightNormal.Content" xml:space="preserve">
|
||||
<value>Normal</value>
|
||||
</data>
|
||||
<data name="Profile_FontWeightSemi-bold.Content" xml:space="preserve">
|
||||
<value>Semi-Bold</value>
|
||||
</data>
|
||||
<data name="Profile_FontWeightSemi-light.Content" xml:space="preserve">
|
||||
<value>Semi-Light</value>
|
||||
</data>
|
||||
<data name="Profile_FontWeightThin.Content" xml:space="preserve">
|
||||
<value>Thin</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -33,6 +33,7 @@
|
||||
|
||||
#include <winrt/Windows.UI.h>
|
||||
#include <winrt/Windows.UI.Core.h>
|
||||
#include <winrt/Windows.UI.Text.h>
|
||||
#include <winrt/Windows.UI.Input.h>
|
||||
#include <winrt/Windows.UI.Popups.h>
|
||||
#include <winrt/Windows.UI.Xaml.h>
|
||||
|
||||
@@ -41,4 +41,17 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
|
||||
DEFINE_ENUM_MAP(Microsoft::Terminal::TerminalControl::TextAntialiasingMode, TextAntialiasingMode);
|
||||
DEFINE_ENUM_MAP(Microsoft::Terminal::TerminalControl::CursorStyle, CursorStyle);
|
||||
DEFINE_ENUM_MAP(Model::BellStyle, BellStyle);
|
||||
|
||||
winrt::Windows::Foundation::Collections::IMap<winrt::hstring, uint16_t> EnumMappings::FontWeight()
|
||||
{
|
||||
static IMap<winrt::hstring, uint16_t> enumMap = []() {
|
||||
auto map = single_threaded_map<winrt::hstring, uint16_t>();
|
||||
for (auto [enumStr, enumVal] : JsonUtils::ConversionTrait<Windows::UI::Text::FontWeight>::mappings)
|
||||
{
|
||||
map.Insert(winrt::to_hstring(enumStr), enumVal);
|
||||
}
|
||||
return map;
|
||||
}();
|
||||
return enumMap;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
|
||||
static winrt::Windows::Foundation::Collections::IMap<winrt::hstring, winrt::Microsoft::Terminal::TerminalControl::TextAntialiasingMode> TextAntialiasingMode();
|
||||
static winrt::Windows::Foundation::Collections::IMap<winrt::hstring, winrt::Microsoft::Terminal::TerminalControl::CursorStyle> CursorStyle();
|
||||
static winrt::Windows::Foundation::Collections::IMap<winrt::hstring, BellStyle> BellStyle();
|
||||
static winrt::Windows::Foundation::Collections::IMap<winrt::hstring, uint16_t> FontWeight();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -19,5 +19,6 @@ namespace Microsoft.Terminal.Settings.Model
|
||||
static Windows.Foundation.Collections.IMap<String, Microsoft.Terminal.TerminalControl.TextAntialiasingMode> TextAntialiasingMode { get; };
|
||||
static Windows.Foundation.Collections.IMap<String, Microsoft.Terminal.TerminalControl.CursorStyle> CursorStyle { get; };
|
||||
static Windows.Foundation.Collections.IMap<String, Microsoft.Terminal.Settings.Model.BellStyle> BellStyle { get; };
|
||||
static Windows.Foundation.Collections.IMap<String, UInt16> FontWeight { get; };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,23 +116,23 @@ JSON_ENUM_MAPPER(::winrt::Microsoft::Terminal::Settings::Model::CloseOnExitMode)
|
||||
template<>
|
||||
struct ::Microsoft::Terminal::Settings::Model::JsonUtils::ConversionTrait<::winrt::Windows::UI::Text::FontWeight> :
|
||||
public ::Microsoft::Terminal::Settings::Model::JsonUtils::EnumMapper<
|
||||
unsigned int,
|
||||
uint16_t,
|
||||
::Microsoft::Terminal::Settings::Model::JsonUtils::ConversionTrait<::winrt::Windows::UI::Text::FontWeight>>
|
||||
{
|
||||
// The original parser used the font weight getters Bold(), Normal(), etc.
|
||||
// They were both cumbersome and *not constant expressions*
|
||||
JSON_MAPPINGS(11) = {
|
||||
pair_type{ "thin", 100u },
|
||||
pair_type{ "extra-light", 200u },
|
||||
pair_type{ "light", 300u },
|
||||
pair_type{ "semi-light", 350u },
|
||||
pair_type{ "normal", 400u },
|
||||
pair_type{ "medium", 500u },
|
||||
pair_type{ "semi-bold", 600u },
|
||||
pair_type{ "bold", 700u },
|
||||
pair_type{ "extra-bold", 800u },
|
||||
pair_type{ "black", 900u },
|
||||
pair_type{ "extra-black", 950u },
|
||||
pair_type{ "thin", static_cast<uint16_t>(100u) },
|
||||
pair_type{ "extra-light", static_cast<uint16_t>(200u) },
|
||||
pair_type{ "light", static_cast<uint16_t>(300u) },
|
||||
pair_type{ "semi-light", static_cast<uint16_t>(350u) },
|
||||
pair_type{ "normal", static_cast<uint16_t>(400u) },
|
||||
pair_type{ "medium", static_cast<uint16_t>(500u) },
|
||||
pair_type{ "semi-bold", static_cast<uint16_t>(600u) },
|
||||
pair_type{ "bold", static_cast<uint16_t>(700u) },
|
||||
pair_type{ "extra-bold", static_cast<uint16_t>(800u) },
|
||||
pair_type{ "black", static_cast<uint16_t>(900u) },
|
||||
pair_type{ "extra-black", static_cast<uint16_t>(950u) },
|
||||
};
|
||||
|
||||
// Override mapping parser to add boolean parsing
|
||||
@@ -149,7 +149,7 @@ struct ::Microsoft::Terminal::Settings::Model::JsonUtils::ConversionTrait<::winr
|
||||
}
|
||||
|
||||
::winrt::Windows::UI::Text::FontWeight weight{
|
||||
static_cast<uint16_t>(std::clamp(value, 100u, 990u))
|
||||
static_cast<uint16_t>(std::clamp(value, 1u, 999u))
|
||||
};
|
||||
return weight;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user