Class: Wx::SF::LayoutMesh

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

Overview

Class encapsulating algorithm which layouts all top-most shapes into mesh registered under “Mesh” name. The algorithm doesn’t optimize connection lines crossing.

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

#initializeLayoutMesh

Constructor.



229
230
231
# File 'lib/wx/shapes/auto_layout.rb', line 229

def initialize
  @h_space = @v_space = 30.0
end

Instance Attribute Details

#h_spaceObject

Get or set horizontal space between shapes.



234
235
236
# File 'lib/wx/shapes/auto_layout.rb', line 234

def h_space
  @h_space
end

#v_spaceObject

Get or set vertical space between shapes.



237
238
239
# File 'lib/wx/shapes/auto_layout.rb', line 237

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



241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# File 'lib/wx/shapes/auto_layout.rb', line 241

def do_layout(shapes)
  cols = Math.sqrt(shapes.size).floor
  max_h = -@h_space
  roffset = coffset = 0

  start = get_top_left(shapes)

  shapes.each_with_index do |shape, i|
    if (i % cols) == 0
      coffset = 0
      roffset += max_h + @h_space
      max_h = 0
    end

    shape.move_to(start.x + coffset, start.y + roffset)

    rct_bb = shape.get_bounding_box
    coffset += rct_bb.width + @v_space

    max_h = rct_bb.height if rct_bb.height > max_h
  end
end