Class: Charming::Layout::Overlay

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

Overview

Overlay is a compositing node used by ScreenLayout for floating elements (modals, dialogs, command palettes). It positions its content at top/left (each may be ‘:center` or an absolute cell offset) and optionally sizes it via width/height with an outer style.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content: nil, block: nil, view: nil, top: :center, left: :center, width: nil, height: nil, style: nil, z_index: 0) ⇒ Overlay

content (or a block) provides the body. top/left default to :center. width/height fix the overlay’s dimensions; when unset, the content’s natural size is used. style wraps the rendered content in a UI::Style. z_index controls stacking: higher values composite on top (ties keep registration order).



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/charming/presentation/layout/overlay.rb', line 18

def initialize(content: nil, block: nil, view: nil, top: :center, left: :center, width: nil, height: nil, style: nil, z_index: 0)
  @content = content
  @block = block
  @view = view
  @top = top
  @left = left
  @width = width
  @height = height
  @style = style
  @z_index = z_index
end

Instance Attribute Details

#leftObject (readonly)

The vertical and horizontal offset (cell count or ‘:center`) of the overlay within the parent canvas, and its stacking order (higher paints later/on top).



12
13
14
# File 'lib/charming/presentation/layout/overlay.rb', line 12

def left
  @left
end

#topObject (readonly)

The vertical and horizontal offset (cell count or ‘:center`) of the overlay within the parent canvas, and its stacking order (higher paints later/on top).



12
13
14
# File 'lib/charming/presentation/layout/overlay.rb', line 12

def top
  @top
end

#z_indexObject (readonly)

The vertical and horizontal offset (cell count or ‘:center`) of the overlay within the parent canvas, and its stacking order (higher paints later/on top).



12
13
14
# File 'lib/charming/presentation/layout/overlay.rb', line 12

def z_index
  @z_index
end

Instance Method Details

#renderObject

Renders the overlay’s content; when width or height is set, places the rendered content into a sized canvas before returning.



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

def render
  return styled_content unless width || height

  UI.place(styled_content, width: width || UI.block_width(styled_content.lines(chomp: true)), height: height || styled_content.lines.count)
end