Class: Shellfie::ThemeData

Inherits:
Object
  • Object
show all
Defined in:
lib/shellfie/theme_data.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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(button_colors)
  @buttons_position = buttons_position
  @button_style = button_style
  @font = deep_freeze_copy(font)
  @title_alignment = title_alignment
  freeze
end

Instance Attribute Details

#button_colorsObject (readonly)

Returns the value of attribute button_colors.



5
6
7
# File 'lib/shellfie/theme_data.rb', line 5

def button_colors
  @button_colors
end

#button_styleObject (readonly)

Returns the value of attribute button_style.



5
6
7
# File 'lib/shellfie/theme_data.rb', line 5

def button_style
  @button_style
end

#buttons_positionObject (readonly)

Returns the value of attribute buttons_position.



5
6
7
# File 'lib/shellfie/theme_data.rb', line 5

def buttons_position
  @buttons_position
end

#colorsObject (readonly)

Returns the value of attribute colors.



5
6
7
# File 'lib/shellfie/theme_data.rb', line 5

def colors
  @colors
end

#fontObject (readonly)

Returns the value of attribute font.



5
6
7
# File 'lib/shellfie/theme_data.rb', line 5

def font
  @font
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/shellfie/theme_data.rb', line 5

def name
  @name
end

#title_alignmentObject (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_decorationObject (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.button_colors,
    buttons_position: theme.buttons_position,
    button_style: theme.button_style,
    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

#headlessObject



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