Class: Wx::SF::LayoutVerticalTree
- Inherits:
-
LayoutAlgorithm
- Object
- LayoutAlgorithm
- Wx::SF::LayoutVerticalTree
- Defined in:
- lib/wx/shapes/auto_layout.rb
Overview
Class encapsulating algorithm which layouts all top-most shapes into vertical tree registered under “Vertical Tree” name.
Instance Attribute Summary collapse
-
#h_space ⇒ Object
Get or set horizontal space between shapes.
-
#v_space ⇒ Object
Get or set vertical space between shapes.
Instance Method Summary collapse
-
#do_layout(shapes) ⇒ Object
Function performing the layout change.
-
#initialize ⇒ LayoutVerticalTree
constructor
Constructor.
-
#process_node(node, y, min_x, curr_max_width) ⇒ Array(Float, Integer)
protected
Process single shape.
Methods inherited from LayoutAlgorithm
#get_bounding_box, #get_shapes_center, #get_shapes_extent, #get_top_left
Constructor Details
#initialize ⇒ LayoutVerticalTree
Constructor.
110 111 112 |
# File 'lib/wx/shapes/auto_layout.rb', line 110 def initialize @h_space = @v_space = 30.0 end |
Instance Attribute Details
#h_space ⇒ Object
Get or set horizontal space between shapes.
115 116 117 |
# File 'lib/wx/shapes/auto_layout.rb', line 115 def h_space @h_space end |
#v_space ⇒ Object
Get or set vertical space between shapes.
118 119 120 |
# File 'lib/wx/shapes/auto_layout.rb', line 118 def v_space @v_space end |
Instance Method Details
#do_layout(shapes) ⇒ Object
Function performing the layout change.
122 123 124 125 126 127 128 129 130 131 |
# File 'lib/wx/shapes/auto_layout.rb', line 122 def do_layout(shapes) start = get_top_left(shapes) min_x = start.x # find root items shapes.each do |shape| lst_connections = shape.get_assigned_connections(LineShape, Shape::CONNECTMODE::ENDING) min_x, _ = process_node(shape, start.y, min_x, 0) if lst_connections.empty? end end |
#process_node(node, y, min_x, curr_max_width) ⇒ Array(Float, Integer) (protected)
Process single shape.
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/wx/shapes/auto_layout.rb', line 141 def process_node(node, y, min_x, curr_max_width) if node node.move_to(min_x, y) rct_bb = node.get_bounding_box curr_max_width = rct_bb.width if rct_bb.width > curr_max_width lst_neighbours = node.get_neighbours(LineShape, Shape::CONNECTMODE::STARTING) if lst_neighbours.empty? min_x += curr_max_width + @h_space else lst_neighbours.each do |nbs| unless nbs.get_parent_shape min_x, curr_max_width = process_node(nbs, y + rct_bb.height + @v_space, min_x, curr_max_width) end end end end [min_x, curr_max_width] end |