Class: Charming::Presentation::Layout::Overlay
- Inherits:
-
Object
- Object
- Charming::Presentation::Layout::Overlay
- 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
-
#left ⇒ Object
readonly
The vertical and horizontal offset (cell count or ‘:center`) of the overlay within the parent canvas.
-
#top ⇒ Object
readonly
The vertical and horizontal offset (cell count or ‘:center`) of the overlay within the parent canvas.
Instance Method Summary collapse
-
#initialize(content: nil, block: nil, view: nil, top: :center, left: :center, width: nil, height: nil, style: nil) ⇒ Overlay
constructor
content (or a block) provides the body.
-
#render ⇒ Object
Renders the overlay’s content; when width or height is set, places the rendered content into a sized canvas before returning.
Constructor Details
#initialize(content: nil, block: nil, view: nil, top: :center, left: :center, width: nil, height: nil, style: nil) ⇒ 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.
18 19 20 21 22 23 24 25 26 27 |
# 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) @content = content @block = block @view = view @top = top @left = left @width = width @height = height @style = style end |
Instance Attribute Details
#left ⇒ Object (readonly)
The vertical and horizontal offset (cell count or ‘:center`) of the overlay within the parent canvas.
13 14 15 |
# File 'lib/charming/presentation/layout/overlay.rb', line 13 def left @left end |
#top ⇒ Object (readonly)
The vertical and horizontal offset (cell count or ‘:center`) of the overlay within the parent canvas.
13 14 15 |
# File 'lib/charming/presentation/layout/overlay.rb', line 13 def top @top end |
Instance Method Details
#render ⇒ Object
Renders the overlay’s content; when width or height is set, places the rendered content into a sized canvas before returning.
31 32 33 34 35 |
# File 'lib/charming/presentation/layout/overlay.rb', line 31 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 |