Class: Charming::Layout::PaneStyle

Inherits:
Object
  • Object
show all
Defined in:
lib/charming/presentation/layout/pane_style.rb

Overview

PaneStyle holds a Pane’s base style and the focused-state override. It resolves which style to use at render time given the pane’s current focus state and the view’s theme.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(style:, focused_style:) ⇒ PaneStyle

Returns a new instance of PaneStyle.



15
16
17
18
# File 'lib/charming/presentation/layout/pane_style.rb', line 15

def initialize(style:, focused_style:)
  @style, @focused_style = style, focused_style
  freeze
end

Instance Attribute Details

#focused_styleObject (readonly)

Returns the value of attribute focused_style.



9
10
11
# File 'lib/charming/presentation/layout/pane_style.rb', line 9

def focused_style
  @focused_style
end

#styleObject (readonly)

Returns the value of attribute style.



9
10
11
# File 'lib/charming/presentation/layout/pane_style.rb', line 9

def style
  @style
end

Class Method Details

.build(style: nil, focused_style: nil) ⇒ Object



11
12
13
# File 'lib/charming/presentation/layout/pane_style.rb', line 11

def self.build(style: nil, focused_style: nil)
  new(style: style, focused_style: focused_style)
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



20
21
22
23
# File 'lib/charming/presentation/layout/pane_style.rb', line 20

def ==(other)
  other.is_a?(PaneStyle) &&
    style == other.style && focused_style == other.focused_style
end

#hashObject



26
27
28
# File 'lib/charming/presentation/layout/pane_style.rb', line 26

def hash
  [style, focused_style].hash
end

#resolve(view, focused:) ⇒ Object

Returns the active style for focused: the focused override when the pane is focused, otherwise the configured style or a default UI::Style.



32
33
34
35
36
# File 'lib/charming/presentation/layout/pane_style.rb', line 32

def resolve(view, focused:)
  return focused_style || view.__send__(:theme).title if focused

  style || UI.style
end