Skip to content

fix(theme): ensure text on accent background keeps 4.5:1 contrast (#65) - #70

Merged
your-moon merged 1 commit into
your-moon:mainfrom
montionugera:fix/button-contrast-on-accent-65
Oct 14, 2026
Merged

your-moon merged 1 commit into
your-moon:mainfrom
montionugera:fix/button-contrast-on-accent-65

Conversation

@montionugera

Copy link
Copy Markdown
Contributor

Fixes #65.

Summary

When an accent color is light (e.g., bright yellow wallpapers like Van Gogh's Wheat Field with Cypresses or wallpaper accents pushed toward white on dark surfaces), primary buttons painted with t.accent and hardcoded white text fell below the WCAG 4.5:1 contrast ratio.

Changes

  1. Added on_accent: Hsla to Theme:
    • Added pub on_accent: Hsla to Theme.
    • Introduced pub fn on_accent_for(accent: Hsla) -> Hsla choosing between white (0xffffff) and near-black dark ink (0x0d0d0d, matching tern's shell) based on contrast_ratio against accent (preferring white when it meets 4.5:1, otherwise falling back to near-black).
    • Computed self.on_accent in Theme::tinted and initialized in stock zeron_light() and zeron_dark().
  2. Applied t.on_accent across primary buttons:
    • crates/tern/src/shell_connections.rs:720 (button form submit / save).
    • crates/tern/src/sidebar.rs:209 (empty state "New connection" button).
  3. Unit Tests:
    • Added text_on_accent_keeps_contrast_in_light_and_dark_modes asserting contrast_ratio(on_accent, accent) >= 4.49 across test wallpaper swatches.
    • Added built_in_wallpapers_keep_on_accent_contrast pinning that for every built-in wallpaper (BUILTINS) in both light and dark appearances, contrast_ratio(on_accent, accent) >= 4.49.
    • Verified stock zeron_dark and zeron_light contrast assertions in crates/tern/src/theme.rs.

Verification

  • cargo test -p tern passed (281 tests passed, 0 failed).
  • ./scripts/check-craft.sh passed cleanly.
  • cargo fmt --check passed cleanly.
  • cargo clippy --all-targets -- -D warnings passed with 0 warnings.

@your-moon your-moon left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

nice one, checked it in the running app: dark mode buttons are now dark text on the violet (measured the pixels, both the sidebar and center buttons), light mode stays white. the built-in wallpapers test is the important part, covers the yellow case i hit. going with black text on dark mode since white on #8b7cf6 is only ~3.5:1. thanks!

@your-moon
your-moon merged commit 20c4dc5 into your-moon:main Oct 14, 2026
10 checks passed
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.

connections: Save button text is unreadable when the accent is light (yellow on white)

2 participants