Class: Wx::SF::LayoutVerticalTree

Inherits:
LayoutAlgorithm show all
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

Instance Method Summary collapse

Methods inherited from LayoutAlgorithm

#get_bounding_box, #get_shapes_center, #get_shapes_extent, #get_top_left

Constructor Details

#initializeLayoutVerticalTree

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_spaceObject

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_spaceObject

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.

Parameters:

  • shapes (Array<Shape>)

    List of shapes which should be layout-ed



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.

Parameters:

  • node (Wx::Shape)

    processed shape.

  • y (Float)

    Vertical position of the shape.

  • min_x (Float)
  • curr_max_width (Integer)

Returns:

  • (Array(Float, Integer))


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