Class: Tuile::Theme::Ref
- Inherits:
-
Object
- Object
- Tuile::Theme::Ref
- Defined in:
- lib/tuile/theme.rb,
sig/tuile.rbs
Overview
A live reference to a theme token, resolved against the current theme at paint time rather than baked to a concrete Color. Assign one where a slot is resolved late — currently Component#bg_color= — and it follows light/dark flips with no Component#on_theme_changed hook:
panel.bg_color = Tuile::Theme.ref(:panel_bg) # a #custom token
dropdown.bg_color = Tuile::Theme.ref(:input_bg_color) # built-in chrome
The name may be a built-in chrome token (CHROME_TOKENS) or a #custom one; a chrome name takes precedence on the (pathological) collision. This does not add a global bg/fg token — it only lets a slot point at a color the theme already carries, resolved the same way framework chrome already resolves it.
Distinct from Color.coerce's symbol support, which names one of the 16 ANSI colors and yields a fixed Color; a Ref names a theme token and re-reads it each paint.
Immutable.
Instance Method Summary collapse
-
#resolve(theme) ⇒ Color
Resolves to the concrete Color
namemaps to intheme— a built-in chrome reader whennameis one (chrome_token?), else a #custom token.
Instance Method Details
#resolve(theme) ⇒ Color
Resolves to the concrete Color name maps to in theme — a built-in
chrome reader when name is one (Tuile::Theme.chrome_token?), else a
Tuile::Theme#custom token.
@param theme
150 151 152 153 154 |
# File 'lib/tuile/theme.rb', line 150 def resolve(theme) return theme.public_send(name) if Theme.chrome_token?(name) theme[name] end |