1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
//! `component_tokens!`: generates one widget's component-token struct, its
//! `resolve()`, and its `component.<widget>.*` key registry constant from a
//! SINGLE table (method name => default [`crate::tokens::ColorSpec`]) — so a
//! key can never exist in the struct but be missing from the registry, or
//! the reverse (H1 token contract design §3). `atomic/button/tokens.rs` is
//! the worked example; every later widget's own `tokens.rs` copies this
//! recipe.
//!
//! ```ignore
//! // ui/widgets/atomic/checkbox/tokens.rs
//! use crate::tokens::{component_tokens, ColorSpec, ColorValue, Modifier, Role};
//!
//! component_tokens! {
//! widget = "checkbox",
//! struct CheckboxTokens, keys = CHECKBOX_KEYS;
//!
//! // One arm per `CheckboxTheme` method that OWNS a literal — required
//! // methods, plus any default-body method that returns its own
//! // literal rather than delegating to `self.other_method()` (H1's
//! // "scope note on trait-default methods"). Pure delegators need no
//! // arm here and no override in `impl CheckboxTheme for TokenTheme`.
//! checkbox_bg_checked => ColorSpec::Alias(Role::AccentDefault, None),
//! checkbox_border => ColorSpec::Literal(ColorValue::Transparent),
//! }
//! ```
//!
//! Then, three more steps land the widget on the token contract:
//! 1. Add `"checkbox" => Some(crate::ui::widgets::atomic::checkbox::tokens::CHECKBOX_KEYS)`
//! to the match in [`crate::tokens::component_keys`].
//! 2. Add a `checkbox: crate::ui::widgets::atomic::checkbox::tokens::CheckboxTokens`
//! field to [`crate::tokens::set::Tokens`] (built in
//! [`crate::tokens::set::TokenSet::resolve`] via `CheckboxTokens::resolve(&semantic,
//! &self.components)`), plus a `pub(crate) fn checkbox(&self) -> &CheckboxTokens`
//! accessor.
//! 3. Add `impl CheckboxTheme for TokenTheme` in `tokens/theme.rs`, one line
//! per owned method reading `&self.0.checkbox().<field>`.
//!
//! **Ambiguity trap.** Several widgets share a trait method name (`bg`,
//! `border`, `text`, `transparency_checker_a`, …) — once `TokenTheme`
//! implements two traits that both declare the same method name, calling it
//! through plain inference (`theme.bg()`) is ambiguous and fails to compile
//! the moment the second trait lands. This is invisible in each widget's own
//! `tokens.rs` unit tests (they call through the concrete `Tokens` accessor,
//! never the trait), so it only bites in `tokens/theme.rs`'s own cross-widget
//! tests and any other call site reachable from more than one implemented
//! trait. Fix at the call site with fully-qualified syntax,
//! `<Trait>::<method>(&theme)` (see `tokens/theme.rs`'s
//! `token_theme_reads_through_to_resolved_button_tokens` test) — never by
//! renaming the shared method on either trait.
/// Byte-array variant of [`component_tokens!`] for the one widget whose
/// trait returns `[u8; 4]` instead of `&str`
/// (`text_input::TextInputTheme` — H1 Brief 7b, companion doc "text_input"
/// section: "the only such widget"). Same single-table shape and the same
/// ambiguity trap applies; the only difference is the resolved value stays a
/// `[u8; 4]` (via [`crate::tokens::color::ColorValue::to_rgba8`]) instead of
/// a pre-rendered CSS `String`.
}
}
};
}
pub use component_tokens;
pub use component_tokens_bytes;