Class: Rooibos::Welcome::UI::ButtonAreas

Inherits:
Data
  • Object
show all
Defined in:
lib/rooibos/welcome.rb

Overview

Value object wrapping hit-test areas for clickable buttons.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#exitObject (readonly)

Returns the value of attribute exit

Returns:

  • (Object)

    the current value of exit



147
148
149
# File 'lib/rooibos/welcome.rb', line 147

def exit
  @exit
end

#websiteObject (readonly)

Returns the value of attribute website

Returns:

  • (Object)

    the current value of website



147
148
149
# File 'lib/rooibos/welcome.rb', line 147

def website
  @website
end

Instance Method Details

#button_at(x, y) ⇒ Object



150
151
152
153
154
155
# File 'lib/rooibos/welcome.rb', line 150

def button_at(x, y)
  return :website if website&.contains?(x, y)
  return :exit if exit&.contains?(x, y)

  nil
end

#contains?(name, x, y) ⇒ Boolean

Returns:

  • (Boolean)


148
# File 'lib/rooibos/welcome.rb', line 148

def contains?(name, x, y) = public_send(name)&.contains?(x, y)

#for_viewport(width, height) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/rooibos/welcome.rb', line 157

def for_viewport(width, height)
  viewport = RatatuiRuby::Layout::Rect.new(x: 0, y: 0, width:, height:)
  frame = UI.frame(focused: nil, hovered: nil)
  inner = frame.inner(viewport)

  content_rects = RatatuiRuby::Layout::Layout.split(
    inner,
    direction: :vertical,
    constraints: CONTENT_CONSTRAINTS
  )
  button_rects = RatatuiRuby::Layout::Layout.split(
    content_rects[1],
    direction: :horizontal,
    constraints: BUTTON_BAR_CONSTRAINTS
  )

  ButtonAreas.new(
    website: button_rects[BUTTON_SLOTS[:website]],
    exit: button_rects[BUTTON_SLOTS[:exit]]
  )
end