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 nullable colors to settings UI #17870

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
57 changes: 56 additions & 1 deletion src/cascadia/TerminalSettingsEditor/Appearances.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,26 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
// box, prevent it from ever being changed again.
_NotifyChanges(L"UseDesktopBGImage", L"BackgroundImageSettingsVisible");
}
else if (viewModelProperty == L"Foreground")
{
_NotifyChanges(L"ForegroundPreview");
}
else if (viewModelProperty == L"Background")
{
_NotifyChanges(L"BackgroundPreview");
}
else if (viewModelProperty == L"SelectionBackground")
{
_NotifyChanges(L"SelectionBackgroundPreview");
}
else if (viewModelProperty == L"CursorColor")
{
_NotifyChanges(L"CursorColorPreview");
}
else if (viewModelProperty == L"DarkColorSchemeName" || viewModelProperty == L"LightColorSchemeName")
{
_NotifyChanges(L"CurrentColorScheme");
}
});

// Cache the original BG image path. If the user clicks "Use desktop
Expand Down Expand Up @@ -893,7 +913,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
_NotifyChanges(L"CurrentColorScheme");
}

Editor::ColorSchemeViewModel AppearanceViewModel::CurrentColorScheme()
Editor::ColorSchemeViewModel AppearanceViewModel::CurrentColorScheme() const
{
const auto schemeName{ DarkColorSchemeName() };
const auto allSchemes{ SchemesList() };
Expand All @@ -915,6 +935,41 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
LightColorSchemeName(val.Name());
}

#define GET_COLOR_PREVIEW(appearanceVal, deducedVal) \
Copy link
Member

Choose a reason for hiding this comment

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

FWIW, this macro could just be a function! you can take all the arguments by & of course to ensure they don't get copied. It probably will get inlined into each function too. Benefits include proper type checking and syntax highlighting

if (const auto& modelVal = appearanceVal) \
{ \
/* user defined an override value */ \
return Windows::UI::Color{ \
.A = 255, \
.R = modelVal.Value().R, \
.G = modelVal.Value().G, \
.B = modelVal.Value().B \
}; \
} \
/* set to null --> deduce value from color scheme */ \
return deducedVal;

Windows::UI::Color AppearanceViewModel::ForegroundPreview() const
{
GET_COLOR_PREVIEW(_appearance.Foreground(), CurrentColorScheme().ForegroundColor().Color());
}

Windows::UI::Color AppearanceViewModel::BackgroundPreview() const
{
GET_COLOR_PREVIEW(_appearance.Background(), CurrentColorScheme().BackgroundColor().Color());
}

Windows::UI::Color AppearanceViewModel::SelectionBackgroundPreview() const
{
GET_COLOR_PREVIEW(_appearance.SelectionBackground(), CurrentColorScheme().SelectionBackgroundColor().Color());
}

Windows::UI::Color AppearanceViewModel::CursorColorPreview() const
{
GET_COLOR_PREVIEW(_appearance.CursorColor(), CurrentColorScheme().CursorColor().Color());
}
#undef GET_COLOR_PREVIEW

DependencyProperty Appearances::_AppearanceProperty{ nullptr };

Appearances::Appearances()
Expand Down
11 changes: 10 additions & 1 deletion src/cascadia/TerminalSettingsEditor/Appearances.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,14 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
void SetBackgroundImagePath(winrt::hstring path);

void ClearColorScheme();
Editor::ColorSchemeViewModel CurrentColorScheme();
Editor::ColorSchemeViewModel CurrentColorScheme() const;
void CurrentColorScheme(const Editor::ColorSchemeViewModel& val);

Windows::UI::Color ForegroundPreview() const;
Windows::UI::Color BackgroundPreview() const;
Windows::UI::Color SelectionBackgroundPreview() const;
Windows::UI::Color CursorColorPreview() const;

WINRT_PROPERTY(bool, IsDefault, false);

// These settings are not defined in AppearanceConfig, so we grab them
Expand All @@ -147,6 +152,10 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
OBSERVABLE_PROJECTED_SETTING(_appearance, BackgroundImageAlignment);
OBSERVABLE_PROJECTED_SETTING(_appearance, IntenseTextStyle);
OBSERVABLE_PROJECTED_SETTING(_appearance, AdjustIndistinguishableColors);
OBSERVABLE_PROJECTED_SETTING(_appearance, Foreground);
OBSERVABLE_PROJECTED_SETTING(_appearance, Background);
OBSERVABLE_PROJECTED_SETTING(_appearance, SelectionBackground);
OBSERVABLE_PROJECTED_SETTING(_appearance, CursorColor);
WINRT_OBSERVABLE_PROPERTY(Windows::Foundation::Collections::IObservableVector<Editor::ColorSchemeViewModel>, SchemesList, _propertyChangedHandlers, nullptr);

private:
Expand Down
10 changes: 10 additions & 0 deletions src/cascadia/TerminalSettingsEditor/Appearances.idl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ namespace Microsoft.Terminal.Settings.Editor
ColorSchemeViewModel CurrentColorScheme;
IObservableVector<ColorSchemeViewModel> SchemesList;

Windows.UI.Color ForegroundPreview { get; };
Windows.UI.Color BackgroundPreview { get; };
Windows.UI.Color SelectionBackgroundPreview { get; };
Windows.UI.Color CursorColorPreview { get; };

String MissingFontFaces { get; };
String ProportionalFontFaces { get; };
Boolean HasPowerlineCharacters { get; };
Expand Down Expand Up @@ -77,6 +82,11 @@ namespace Microsoft.Terminal.Settings.Editor
OBSERVABLE_PROJECTED_APPEARANCE_SETTING(Microsoft.Terminal.Settings.Model.ConvergedAlignment, BackgroundImageAlignment);
OBSERVABLE_PROJECTED_APPEARANCE_SETTING(Microsoft.Terminal.Settings.Model.IntenseStyle, IntenseTextStyle);
OBSERVABLE_PROJECTED_APPEARANCE_SETTING(Microsoft.Terminal.Core.AdjustTextMode, AdjustIndistinguishableColors);

OBSERVABLE_PROJECTED_APPEARANCE_SETTING(Windows.Foundation.IReference<Microsoft.Terminal.Core.Color>, Foreground);
OBSERVABLE_PROJECTED_APPEARANCE_SETTING(Windows.Foundation.IReference<Microsoft.Terminal.Core.Color>, Background);
OBSERVABLE_PROJECTED_APPEARANCE_SETTING(Windows.Foundation.IReference<Microsoft.Terminal.Core.Color>, SelectionBackground);
OBSERVABLE_PROJECTED_APPEARANCE_SETTING(Windows.Foundation.IReference<Microsoft.Terminal.Core.Color>, CursorColor);
}

[default_interface] runtimeclass Appearances : Windows.UI.Xaml.Controls.UserControl, Windows.UI.Xaml.Data.INotifyPropertyChanged
Expand Down
Loading
Loading