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

Conversation

carlos-zamora
Copy link
Member

Summary of the Pull Request

Adds some pre-existing settings ($profile.foreground, $profile.background, $profile.selectionBackground, $profile.cursorColor) to the settings UI. This was accomplished by introducing a new control: NullableColorPicker. This control allows the user to pick a color from the color scheme, set the color to null, and select a color from an advanced color picker.

References and Relevant Issues

#10000

Detailed Description of the Pull Request / Additional comments

  • NullableColorPicker control
    • includes a built-in NullColorButton to set the current value to null
    • includes a "More colors..." button to display an advanced color picker
    • uses data templates on data templates (data templates squared?) to convert the current color scheme into a grid of color chips
    • color chips display a checkmark (similar to Windows settings personalization). This automatically updates its color to stay compliant with color contrast.
    • color chips are added to a list so we can (un)check them when a new color is selected
  • SettingsContainer changes
    • Forked ExpanderSettingContainerStyle to allow for a custom preview template. This way, we can display the current value in the expander and we're not just limited to text.
    • changed type of CurrentValue property from String to IInspectable
    • added CurrentValueTemplate property to control how to display the current value
  • Miscellaneous:
    • Added a few converters (BooleanToVisibility, ColorToString, ColorToBrush)
    • Added NameWithHexCode to ColorTableEntry to expose a color as Red #RRGGBB (used for tooltips and a11y)
    • Added ForegroundPreview (and equivalent for other colors) to AppearanceViewModel to deduce the color that will be used

Validation Steps Performed

  • a11y pass (NVDA, keyboard)
  • set the color to one of the color chips
  • set the color to null
  • set the color to a value from the integrated color picker
  • control updates properly when a new color scheme is selected
  • control updates properly when a color scheme has multiple colors of the same value

Follow-ups

  • [A11y] Screen readers don't read expander's preview text
  • Add Tab Color to settings UI
  • Update CursorColor preview to display #FFFFFF as "invert"
  • [Focus issue] Clicking on the appearance page yeets focus to FontFace control

@carlos-zamora
Copy link
Member Author

Demo

collapsed view

expanded view with tooltip

null color selected

advanced color picker

@carlos-zamora carlos-zamora mentioned this pull request Sep 18, 2024
65 tasks
Windows::Foundation::IInspectable ColorToBrushConverter::Convert(Windows::Foundation::IInspectable const& value, Windows::UI::Xaml::Interop::TypeName const& /*targetType*/, Windows::Foundation::IInspectable const& /*parameter*/, hstring const& /*language*/)
{
const auto color = value.as<Windows::UI::Color>();
return Microsoft::Terminal::UI::Converters::ColorToBrush(color);
Copy link
Member

Choose a reason for hiding this comment

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

fwiw if we're adding a static global converter function, we don't need a converter object!

Copy link
Member Author

Choose a reason for hiding this comment

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

Omg, yeah, I hate it. I'd rather directly use mtu:Converters.ColorToBrush(<param>) in the XML, but the problem is here:

<!--  CommonResources.xaml::ColorPreviewTemplate  -->
Fill="{Binding Converter={StaticResource ColorToBrushConverter}}"

We don't have a Path set because we want to convert the object itself. Since there isn't a path, there isn't a way to target the object itself (from what I know, at least). Fill="{Binding mtu:Converters.ColorToBrush}" silently fails (no rendered Rectangle)!

Also, if you're curious, we can't use x:Bind because XamlCompiler error WMC1119: This Xaml file must have a code-behind class to use {x:Bind}. See http://go.microsoft.com/fwlink/?LinkID=532920&clcid=0x409 for more information.

Also also, in case you're extra curious, I wasn't able to figure out how to define the DataType as IReference<Core::Color> because of the IReference part.

So that's why this part's implemented like this 🫤

Copy link
Member

Choose a reason for hiding this comment

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

UGH. Thanks.

@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Oct 3, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Oct 4, 2024
@@ -18,6 +18,11 @@ namespace winrt::Microsoft::Terminal::UI::implementation
return value ? winrt::Windows::UI::Xaml::Visibility::Collapsed : winrt::Windows::UI::Xaml::Visibility::Visible;
}

winrt::Windows::UI::Xaml::Visibility Converters::BooleanToVisibility(bool value)
Copy link
Member

Choose a reason for hiding this comment

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

It doesn't seem like anyone is using these now - can we just back out the UIHelpers changes?

Copy link
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

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

18/26

@@ -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

@@ -396,6 +264,188 @@
</local:SettingContainer>
</StackPanel>

<!-- Grouping: Color -->
Copy link
Member

Choose a reason for hiding this comment

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

I'm minorly concerned concern about moving the whole color scheme part down to where Cursor is. I suspect that the thing people doing personalization want most is their color scheme.

<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<ContentDialog x:Name="ColorPickerDialog"
Copy link
Member

Choose a reason for hiding this comment

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

content dialogs can be spicy - test this on Win10!

Copy link
Member

Choose a reason for hiding this comment

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

specifically content dialogs inside grids even

Opened="ColorPickerDialog_Opened"
PrimaryButtonClick="ColorPickerDialog_PrimaryButtonClick">
<muxc:ColorPicker x:Name="ColorPickerControl"
Margin="0,0,0,-40"
Copy link
Member

Choose a reason for hiding this comment

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

(why -40?)


<ContentPresenter Grid.Column="0"
Content="{x:Bind ColorSchemeVM, Mode=OneWay}"
ContentTemplate="{StaticResource ColorSchemeTemplate}" />
Copy link
Member

Choose a reason for hiding this comment

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

📝 ColorSchemeTemplate?

@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Oct 11, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants