Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
theme_contrast.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <pulp/view/theme.hpp>
4#include <string>
5#include <vector>
6#include <optional>
7
8namespace pulp::view {
9
10// ── WCAG Contrast Utilities ─────────────────────────────────────────────────
11// Implements WCAG 2.1 contrast ratio calculations for accessible theme design.
12
16
20
22enum class ContrastLevel {
23 aa_normal, // 4.5:1 for normal text (< 18pt or < 14pt bold)
24 aa_large, // 3.0:1 for large text (>= 18pt or >= 14pt bold)
25 aaa_normal, // 7.0:1 for AAA normal text
26 aaa_large // 4.5:1 for AAA large text
27};
28
31
33bool meets_contrast(Color foreground, Color background, ContrastLevel level = ContrastLevel::aa_normal);
34
39
43std::optional<Color> adjust_for_contrast(Color foreground, Color background,
45
46// ── HSL Conversion Utilities ────────────────────────────────────────────────
47// Delegates to Color::to_hsl() / Color::from_hsl() — these wrappers exist
48// for backward compatibility with code that uses the free-function API.
49
51
52inline HSL rgb_to_hsl(Color c) { return c.to_hsl(); }
53inline Color hsl_to_rgb(HSL hsl, float alpha = 1.0f) { return Color::from_hsl(hsl, alpha); }
54
56Color shift_hue(Color c, float degrees);
57
60
63
65Color with_alpha(Color c, float alpha);
66
67// ── Theme Contrast Validation ───────────────────────────────────────────────
68
75
79std::vector<ContrastIssue> validate_theme_contrast(const Theme& theme,
81
85
86} // namespace pulp::view
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
bool meets_contrast(Color foreground, Color background, ContrastLevel level=ContrastLevel::aa_normal)
Check if a foreground/background pair meets a given contrast level.
std::vector< ContrastIssue > validate_theme_contrast(const Theme &theme, ContrastLevel level=ContrastLevel::aa_normal)
Validate a theme for contrast issues.
float contrast_ratio(Color a, Color b)
Compute WCAG contrast ratio between two colors.
Color blend_colors(Color a, Color b, float t)
Blend two colors by factor t in [0,1]. t=0 returns a, t=1 returns b.
Theme auto_fix_contrast(const Theme &theme, ContrastLevel level=ContrastLevel::aa_normal)
Auto-fix contrast issues in a theme by adjusting foreground colors.
Color shift_hue(Color c, float degrees)
Shift hue by degrees (wraps around 360).
canvas::Color Color
Definition theme.hpp:12
float min_contrast_for_level(ContrastLevel level)
Get the minimum contrast ratio required for a given level.
std::optional< Color > adjust_for_contrast(Color foreground, Color background, ContrastLevel level=ContrastLevel::aa_normal)
Given a background color and a desired foreground, adjust the foreground lightness until it meets the...
Color adjust_lightness(Color c, float delta)
Adjust lightness by a delta (clamped to [0,1]).
@ a
Definition input_events.hpp:39
@ c
Definition input_events.hpp:39
@ b
Definition input_events.hpp:39
@ t
Definition input_events.hpp:41
float relative_luminance(Color c)
Compute relative luminance of a color per WCAG 2.1 definition.
ContrastLevel
WCAG AA compliance levels.
Definition theme_contrast.hpp:22
@ aaa_normal
Definition theme_contrast.hpp:25
@ aaa_large
Definition theme_contrast.hpp:26
@ aa_normal
Definition theme_contrast.hpp:23
@ aa_large
Definition theme_contrast.hpp:24
HSL rgb_to_hsl(Color c)
Definition theme_contrast.hpp:52
Color hsl_to_rgb(HSL hsl, float alpha=1.0f)
Definition theme_contrast.hpp:53
canvas::Color::HSL HSL
Definition theme_contrast.hpp:50
Color with_alpha(Color c, float alpha)
Apply alpha to a color [0.0-1.0].
Color auto_contrast_foreground(Color background, ContrastLevel level=ContrastLevel::aa_normal)
Given a background color, compute an accessible foreground color.
Definition canvas.hpp:75
static Color from_hsl(HSL hsl, float alpha=1.0f)
Definition theme_contrast.hpp:69
ContrastLevel required_level
Definition theme_contrast.hpp:73
std::string foreground_token
Definition theme_contrast.hpp:70
std::string background_token
Definition theme_contrast.hpp:71
float ratio
Definition theme_contrast.hpp:72
Definition theme.hpp:32