Class: RETerm::Layout
- Includes:
- NavInput
- Defined in:
- lib/reterm/layout.rb
Overview
Provides mechanism to orgranize on screen components according to rules defined by subclasses.
Layouts themselves are specialized types of components as they are intended to be associated with windows in which to be rendered
Direct Known Subclasses
Constant Summary
Constants included from NavInput
NavInput::DOWN_CONTROLS, NavInput::ENTER_CONTROLS, NavInput::LEFT_CONTROLS, NavInput::QUIT_CONTROLS, NavInput::RIGHT_CONTROLS, NavInput::UP_CONTROLS
Instance Attribute Summary collapse
-
#children ⇒ Object
TODO padding / margin support.
Attributes inherited from Component
Instance Method Summary collapse
-
#activatable? ⇒ Boolean
Return boolean indicating if any child component is activatable.
-
#activate! ⇒ Object
Activates layout by dispatching to navigation input system.
-
#add_child(h = {}) ⇒ Object
Create new child window and add it to layout.
-
#draw! ⇒ Object
Draw all layout children.
-
#exceeds_bounds?(child) ⇒ Boolean
Subclasses should override this method returning boolean if child window exceeds bounds of layout.
-
#initialize(args = {}) ⇒ Layout
constructor
A new instance of Layout.
Methods included from NavInput
#focusable, #focusable?, #handle_input
Methods inherited from Component
#colored?, #colors=, #finalize!
Constructor Details
#initialize(args = {}) ⇒ Layout
Returns a new instance of Layout.
14 15 16 |
# File 'lib/reterm/layout.rb', line 14 def initialize(args={}) @children ||= [] end |
Instance Attribute Details
#children ⇒ Object
TODO padding / margin support
12 13 14 |
# File 'lib/reterm/layout.rb', line 12 def children @children end |
Instance Method Details
#activatable? ⇒ Boolean
Return boolean indicating if any child component is activatable
26 27 28 |
# File 'lib/reterm/layout.rb', line 26 def activatable? children.any? { |c| c.component.activatable? } end |
#activate! ⇒ Object
Activates layout by dispatching to navigation input system.
57 58 59 60 61 |
# File 'lib/reterm/layout.rb', line 57 def activate! draw! update_reterm handle_input end |
#add_child(h = {}) ⇒ Object
Create new child window and add it to layout
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/reterm/layout.rb', line 31 def add_child(h={}) child = window.create_child(h) if child.win.nil? raise ArgumentError, "could not create child window" end if exceeds_bounds?(child) window.del_child(child) unless child.win.nil? raise ArgumentError, "child exceeds bounds" end children << child update_reterm child end |
#draw! ⇒ Object
Draw all layout children
49 50 51 |
# File 'lib/reterm/layout.rb', line 49 def draw! children.each { |c| c.draw! } end |
#exceeds_bounds?(child) ⇒ Boolean
Subclasses should override this method returning boolean if child window exceeds bounds of layout
20 21 22 |
# File 'lib/reterm/layout.rb', line 20 def exceeds_bounds?(child) raise "NotImplemented" end |