Class: Shellfie::ThemeData
- Inherits:
-
Object
- Object
- Shellfie::ThemeData
- Defined in:
- lib/shellfie/theme_data.rb
Instance Attribute Summary collapse
-
#button_colors ⇒ Object
readonly
Returns the value of attribute button_colors.
-
#button_style ⇒ Object
readonly
Returns the value of attribute button_style.
-
#buttons_position ⇒ Object
readonly
Returns the value of attribute buttons_position.
-
#colors ⇒ Object
readonly
Returns the value of attribute colors.
-
#font ⇒ Object
readonly
Returns the value of attribute font.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#title_alignment ⇒ Object
readonly
Returns the value of attribute title_alignment.
-
#window_decoration ⇒ Object
readonly
Returns the value of attribute window_decoration.
Class Method Summary collapse
- .deep_merge(base, overrides) ⇒ Object
- .from_theme(theme, name:, colors: {}, window_decoration: {}, font: {}, headless: false) ⇒ Object
Instance Method Summary collapse
- #color_for(name) ⇒ Object
- #headless ⇒ Object
-
#initialize(name:, colors:, window_decoration:, button_colors:, buttons_position:, button_style:, font:, title_alignment:) ⇒ ThemeData
constructor
A new instance of ThemeData.
Constructor Details
#initialize(name:, colors:, window_decoration:, button_colors:, buttons_position:, button_style:, font:, title_alignment:) ⇒ ThemeData
Returns a new instance of ThemeData.
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/shellfie/theme_data.rb', line 28 def initialize(name:, colors:, window_decoration:, button_colors:, buttons_position:, button_style:, font:, title_alignment:) @name = name @colors = deep_freeze_copy(colors) @window_decoration = deep_freeze_copy(window_decoration) @button_colors = deep_freeze_copy() @buttons_position = @button_style = @font = deep_freeze_copy(font) @title_alignment = title_alignment freeze end |
Instance Attribute Details
#button_colors ⇒ Object (readonly)
Returns the value of attribute button_colors.
5 6 7 |
# File 'lib/shellfie/theme_data.rb', line 5 def @button_colors end |
#button_style ⇒ Object (readonly)
Returns the value of attribute button_style.
5 6 7 |
# File 'lib/shellfie/theme_data.rb', line 5 def @button_style end |
#buttons_position ⇒ Object (readonly)
Returns the value of attribute buttons_position.
5 6 7 |
# File 'lib/shellfie/theme_data.rb', line 5 def @buttons_position end |
#colors ⇒ Object (readonly)
Returns the value of attribute colors.
5 6 7 |
# File 'lib/shellfie/theme_data.rb', line 5 def colors @colors end |
#font ⇒ Object (readonly)
Returns the value of attribute font.
5 6 7 |
# File 'lib/shellfie/theme_data.rb', line 5 def font @font end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/shellfie/theme_data.rb', line 5 def name @name end |
#title_alignment ⇒ Object (readonly)
Returns the value of attribute title_alignment.
5 6 7 |
# File 'lib/shellfie/theme_data.rb', line 5 def title_alignment @title_alignment end |
#window_decoration ⇒ Object (readonly)
Returns the value of attribute window_decoration.
5 6 7 |
# File 'lib/shellfie/theme_data.rb', line 5 def window_decoration @window_decoration end |
Class Method Details
.deep_merge(base, overrides) ⇒ Object
22 23 24 25 26 |
# File 'lib/shellfie/theme_data.rb', line 22 def self.deep_merge(base, overrides) base.merge(overrides) do |_key, left, right| left.is_a?(Hash) && right.is_a?(Hash) ? deep_merge(left, right) : right end end |
.from_theme(theme, name:, colors: {}, window_decoration: {}, font: {}, headless: false) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/shellfie/theme_data.rb', line 8 def self.from_theme(theme, name:, colors: {}, window_decoration: {}, font: {}, headless: false) data = new( name: name, colors: theme.colors.merge(colors || {}), window_decoration: deep_merge(theme.window_decoration, window_decoration || {}), button_colors: theme., buttons_position: theme., button_style: theme., font: theme.font.merge(font || {}), title_alignment: theme.title_alignment ) headless ? data.headless : data end |
Instance Method Details
#color_for(name) ⇒ Object
41 42 43 44 45 |
# File 'lib/shellfie/theme_data.rb', line 41 def color_for(name) return name if name.is_a?(String) && name.start_with?("#") colors[name.to_sym] || colors[:foreground] end |
#headless ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/shellfie/theme_data.rb', line 47 def headless self.class.new( name: name, colors: colors, window_decoration: self.class.deep_merge( window_decoration, title_bar_height: 0, corner_radius: 0, button_size: 0, button_spacing: 0 ), button_colors: [], buttons_position: :left, button_style: :none, font: font, title_alignment: :left ) end |