Module: Plushie::Type::Theme
- Defined in:
- lib/plushie/type/theme.rb
Overview
Theme selection for windows and the application.
22 built-in themes, :system for OS preference, or a custom palette map.
Constant Summary collapse
- BUILTIN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Built-in theme names.
%i[ light dark dracula nord solarized_light solarized_dark gruvbox_light gruvbox_dark catppuccin_latte catppuccin_frappe catppuccin_macchiato catppuccin_mocha tokyo_night tokyo_night_storm tokyo_night_light kanagawa_wave kanagawa_dragon kanagawa_lotus moonfly nightfly oxocarbon ferra ].freeze
- CORE_SEEDS =
Core palette seeds.
%i[background text primary success danger warning].freeze
- COLOR_FAMILIES =
Color families with base/weak/strong shades.
%i[primary secondary success warning danger].freeze
- BACKGROUND_SHADES =
Background shade levels.
%i[ background_base background_weakest background_weaker background_weak background_neutral background_strong background_stronger background_strongest ].freeze
- VALID_CUSTOM_KEYS =
All valid custom theme keys (computed once).
begin shade_keys = COLOR_FAMILIES.flat_map { |f| %w[base weak strong].flat_map { |s| [:"#{f}_#{s}", :"#{f}_#{s}_text"] } } bg_keys = BACKGROUND_SHADES.flat_map { |s| [s, :"#{s}_text"] } (CORE_SEEDS + shade_keys + bg_keys).freeze end
Class Method Summary collapse
-
.custom(name, base: nil, **overrides) ⇒ Hash
Create a custom theme from a base and color overrides.
-
.encode(value) ⇒ String, Hash
Encode a theme value for the wire protocol.
-
.valid_custom_keys ⇒ Array<Symbol>
All valid keys for custom theme overrides.
Class Method Details
.custom(name, base: nil, **overrides) ⇒ Hash
Create a custom theme from a base and color overrides.
All keys are validated against the known set of core seeds and shade overrides. Unknown keys raise ArgumentError to catch typos.
Note: :secondary is not a core seed. It is auto-derived from :background and :text by iced's palette generator. Use shade overrides (secondary_base, secondary_weak, secondary_strong plus _text variants) for fine-grained control.
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/plushie/type/theme.rb', line 90 def custom(name, base: nil, **overrides) validate_custom_keys!(overrides) result = {name: name} result[:base] = base.to_s if base overrides.each do |key, value| result[key] = Color.cast(value) end result end |
.encode(value) ⇒ String, Hash
Encode a theme value for the wire protocol.
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/plushie/type/theme.rb', line 64 def encode(value) case value when :system then "system" when Symbol raise ArgumentError, "unknown theme: #{value.inspect}" unless BUILTIN.include?(value) value.to_s when Hash then value when String then value else raise ArgumentError, "invalid theme: #{value.inspect}" end end |
.valid_custom_keys ⇒ Array<Symbol>
Returns all valid keys for custom theme overrides.
104 |
# File 'lib/plushie/type/theme.rb', line 104 def valid_custom_keys = VALID_CUSTOM_KEYS |