mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-08 11:03:25 -08:00
[Icons] Author icon emphasis colors as palette roles (#7789)
Some checks are pending
CodeQL / Analyze (cpp) (push) Waiting to run
CodeQL / Analyze (actions) (push) Waiting to run
Build Desktop / Configure (push) Waiting to run
Build Desktop / vcpkg baseline (push) Waiting to run
Build Desktop / Debian 13 (push) Blocked by required conditions
Build Desktop / Fedora 45 release (push) Blocked by required conditions
Build Desktop / Fedora 45 debug (push) Blocked by required conditions
Build Desktop / Servatrice_Debian 12 (push) Blocked by required conditions
Build Desktop / Ubuntu 26.04 (push) Blocked by required conditions
Build Desktop / Arch (push) Blocked by required conditions
Build Desktop / Debian 12 (push) Blocked by required conditions
Build Desktop / Fedora 44 (push) Blocked by required conditions
Build Desktop / Ubuntu 24.04 (push) Blocked by required conditions
Build Desktop / Ubuntu 26.04 sanitize (push) Blocked by required conditions
Build Desktop / Ubuntu 26.04 cover (push) Blocked by required conditions
Build Desktop / macOS 14 (push) Blocked by required conditions
Build Desktop / macOS 15 (push) Blocked by required conditions
Build Desktop / macOS 27 Debug (push) Blocked by required conditions
Build Desktop / Windows 10 (push) Blocked by required conditions
Build Desktop / macOS 13 Intel (push) Blocked by required conditions
Build Desktop / Prune caches (push) Waiting to run
Build Docker / Servatrice (arm) (push) Waiting to run
Build Docker / Servatrice (x86) (push) Waiting to run
Build Docker / Publish multi-platform Servatrice image (push) Blocked by required conditions
Some checks are pending
CodeQL / Analyze (cpp) (push) Waiting to run
CodeQL / Analyze (actions) (push) Waiting to run
Build Desktop / Configure (push) Waiting to run
Build Desktop / vcpkg baseline (push) Waiting to run
Build Desktop / Debian 13 (push) Blocked by required conditions
Build Desktop / Fedora 45 release (push) Blocked by required conditions
Build Desktop / Fedora 45 debug (push) Blocked by required conditions
Build Desktop / Servatrice_Debian 12 (push) Blocked by required conditions
Build Desktop / Ubuntu 26.04 (push) Blocked by required conditions
Build Desktop / Arch (push) Blocked by required conditions
Build Desktop / Debian 12 (push) Blocked by required conditions
Build Desktop / Fedora 44 (push) Blocked by required conditions
Build Desktop / Ubuntu 24.04 (push) Blocked by required conditions
Build Desktop / Ubuntu 26.04 sanitize (push) Blocked by required conditions
Build Desktop / Ubuntu 26.04 cover (push) Blocked by required conditions
Build Desktop / macOS 14 (push) Blocked by required conditions
Build Desktop / macOS 15 (push) Blocked by required conditions
Build Desktop / macOS 27 Debug (push) Blocked by required conditions
Build Desktop / Windows 10 (push) Blocked by required conditions
Build Desktop / macOS 13 Intel (push) Blocked by required conditions
Build Desktop / Prune caches (push) Waiting to run
Build Docker / Servatrice (arm) (push) Waiting to run
Build Docker / Servatrice (x86) (push) Waiting to run
Build Docker / Publish multi-platform Servatrice image (push) Blocked by required conditions
* [Icons] Author icon emphasis colors as palette roles The emphasis levels were computed from the accent at paint time, so a theme could not vary them: every theme got the same derived strong and soft tones, and a semantic hue was pushed toward the accent whether the author wanted that or not. Give each family three authored roles instead. Icon/IconStrong/IconSoft carry the neutral glyph ink and Positive/Negative gain the same Strong and Soft companions. Emphasis becomes a lookup inside the family, and a caller that names a variant pins that level at every emphasis. The paint path returns the authored color verbatim; only the filled treatments keep their saturation floor, because carrying a disc or a fill is a treatment decision. Shipped palettes author the full ladder for both schemes; the palette editor exposes the new rows and the generator writes them. System keeps deriving its neutral ink from the platform palette, since it ships no palette of its own. * [Icons] Keep the authored emphasis in filled treatments The saturation floor was added while the emphasis levels were still computed: it rescued the pale dark-scheme tones once a whole shape carried them. With the levels authored, the floor overrides the author instead: a quiet level jumped to the secondary saturation as soon as a sticker or a badge painted it, so the ladder only existed for line glyphs. The authored tone is now the top of the fill gradient and the treatment only darkens the bottom for depth, so every treatment renders exactly the level the palette stores. The badge glyph ink no longer guesses the scheme from the tone's value: an authored quiet level is a dark color on the dark scheme too, so the scheme is passed in from the surface palette. The preview sheet renders every shipped palette theme, three glyphs per family, and each row prints the authored tone and the darker bottom. * [Icons] Order the emphasis ladder by chroma, not contrast Contrast cannot order the ladder. On a dark surface the highest-contrast tone is the palest one, so a 7:1 primary came out near-white while the secondary kept the family's color; the ladder read inverted, and for the shipped semantic greens and reds the primary level was already satisfied by the secondary, so the two levels resolved to the same hex. Emphasis is chromatic intensity now. Quiet recedes toward the surface at the 3:1 non-text floor, secondary keeps the family color at the 4.5:1 text floor, and primary is the most chromatic tone the same floor allows. Every level stays legible on the window and the button surface, and the primary is a strictly more saturated member of its family on both schemes. The reformatted palettes move the two upper levels onto the shared floor and leave the quiet level alone. * [Icons] Make the emphasis ladder structural on every theme The chroma ladder landed with four P1s from review: reachContrast picked its pole by background lightness instead of by what each pole can reach, the generated neutral ink was solved on the window surface only, Fusion's neutral family was still the green accent, and quiet sat below the text floor while disabled reused the palette gray. Pick the pole by achievable contrast, solve fallback and preview inks on the harder of the window and button surfaces, re-author Fusion's neutral trio in slate blue, and keep quiet on the shared text floor by muting its saturation to 45% instead of blending it into the surface. Disabled is now derived from the quiet ink, so it is structurally dimmer than every enabled level on every theme. Re-author all soft roles at a 4.60 target with a rounding margin, rebuild the per-theme preview generator the rebase dropped, and add a Disabled row to every treatment sheet. * [Icons] Render preview glyphs at the sheet's device pixel ratio The preview sheets paint on a 2x painter but rasterized each glyph at its logical size, so every icon was upscaled on the way into the file and the sheets read as blurry. Render each glyph at device size and tag the pixmap with the ratio, so one source pixel lands on one file pixel. * [Icons] Keep the System semantic ladder on the text floor System authors no palette of its own, so its semantic family is fixed data measured against whatever surfaces the platform provides. The ladder that landed with the authored roles reused the old contrast-ordered values: PositiveSoft and NegativeSoft sat at 2.76–3.90:1 on common light and dark platform surfaces, and the strong level was less saturated than the secondary, which is the inversion the chroma rule removes. Re-author the six default semantic colors per scheme at the same 4.60 target the shipped themes use, against representative platform surfaces, and mirror them in System's palette files. The new DefaultSemanticFamilyMeetsTheLadderOnPlatformSurfaces test holds the floor and the saturation order there, and shippedPalette's early return now says why System is outside the authored-palette assertions. * [Icons] Apply the CI clang-format output to the new tests * [Icons] Adapt the treatment preview to the authored roles The preview file is inherited from the treatment PR. Here the palette already authors the fill tone and the badge takes an explicit scheme, so the generator stops re-saturating the role and passes the scheme the sheet renders. * [Icons] Author neutral System icon ink The System theme derived icon ink from the platform palette, which rendered blue under the default palette. Author Icon/IconStrong/IconSoft explicitly: a black ladder in light mode, a white ladder in dark mode. Pin authorship, achromaticity and ordering in the render test. * Address review findings
This commit is contained in:
parent
3e2884e6e1
commit
c7e8422808
29 changed files with 1448 additions and 417 deletions
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
#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"
|
||||
|
|
@ -31,6 +30,74 @@
|
|||
|
||||
namespace
|
||||
{
|
||||
/**
|
||||
* @brief The role an emphasis level selects inside a base role's family.
|
||||
*
|
||||
* The theme authors all three levels, so emphasis is a lookup instead of a
|
||||
* color computation. Naming a variant (`IconStrong`, `PositiveSoft`) is an
|
||||
* explicit request and keeps that role at every emphasis; only the base roles
|
||||
* take part in the mapping. Accent roles have no neutral middle member, so they
|
||||
* are always used as named.
|
||||
*/
|
||||
AppColor::Role emphasisRole(AppColor::Role role, IconEmphasis emphasis)
|
||||
{
|
||||
switch (role) {
|
||||
case AppColor::Icon:
|
||||
return emphasis == IconEmphasis::Primary ? AppColor::IconStrong
|
||||
: emphasis == IconEmphasis::Quiet ? AppColor::IconSoft
|
||||
: AppColor::Icon;
|
||||
case AppColor::Positive:
|
||||
return emphasis == IconEmphasis::Primary ? AppColor::PositiveStrong
|
||||
: emphasis == IconEmphasis::Quiet ? AppColor::PositiveSoft
|
||||
: AppColor::Positive;
|
||||
case AppColor::Negative:
|
||||
return emphasis == IconEmphasis::Primary ? AppColor::NegativeStrong
|
||||
: emphasis == IconEmphasis::Quiet ? AppColor::NegativeSoft
|
||||
: AppColor::Negative;
|
||||
default:
|
||||
return role;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The scheme the active application palette is painting for.
|
||||
*
|
||||
* The fill needs the surface scheme to choose the badge glyph ink, and it cannot
|
||||
* read it from the tone: an authored quiet level is a dark color on the dark
|
||||
* scheme too. The theme's resolved scheme is the same source the palette file
|
||||
* and the default app colors are chosen from, so the fill follows it instead of
|
||||
* re-deriving the scheme from the live Window lightness, which can disagree
|
||||
* when a theme pins a scheme the platform palette does not match.
|
||||
*/
|
||||
ThemeIconFill::Scheme activeScheme()
|
||||
{
|
||||
if (themeManager != nullptr) {
|
||||
return themeManager->isDarkModeActive() ? ThemeIconFill::Scheme::Dark : ThemeIconFill::Scheme::Light;
|
||||
}
|
||||
|
||||
// No manager (test binaries link the icon engine without the app): fall
|
||||
// back to the live palette, which is the only scheme signal left.
|
||||
const QPalette &palette = qApp->palette();
|
||||
return palette.color(QPalette::Active, QPalette::Window).lightness() < 128 ? ThemeIconFill::Scheme::Dark
|
||||
: ThemeIconFill::Scheme::Light;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief The ink a disabled glyph is painted with.
|
||||
*
|
||||
* A disabled icon used to be the palette's disabled text, a fixed gray whose
|
||||
* contrast swings with the surface: on the darkest themes it out-reads the quiet
|
||||
* level, so an enabled quiet glyph looks more disabled than a disabled one.
|
||||
* Deriving it from the theme's own quiet ink keeps the order structural.
|
||||
*/
|
||||
QColor disabledGlyphInk(const QPalette &palette)
|
||||
{
|
||||
const QColor quiet = themeManager->appColor(AppColor::IconSoft);
|
||||
const QColor surface = ThemeIconInk::harderSurface(palette.color(QPalette::Active, QPalette::Window),
|
||||
palette.color(QPalette::Active, QPalette::Button), quiet);
|
||||
return ThemeIconInk::disabledInk(quiet, surface);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reads an SVG through the `theme:` search path.
|
||||
*/
|
||||
|
|
@ -265,7 +332,7 @@ private:
|
|||
QByteArray variant;
|
||||
if (badge) {
|
||||
variant = QByteArrayLiteral("B|") + tone.name(QColor::HexRgb).toLatin1() + '|' +
|
||||
ThemeIconBadge::glyphColor(tone).name(QColor::HexRgb).toLatin1();
|
||||
ThemeIconBadge::glyphColor(tone, activeScheme()).name(QColor::HexRgb).toLatin1();
|
||||
} else if (sticker) {
|
||||
variant = QByteArrayLiteral("S|") + tone.name(QColor::HexRgb).toLatin1();
|
||||
} else if (resolvedHasSentinel) {
|
||||
|
|
@ -283,7 +350,7 @@ private:
|
|||
if (badge) {
|
||||
// Geometry is computed from the device-pixel size, and the ratio is
|
||||
// attached below like every other path.
|
||||
pixmap = ThemeIconBadge::renderBadge(resolvedSvg, tone, pixelSize);
|
||||
pixmap = ThemeIconBadge::renderBadge(resolvedSvg, tone, pixelSize, activeScheme());
|
||||
} else if (sticker) {
|
||||
pixmap = ThemeIconSticker::renderSticker(resolvedSvg, tone, pixelSize);
|
||||
} else if (resolvedHasSentinel) {
|
||||
|
|
@ -318,6 +385,7 @@ private:
|
|||
mutable bool hasResolvedAsset = false;
|
||||
mutable bool hasIntrinsicSize = false;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
IconTint::IconTint(QPalette::ColorRole role, IconEmphasis _emphasis) : paletteRole(role), emphasis(_emphasis)
|
||||
|
|
@ -342,21 +410,18 @@ IconTint IconTint::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 palette.color(QPalette::Disabled, QPalette::WindowText);
|
||||
return disabledGlyphInk(palette);
|
||||
}
|
||||
// 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. 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);
|
||||
// The theme authors one color per emphasis level, so the paint path
|
||||
// uses the resolved role verbatim. The filled treatments only shape the
|
||||
// tone's value to give a disc or a fill depth; hue and saturation stay
|
||||
// the author's.
|
||||
const QColor color = themeManager->appColor(emphasisRole(appRole, emphasis));
|
||||
if (mode != QIcon::Selected) {
|
||||
return color;
|
||||
}
|
||||
|
|
@ -372,17 +437,14 @@ QColor IconTint::resolve(QIcon::Mode mode) const
|
|||
const QPalette::ColorGroup group = mode == QIcon::Disabled ? QPalette::Disabled : QPalette::Active;
|
||||
const QPalette::ColorRole effective =
|
||||
mode == QIcon::Selected && paletteRole == QPalette::WindowText ? QPalette::HighlightedText : paletteRole;
|
||||
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);
|
||||
// A neutral label role resolves to the theme's authored icon ink. A disabled
|
||||
// one uses the dimmed quiet ink so it always sits below the quiet level;
|
||||
// semantic roles keep the color the palette gave them.
|
||||
if (effective == QPalette::WindowText || effective == QPalette::Text) {
|
||||
return group == QPalette::Disabled ? disabledGlyphInk(palette)
|
||||
: themeManager->appColor(emphasisRole(AppColor::Icon, emphasis));
|
||||
}
|
||||
return color;
|
||||
return palette.color(group, effective);
|
||||
}
|
||||
|
||||
QIcon loadThemedIcon(QStringView prefix, IconTint tint, IconStyle style)
|
||||
|
|
@ -407,7 +469,7 @@ QPixmap loadSentinelSvgPixmap(const QString &resolvedPath, IconTint tint, const
|
|||
if (canvas.isEmpty()) {
|
||||
canvas = QSvgRenderer(svg).defaultSize();
|
||||
}
|
||||
return style == IconStyle::Badge ? ThemeIconBadge::renderBadge(svg, tone, canvas)
|
||||
return style == IconStyle::Badge ? ThemeIconBadge::renderBadge(svg, tone, canvas, activeScheme())
|
||||
: ThemeIconSticker::renderSticker(svg, tone, canvas);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue