Skip to content

Commit

Permalink
Update SUI Color Scheme colors' AutoProp.Name and ToolTip (#16544)
Browse files Browse the repository at this point in the history
In the Settings UI's Color Scheme page (where you edit the color scheme itself), update the color chip buttons to include the RGB value in the tooltip and screen reader announcements.

Closes #15985
Closes #15983

## Validation Steps Performed
Tooltip and screen reader announcement is updated on launch and when a new value is selected.
  • Loading branch information
carlos-zamora committed Jan 10, 2024
1 parent fb8b120 commit 057183b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.cpp
Expand Up @@ -178,12 +178,26 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
Name(TableColorNames[index]);
Tag(winrt::box_value<uint8_t>(index));
Color(color);

PropertyChanged({ get_weak(), &ColorTableEntry::_PropertyChangedHandler });
}

ColorTableEntry::ColorTableEntry(std::wstring_view tag, Windows::UI::Color color)
{
Name(LocalizedNameForEnumName(L"ColorScheme_", tag, L"Text"));
Tag(winrt::box_value(tag));
Color(color);

PropertyChanged({ get_weak(), &ColorTableEntry::_PropertyChangedHandler });

This comment has been minimized.

Copy link
@DHowett

DHowett Jan 10, 2024

Member

@carlos-zamora FYI in cases like this... when an object subscribes to its own events, you don't need to use a weak pointer. You can just use this. The object will not be firing its own events after it's destroyed, and so it will never run its event handler after it got destroyed. You don't need to guard against impossible conditions 😄

}

void ColorTableEntry::_PropertyChangedHandler(const IInspectable& /*sender*/, const PropertyChangedEventArgs& args)
{
const auto propertyName{ args.PropertyName() };
if (propertyName == L"Color" || propertyName == L"Name")
{
_PropertyChangedHandlers(*this, PropertyChangedEventArgs{ L"AccessibleName" });
}
}

}
7 changes: 7 additions & 0 deletions src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.h
Expand Up @@ -63,12 +63,19 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
ColorTableEntry(uint8_t index, Windows::UI::Color color);
ColorTableEntry(std::wstring_view tag, Windows::UI::Color color);

hstring AccessibleName() const
{
return hstring{ fmt::format(FMT_COMPILE(L"{} RGB({}, {}, {})"), _Name, _Color.R, _Color.G, _Color.B) };
}

WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler);
WINRT_OBSERVABLE_PROPERTY(Windows::UI::Color, Color, _PropertyChangedHandlers);
WINRT_OBSERVABLE_PROPERTY(winrt::hstring, Name, _PropertyChangedHandlers);
WINRT_OBSERVABLE_PROPERTY(IInspectable, Tag, _PropertyChangedHandlers);

private:
Windows::UI::Color _color;

void _PropertyChangedHandler(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::Data::PropertyChangedEventArgs& args);
};
};
Expand Up @@ -34,5 +34,6 @@ namespace Microsoft.Terminal.Settings.Editor
String Name { get; };
IInspectable Tag;
Windows.UI.Color Color;
String AccessibleName { get; };
}
}
4 changes: 2 additions & 2 deletions src/cascadia/TerminalSettingsEditor/EditColorScheme.xaml
Expand Up @@ -55,10 +55,10 @@

<DataTemplate x:Key="ColorTableEntryTemplate"
x:DataType="local:ColorTableEntry">
<Button AutomationProperties.Name="{x:Bind Name}"
<Button AutomationProperties.Name="{x:Bind AccessibleName, Mode=OneWay}"
Background="{x:Bind local:Converters.ColorToBrush(Color), Mode=OneWay}"
Style="{StaticResource ColorSchemesColorButtonStyle}"
ToolTipService.ToolTip="{x:Bind Name}">
ToolTipService.ToolTip="{x:Bind AccessibleName, Mode=OneWay}">
<Button.Flyout>
<Flyout>
<muxc:ColorPicker ColorChanged="ColorPickerChanged"
Expand Down

0 comments on commit 057183b

Please sign in to comment.