[Icons] Paint neutral glyphs with icon ink and add an emphasis axis (#7788)

* [Icons] Paint neutral glyphs with icon ink instead of body-text ink

Neutral icons resolved `currentColor` straight to `QPalette::WindowText`. A
glyph is not a word: it is a 16-24px mark drawn with a 2-unit stroke, so
antialiasing thins it until it reads lighter than the text beside it, in the
one color the palette reserves for reading. The result is that icons recede
into the chrome exactly where they should anchor it.

Add `theme_icon_ink`, one rule with one job: mix a share of the theme accent
into the neutral text color, then hold the result to a contrast floor. The
accent share gives the glyph chroma the text does not have, so it reads as an
icon rather than as leftover text, and it is derived from `QPalette::Highlight`
rather than a new token. The floor keeps a theme with a weak text color from
producing an illegible glyph.

Only the neutral label roles (`WindowText`, `Text`) are inked. Semantic tints
are hues the call site chose on purpose, disabled uses the disabled group, and
the selected-row swap to `HighlightedText` is unchanged.

The WCAG contrast math moves from `theme_icon_badge` to the new unit, so badge
ink decisions and the floor share one implementation.

Tests: the ink rule against every shipped palette, the weak-text floor, and the
palette-following render tests now ask the rule instead of restating its
output. A preview sheet sweeps the accent share at 0-35% over window and button
surfaces for both schemes.

* [Icons] Add an emphasis axis for icon ink

Tint says which hue, style says how much shape, and nothing said how loud.
Call sites that have a hierarchy (a card hover panel's nav strip, the visual
database filter toolbar) could only pick between "the theme color" and
"another theme color", so "this is the important one" had no way to be
expressed and every glyph in a surface arrived with the same weight.

Add `IconEmphasis` as the third axis: Quiet, Secondary, Primary. It travels
inside `IconTint` instead of becoming a fourth `loadThemedIcon` parameter, so
every existing call site keeps working and its look, and emphasis reads as
part of the same "how should this glyph be inked" decision as the tint.

- Primary lifts a neutral glyph to `QPalette::Highlight`, so the surface's own
  action color names the primary action instead of a second gray token, and
  pushes both neutral and tinted glyphs to a 7:1 floor.
- Quiet blends toward the surface and stops at the 3:1 WCAG non-text floor,
  for glyphs that label a control rather than act (the magnifier in a search
  field, a section marker).
- Secondary is the previous color verbatim.

The default ink borrows enough accent to sit off the palette's pole (5.4:1 on
light, 6.4:1 on dark), so the 7:1 primary floor is measurably above it in both
schemes instead of being lost against a near-black or near-white default. The
tests pin that order where it exists, and the hue shift still separates the
levels at a glance.

Disabled glyphs and the Selected -> HighlightedText swap are unchanged at
every emphasis level.

* [Icons] Render the emphasis sheet for every shipped theme

The preview only rendered one theme, so a reviewer could not see that the
emphasis levels behave the same way across Fabric, Fusion, Leather,
Plasma and VelvetMarble. It now writes one sheet per theme and scheme:
the neutral, positive and negative families at all three levels, three
glyphs per family, as line, sticker and badge at 16 and 24 px, on the
window and button surfaces.

* Address review findings
This commit is contained in:
BruebachL 2026-11-08 19:09:01 +01:00 • committed by GitHub
parent e81ee02c24
commit 3e2884e6e1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 888 additions and 44 deletions

View file

@ -3,6 +3,7 @@
#include "libcockatrice/utility/svg_recolor.h"
#include "theme_icon_badge.h"
#include "theme_icon_fill.h"
#include "theme_icon_ink.h"
#include "theme_icon_sticker.h"
#include "theme_manager.h"
@ -319,26 +320,43 @@ private:
};
} // namespace
IconTint::IconTint(QPalette::ColorRole role) : paletteRole(role)
IconTint::IconTint(QPalette::ColorRole role, IconEmphasis _emphasis) : paletteRole(role), emphasis(_emphasis)
{
}
IconTint::IconTint(AppColor::Role role) : source(Source::AppColor), appRole(role)
IconTint::IconTint(AppColor::Role role, IconEmphasis _emphasis)
: source(Source::AppColor), appRole(role), emphasis(_emphasis)
{
}
IconTint IconTint::primary()
{
return IconTint(QPalette::WindowText, IconEmphasis::Primary);
}
IconTint IconTint::quiet()
{
return IconTint(QPalette::WindowText, IconEmphasis::Quiet);
}
QColor IconTint::resolve(QIcon::Mode mode) const
{
const QPalette &palette = qApp->palette();
const QColor surface = palette.color(QPalette::Active, QPalette::Window);
const QColor accent = palette.color(QPalette::Active, QPalette::Highlight);
if (source == Source::AppColor) {
// A disabled control must not keep signalling its semantic color.
if (mode == QIcon::Disabled) {
return qApp->palette().color(QPalette::Disabled, QPalette::WindowText);
return palette.color(QPalette::Disabled, QPalette::WindowText);
}
// The three treatments paint the same tone: a line glyph, a badge disc
// and a sticker fill must not disagree on how saturated the role is.
// The fill treatments apply this floor themselves, so this only changes
// the line path, and only for the desaturated dark-scheme tones.
const QColor color = ThemeIconFill::saturated(themeManager->appColor(appRole));
// the line path, and only for the desaturated dark-scheme tones. The
// emphasis then decides how loud that tone is, without changing its hue.
const QColor color =
ThemeIconInk::forEmphasis(ThemeIconFill::saturated(themeManager->appColor(appRole)), surface, emphasis);
if (mode != QIcon::Selected) {
return color;
}
@ -346,16 +364,25 @@ QColor IconTint::resolve(QIcon::Mode mode) const
// semantic tint when it stays legible there; otherwise the glyph would
// vanish into the selection.
constexpr double MIN_SELECTED_CONTRAST = 3.0;
const QColor highlight = qApp->palette().color(QPalette::Active, QPalette::Highlight);
return ThemeIconBadge::contrastRatio(color, highlight) >= MIN_SELECTED_CONTRAST
return ThemeIconInk::contrastRatio(color, accent) >= MIN_SELECTED_CONTRAST
? color
: qApp->palette().color(QPalette::Active, QPalette::HighlightedText);
: palette.color(QPalette::Active, QPalette::HighlightedText);
}
const QPalette::ColorGroup group = mode == QIcon::Disabled ? QPalette::Disabled : QPalette::Active;
const QPalette::ColorRole effective =
mode == QIcon::Selected && paletteRole == QPalette::WindowText ? QPalette::HighlightedText : paletteRole;
return qApp->palette().color(group, effective);
const QColor color = palette.color(group, effective);
// A neutral label role is inked as an icon, not as body text: it borrows a
// little accent chroma and is held to a contrast floor. Semantic roles and
// the selected-row swap keep the color the palette gave them.
if (group == QPalette::Active && (effective == QPalette::WindowText || effective == QPalette::Text)) {
// The primary action of a surface takes the accent itself; the other
// levels stay neutral. Emphasis then sets the contrast the glyph pays.
const QColor base = emphasis == IconEmphasis::Primary ? accent : ThemeIconInk::glyphInk(color, surface, accent);
return ThemeIconInk::forEmphasis(base, surface, emphasis);
}
return color;
}
QIcon loadThemedIcon(QStringView prefix, IconTint tint, IconStyle style)