Class: Ace::Tmux::Models::LayoutNode
- Inherits:
-
Object
- Object
- Ace::Tmux::Models::LayoutNode
- Defined in:
- lib/ace/tmux/models/layout_node.rb
Overview
A tree node for nested pane layouts.
Either a leaf (wraps a Pane model) or a container (direction + children). Used by LayoutStringBuilder to produce tmux custom layout strings.
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#direction ⇒ Object
readonly
Returns the value of attribute direction.
-
#pane ⇒ Object
readonly
Returns the value of attribute pane.
-
#pane_id ⇒ Object
Returns the value of attribute pane_id.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
-
#container? ⇒ Boolean
True if this node is a container (has direction + children).
-
#initialize(direction: nil, children: [], pane: nil, size: nil) ⇒ LayoutNode
constructor
A new instance of LayoutNode.
-
#leaf? ⇒ Boolean
True if this node is a leaf (has a pane, no children).
-
#leaf_count ⇒ Integer
Total number of leaf panes in this subtree.
-
#leaves ⇒ Array<LayoutNode>
All leaf nodes in DFS left-to-right order.
Constructor Details
#initialize(direction: nil, children: [], pane: nil, size: nil) ⇒ LayoutNode
Returns a new instance of LayoutNode.
19 20 21 22 23 24 25 |
# File 'lib/ace/tmux/models/layout_node.rb', line 19 def initialize(direction: nil, children: [], pane: nil, size: nil) @direction = direction @children = children @pane = pane @size = size @pane_id = nil end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
12 13 14 |
# File 'lib/ace/tmux/models/layout_node.rb', line 12 def children @children end |
#direction ⇒ Object (readonly)
Returns the value of attribute direction.
12 13 14 |
# File 'lib/ace/tmux/models/layout_node.rb', line 12 def direction @direction end |
#pane ⇒ Object (readonly)
Returns the value of attribute pane.
12 13 14 |
# File 'lib/ace/tmux/models/layout_node.rb', line 12 def pane @pane end |
#pane_id ⇒ Object
Returns the value of attribute pane_id.
13 14 15 |
# File 'lib/ace/tmux/models/layout_node.rb', line 13 def pane_id @pane_id end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
12 13 14 |
# File 'lib/ace/tmux/models/layout_node.rb', line 12 def size @size end |
Instance Method Details
#container? ⇒ Boolean
Returns true if this node is a container (has direction + children).
33 34 35 |
# File 'lib/ace/tmux/models/layout_node.rb', line 33 def container? !leaf? end |
#leaf? ⇒ Boolean
Returns true if this node is a leaf (has a pane, no children).
28 29 30 |
# File 'lib/ace/tmux/models/layout_node.rb', line 28 def leaf? @pane != nil end |
#leaf_count ⇒ Integer
Returns Total number of leaf panes in this subtree.
38 39 40 41 42 |
# File 'lib/ace/tmux/models/layout_node.rb', line 38 def leaf_count return 1 if leaf? @children.sum(&:leaf_count) end |
#leaves ⇒ Array<LayoutNode>
Returns All leaf nodes in DFS left-to-right order.
45 46 47 48 49 |
# File 'lib/ace/tmux/models/layout_node.rb', line 45 def leaves return [self] if leaf? @children.flat_map(&:leaves) end |