Class: Charming::Layout::ScreenLayout
- Inherits:
-
Object
- Object
- Charming::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.
11 12 13 14 15 16 |
# File 'lib/charming/presentation/layout/screen_layout.rb', line 11 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.
19 20 21 22 23 |
# File 'lib/charming/presentation/layout/screen_layout.rb', line 19 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.
26 27 28 |
# File 'lib/charming/presentation/layout/screen_layout.rb', line 26 def (node) << node end |
#focusable_names ⇒ Object
Returns the focusable names from the child, or [] when no child has been added.
31 32 33 |
# File 'lib/charming/presentation/layout/screen_layout.rb', line 31 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.
37 38 39 40 41 42 43 |
# File 'lib/charming/presentation/layout/screen_layout.rb', line 37 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 |