Class: Wx::SF::LayoutAlgorithm
- Inherits:
-
Object
- Object
- Wx::SF::LayoutAlgorithm
- Defined in:
- lib/wx/shapes/auto_layout.rb
Overview
Base class for all layouting algorithms.
Direct Known Subclasses
LayoutCircle, LayoutHorizontalTree, LayoutMesh, LayoutVerticalTree
Instance Method Summary collapse
-
#do_layout(shapes) ⇒ Object
Function performing the layout change.
-
#get_bounding_box(shapes) ⇒ Wx::Rect
protected
Calculate bounding box surrounding given shapes.
-
#get_shapes_center(shapes) ⇒ Wx::RealPoint
protected
Get center point of given shapes.
-
#get_shapes_extent(shapes) ⇒ Wx::Size
protected
Get overall extent of all given shapes calculated as a sum of their width and height.
-
#get_top_left(shapes) ⇒ Wx::RealPoint
protected
Get top-left point of bounding box surrounding given shapes.
Instance Method Details
#do_layout(shapes) ⇒ Object
Function performing the layout change. All derived classes must implement it.
11 12 13 |
# File 'lib/wx/shapes/auto_layout.rb', line 11 def do_layout(shapes) ::Kernel.raise NotImplementedError end |
#get_bounding_box(shapes) ⇒ Wx::Rect (protected)
Calculate bounding box surrounding given shapes.
20 21 22 23 24 |
# File 'lib/wx/shapes/auto_layout.rb', line 20 def get_bounding_box(shapes) shapes.inject(nil) do |rct_bb, shape| rct_bb ? rct_bb.union!(shape.get_bounding_box) : shape.get_bounding_box end end |
#get_shapes_center(shapes) ⇒ Wx::RealPoint (protected)
Get center point of given shapes.
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/wx/shapes/auto_layout.rb', line 41 def get_shapes_center(shapes) center = shapes.inject(Wx::RealPoint.new) do |centre, shape| sh_pos = shape.get_absolute_position centre.x += sh_pos.x centre.y += sh_pos.y centre end center.x /= shapes.size center.y /= shapes.size center end |
#get_shapes_extent(shapes) ⇒ Wx::Size (protected)
Get overall extent of all given shapes calculated as a sum of their width and height.
29 30 31 32 33 34 35 36 |
# File 'lib/wx/shapes/auto_layout.rb', line 29 def get_shapes_extent(shapes) shapes.inject(Wx::Size.new) do |ext_sz, shape| sh_bb = shape.get_bounding_box ext_sz.width += sh_bb.width ext_sz.height += sh_bb.height ext_sz end end |
#get_top_left(shapes) ⇒ Wx::RealPoint (protected)
Get top-left point of bounding box surrounding given shapes.
56 57 58 59 60 61 62 63 |
# File 'lib/wx/shapes/auto_layout.rb', line 56 def get_top_left(shapes) shapes.inject(Wx::RealPoint.new(::Float::MAX, ::Float::MAX)) do |pos, shape| sh_pos = shape.get_absolute_position pos.x = sh_pos.x if sh_pos.x < pos.x pos.y = sh_pos.y if sh_pos.y < pos.y pos end end |