Module: Wx::SF::ManagerShape
Overview
Mixin for container shape classes that control there child shape size/position/alignment.
Instance Method Summary collapse
-
#do_alignment ⇒ Object
Update the shape’s position in order to its alignment.
- #do_children_layout ⇒ Object protected
-
#fit_shape_to_rect(shape, rct) ⇒ Object
protected
Move and resize given shape so it will fit the given bounding rectangle.
-
#is_manager ⇒ Boolean
(also: #manager?)
Returns true if the shape manages (size/position/alignment) of it’s child shapes.
Instance Method Details
#do_alignment ⇒ Object
Update the shape’s position in order to its alignment
17 18 19 20 21 22 |
# File 'lib/wx/shapes/shapes/manager_shape.rb', line 17 def do_alignment super # do alignment of shape's children do_children_layout end |
#do_children_layout ⇒ Object (protected)
26 27 28 |
# File 'lib/wx/shapes/shapes/manager_shape.rb', line 26 def do_children_layout raise NotImplementedError, 'Manager shapes need override' end |
#fit_shape_to_rect(shape, rct) ⇒ Object (protected)
Move and resize given shape so it will fit the given bounding rectangle.
The shape is aligned inside the given bounding rectangle in accordance to the shape’s valign and halign flags.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/wx/shapes/shapes/manager_shape.rb', line 38 def fit_shape_to_rect(shape, rct) shape_bb = shape.get_bounding_box prev_pos = shape.get_relative_position # do vertical alignment case shape.get_v_align when Shape::VALIGN::TOP shape.set_relative_position(prev_pos.x, rct.top + shape.get_v_border) when Shape::VALIGN::MIDDLE shape.set_relative_position(prev_pos.x, rct.top + (rct.height/2 - shape_bb.height/2)) when Shape::VALIGN::BOTTOM shape.set_relative_position(prev_pos.x, rct.bottom - shape_bb.height - shape.get_v_border) when Shape::VALIGN::EXPAND shape.set_relative_position(prev_pos.x, rct.top + shape.get_v_border) shape.scale(1.0, (rct.height - 2*shape.get_v_border).to_f/shape_bb.height) else shape.set_relative_position(prev_pos.x, rct.top) end prev_pos = shape.get_relative_position # do horizontal alignment case shape.get_h_align when Shape::HALIGN::LEFT shape.set_relative_position(rct.left + shape.get_h_border, prev_pos.y) when Shape::HALIGN::CENTER shape.set_relative_position(rct.left + (rct.width/2 - shape_bb.width/2), prev_pos.y) when Shape::HALIGN::RIGHT shape.set_relative_position(rct.right - shape_bb.width - shape.get_h_border, prev_pos.y) when Shape::HALIGN::EXPAND shape.set_relative_position(rct.left + shape.get_h_border, prev_pos.y) shape.scale((rct.width - 2*shape.get_h_border).to_f/shape_bb.width, 1.0) else shape.set_relative_position(rct.left, prev_pos.y) end end |
#is_manager ⇒ Boolean Also known as: manager?
Returns true if the shape manages (size/position/alignment) of it’s child shapes.
11 12 13 |
# File 'lib/wx/shapes/shapes/manager_shape.rb', line 11 def is_manager true end |