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 and improve Profile.Icon in settings UI #17870

Open
wants to merge 18 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
1 change: 1 addition & 0 deletions .github/actions/spelling/excludes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
^doc/reference/windows-terminal-logo\.ans$
^oss/
^samples/PixelShaders/Screenshots/
^src/cascadia/TerminalSettingsEditor/SegoeFluentIconList.h$
^src/interactivity/onecore/BgfxEngine\.
^src/renderer/atlas/
^src/renderer/wddmcon/WddmConRenderer\.
Expand Down
62 changes: 61 additions & 1 deletion src/cascadia/TerminalSettingsEditor/Appearances.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,30 @@ 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");
}
else if (viewModelProperty == L"CurrentColorScheme")
{
_NotifyChanges(L"ForegroundPreview", L"BackgroundPreview", L"SelectionBackgroundPreview", L"CursorColorPreview");
}
});

// Cache the original BG image path. If the user clicks "Use desktop
Expand Down Expand Up @@ -928,7 +952,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 @@ -950,6 +974,42 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
LightColorSchemeName(val.Name());
}

static inline Windows::UI::Color _getColorPreview(const IReference<Microsoft::Terminal::Core::Color>& modelVal, Windows::UI::Color deducedVal)
{
if (modelVal)
{
// 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
{
return _getColorPreview(_appearance.Foreground(), CurrentColorScheme().ForegroundColor().Color());
}

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

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

Windows::UI::Color AppearanceViewModel::CursorColorPreview() const
{
return _getColorPreview(_appearance.CursorColor(), CurrentColorScheme().CursorColor().Color());
}

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 @@ -127,9 +127,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 @@ -153,6 +158,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 @@ -78,6 +83,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