Class: Charming::Presentation::Layout::ScreenLayout
- Inherits:
-
Object
- Object
- Charming::Presentation::Layout::ScreenLayout
- Defined in:
- lib/charming/presentation/layout/screen_layout.rb
Overview
ScreenLayout is the root of a layout tree. It owns a single child (typically a Split or Pane) rendered into the full terminal screen, and an ordered list of Overlays composited on top of the rendered body.
Instance Method Summary collapse
-
#add_child(node) ⇒ Object
Sets the single root child.
-
#add_overlay(node) ⇒ Object
Appends an overlay to be composited on top of the body, in registration order.
-
#focusable_names ⇒ Object
Returns the focusable names from the child, or [] when no child has been added.
-
#initialize(screen:, background: nil) ⇒ ScreenLayout
constructor
screen is the Charming::Screen whose dimensions define the layout area.
-
#render ⇒ Object
Renders the child into the full-screen rect, then overlays each registered overlay on top in order.
Constructor Details
#initialize(screen:, background: nil) ⇒ ScreenLayout
screen is the Charming::Screen whose dimensions define the layout area. background (optional) is a UI::Style applied to the empty canvas behind the body.
12 13 14 15 16 17 |
# File 'lib/charming/presentation/layout/screen_layout.rb', line 12 def initialize(screen:, background: nil) @screen = screen @background = background @child = nil @overlays = [] end |
Instance Method Details
#add_child(node) ⇒ Object
Sets the single root child. Raises ArgumentError when a child is already present.
20 21 22 23 24 |
# File 'lib/charming/presentation/layout/screen_layout.rb', line 20 def add_child(node) raise ArgumentError, "screen_layout accepts one root layout node" if child @child = node end |
#add_overlay(node) ⇒ Object
Appends an overlay to be composited on top of the body, in registration order.
27 28 29 |
# File 'lib/charming/presentation/layout/screen_layout.rb', line 27 def (node) << node end |
#focusable_names ⇒ Object
Returns the focusable names from the child, or [] when no child has been added.
32 33 34 |
# File 'lib/charming/presentation/layout/screen_layout.rb', line 32 def focusable_names child ? child.focusable_names : [] end |
#render ⇒ Object
Renders the child into the full-screen rect, then overlays each registered overlay on top in order.
38 39 40 41 42 43 44 |
# File 'lib/charming/presentation/layout/screen_layout.rb', line 38 def render body = UI.place(render_child, width: screen.width, height: screen.height, background: background) .reduce(body) do |current, | UI.(current, .render, top: .top, left: .left) end end |