Class: Echoes::PaneTree
- Inherits:
-
Object
- Object
- Echoes::PaneTree
- Defined in:
- lib/echoes/pane_tree.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#active_pane ⇒ Object
Returns the value of attribute active_pane.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
-
#initialize(pane) ⇒ PaneTree
constructor
A new instance of PaneTree.
-
#layout(x, y, w, h) ⇒ Object
Calculate layout rectangles for all panes Returns [x:, y:, w:, h:, …].
-
#next_pane(current) ⇒ Object
Cycle to next pane.
- #pane_count ⇒ Object
-
#panes ⇒ Object
Flat list of all panes (in-order traversal).
-
#prev_pane(current) ⇒ Object
Cycle to previous pane.
-
#remove(pane) ⇒ Object
Remove a pane, promoting its sibling.
- #single_pane? ⇒ Boolean
-
#split(pane, direction, new_pane) ⇒ Object
Split the active pane in the given direction, returning the new pane.
Constructor Details
Instance Attribute Details
#active_pane ⇒ Object
Returns the value of attribute active_pane.
28 29 30 |
# File 'lib/echoes/pane_tree.rb', line 28 def active_pane @active_pane end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
27 28 29 |
# File 'lib/echoes/pane_tree.rb', line 27 def root @root end |
Instance Method Details
#layout(x, y, w, h) ⇒ Object
Calculate layout rectangles for all panes Returns [x:, y:, w:, h:, …]
72 73 74 |
# File 'lib/echoes/pane_tree.rb', line 72 def layout(x, y, w, h) layout_node(@root, x, y, w, h) end |
#next_pane(current) ⇒ Object
Cycle to next pane
82 83 84 85 86 87 |
# File 'lib/echoes/pane_tree.rb', line 82 def next_pane(current) list = panes idx = list.index(current) return list.first unless idx list[(idx + 1) % list.size] end |
#pane_count ⇒ Object
101 102 103 |
# File 'lib/echoes/pane_tree.rb', line 101 def pane_count panes.size end |
#panes ⇒ Object
Flat list of all panes (in-order traversal)
77 78 79 |
# File 'lib/echoes/pane_tree.rb', line 77 def panes collect_panes(@root) end |
#prev_pane(current) ⇒ Object
Cycle to previous pane
90 91 92 93 94 95 |
# File 'lib/echoes/pane_tree.rb', line 90 def prev_pane(current) list = panes idx = list.index(current) return list.last unless idx list[(idx - 1) % list.size] end |
#remove(pane) ⇒ Object
Remove a pane, promoting its sibling
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/echoes/pane_tree.rb', line 50 def remove(pane) return nil if single_pane? parent = find_parent(@root, pane) return nil unless parent sibling = if pane_in_subtree?(parent.left, pane) parent.right else parent.left end replace_node(parent, sibling) if @active_pane == pane @active_pane = panes.first end pane end |
#single_pane? ⇒ Boolean
97 98 99 |
# File 'lib/echoes/pane_tree.rb', line 97 def single_pane? @root.is_a?(PaneNode) end |
#split(pane, direction, new_pane) ⇒ Object
Split the active pane in the given direction, returning the new pane
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/echoes/pane_tree.rb', line 36 def split(pane, direction, new_pane) node = find_node(@root, pane) return nil unless node old_node = PaneNode.new(pane) new_node = PaneNode.new(new_pane) split_node = SplitNode.new(direction: direction, left: old_node, right: new_node) replace_node(node, split_node) @active_pane = new_pane new_pane end |