Class: Wx::SF::LayoutHorizontalTree

Inherits:
LayoutAlgorithm show all
Defined in:
lib/wx/shapes/auto_layout.rb

Overview

Class encapsulating algorithm which layouts all top-most shapes into horizontal tree registered under “Horizontal 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

#initializeLayoutHorizontalTree

Constructor.



169
170
171
# File 'lib/wx/shapes/auto_layout.rb', line 169

def initialize
  @h_space = @v_space = 30.0
end

Instance Attribute Details

#h_spaceObject

Get or set horizontal space between shapes.



174
175
176
# File 'lib/wx/shapes/auto_layout.rb', line 174

def h_space
  @h_space
end

#v_spaceObject

Get or set vertical space between shapes.



177
178
179
# File 'lib/wx/shapes/auto_layout.rb', line 177

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



181
182
183
184
185
186
187
188
189
190
# File 'lib/wx/shapes/auto_layout.rb', line 181

def do_layout(shapes)
  start = get_top_left(shapes)
  min_y = start.y
  # find root items
  shapes.each do |shape|
    lst_connections = shape.get_assigned_connections(LineShape, Shape::CONNECTMODE::ENDING)

    min_y, _ = process_node(shape, start.x, min_y, 0) if lst_connections.empty?
  end
end

#process_node(node, x, min_y, curr_max_height) ⇒ Array(Float, Integer) (protected)

Process single shape.

Parameters:

  • node (Wx::Shape)

    processed shape.

  • x (Float)

    Vertical position of the shape.

  • min_y (Float)
  • curr_max_height (Integer)

Returns:

  • (Array(Float, Integer))


200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/wx/shapes/auto_layout.rb', line 200

def process_node(node, x, min_y, curr_max_height)
  if node
    node.move_to(x, min_y)

    rct_bb = node.get_bounding_box
    curr_max_height = rct_bb.height if rct_bb.height > curr_max_height

    lst_neighbours = node.get_neighbours(LineShape, Shape::CONNECTMODE::STARTING)

    if lst_neighbours.empty?
      min_y += curr_max_height + @v_space
    else
      lst_neighbours.each do |nbs|
        unless nbs.get_parent_shape
          min_y, curr_max_height = process_node(nbs, x + rct_bb.width + @h_space, min_y, curr_max_height)
        end
      end
    end
  end
  [min_y, curr_max_height]
end