Class: Wx::SF::FlexGridShape
- Defined in:
- lib/wx/shapes/shapes/flex_grid_shape.rb
Overview
Class encapsulates a rectangular shape derived from GridShape class which acts as a flexible grid-based container able to manage other assigned child shapes (it can control their position). The managed shapes are aligned into defined grid with a behaviour similar to classic Wx::FlexGridSizer class.
Instance Attribute Summary
Attributes inherited from GridShape
Instance Method Summary collapse
-
#do_children_layout ⇒ Object
protected
Do layout of assigned child shapes.
- #find_cell(child_rect) ⇒ Object protected
- #get_max_child_sizes ⇒ Object protected
-
#initialize(pos = Shape::DEFAULT::POSITION, size = RectShape::DEFAULT::SIZE, cols: DEFAULT::COLUMNS, max_rows: 0, cell_space: DEFAULT::CELLSPACE, diagram: nil) ⇒ FlexGridShape
constructor
Constructor.
Methods inherited from GridShape
#append_to_grid, #clear_cell, #clear_grid, #each_cell, #fit_to_children, #get_cell_count, #get_cell_space, #get_dimensions, #get_managed_shape, #get_max_child_size, get_min_size, #insert_to_grid, #on_child_dropped, #on_import, #position_child_cell, #remove_from_grid, #set_cell_space, #set_dimensions, #set_max_rows, set_min_size, #update, #update_rows
Methods included from ManagerShape
#do_alignment, #fit_shape_to_rect, #is_manager
Methods inherited from RectShape
#create_handles, #do_begin_handle, #do_on_handle, #draw_highlighted, #draw_hover, #draw_normal, #draw_shadow, #fit_to_children, #get_border, #get_border_point, #get_bounding_box, #get_fill, #get_rect_size, #on_begin_handle, #on_bottom_handle, #on_handle, #on_left_handle, #on_right_handle, #on_top_handle, #scale, #scale_rectangle, #set_border, #set_fill, #set_rect_size
Methods inherited from Shape
#accept_child, #accept_connection, #accept_currently_dragged_shapes, #accept_src_neighbour, #accept_trg_neighbour, #activate, #active?, #add_child_shape, #add_connection_point, #add_handle, #add_style, #ancestor?, #clear_accepted_childs, #clear_accepted_connections, #clear_accepted_src_neighbours, #clear_accepted_trg_neighbours, component, component_shapes, #contains?, #contains_style, #create_handles, #descendant?, #do_alignment, #does_not_accept_children?, #draw, #draw_highlighted, #draw_hover, #draw_normal, #draw_selected, #draw_shadow, #fit_to_children, #get_absolute_position, #get_accepted_children, #get_accepted_connections, #get_accepted_src_neighbours, #get_accepted_trg_neighbours, #get_assigned_connections, #get_border_point, #get_bounding_box, #get_center, #get_child_shapes, #get_children, #get_children_recursively, #get_complete_bounding_box, #get_connection_point, #get_connection_points, #get_custom_dock_point, #get_diagram, #get_grand_parent_shape, #get_h_align, #get_h_border, #get_handle, #get_handles, #get_hover_colour, #get_nearest_connection_point, #get_neighbours, #get_parent_absolute_position, #get_parent_canvas, #get_parent_shape, #get_relative_position, #get_shape_canvas, #get_style, #get_user_data, #get_v_align, #get_v_border, #has_children, #has_selected_parent?, #include_child_shape?, #inside?, #inspect, #intersects?, #is_child_accepted, #is_connection_accepted, #is_managed, #is_manager, #is_src_neighbour_accepted, #is_trg_neighbour_accepted, lines_intersection, #lines_intersection, #move_by, #move_to, #on_begin_drag, #on_begin_handle, #on_child_dropped, #on_dragging, #on_end_drag, #on_end_handle, #on_handle, #on_import, #on_key, #on_left_click, #on_left_double_click, #on_mouse_enter, #on_mouse_leave, #on_mouse_over, #on_right_click, #on_right_double_click, #refresh, #refresh_rect, #remove_connection_point, #remove_handle, #remove_style, #scale, #scale_children, #select, #selected?, #set_custom_dock_point, #set_diagram, #set_h_align, #set_h_border, #set_hover_colour, #set_parent_shape, #set_relative_position, #set_style, #set_user_data, #set_v_align, #set_v_border, #show, #show_handles, #to_s, #update, #visible?
Constructor Details
#initialize(pos = Shape::DEFAULT::POSITION, size = RectShape::DEFAULT::SIZE, cols: DEFAULT::COLUMNS, max_rows: 0, cell_space: DEFAULT::CELLSPACE, diagram: nil) ⇒ FlexGridShape
Constructor.
21 22 23 24 |
# File 'lib/wx/shapes/shapes/flex_grid_shape.rb', line 21 def initialize(pos = Shape::DEFAULT::POSITION, size = RectShape::DEFAULT::SIZE, cols: DEFAULT::COLUMNS, max_rows: 0, cell_space: DEFAULT::CELLSPACE, diagram: nil) super end |
Instance Method Details
#do_children_layout ⇒ Object (protected)
Do layout of assigned child shapes
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/wx/shapes/shapes/flex_grid_shape.rb', line 29 def do_children_layout return if @cols == 0 || @rows == 0 # get maximum size of all managed (child) shapes per row and column row_sizes, col_sizes = get_max_child_sizes total_x = total_y = 0 # put managed shapes to appropriate positions @cells.each_with_index do |shape, i| col = (i % @cols) row = (i / @cols) if col == 0 total_x = 0 total_y += row_sizes[row-1] if row > 0 else total_x += col_sizes[col-1] end if shape fit_shape_to_rect(shape, Wx::Rect.new(total_x + (col+1)*@cell_space, total_y + (row+1)*@cell_space, col_sizes[col], row_sizes[row])) end end end |
#find_cell(child_rect) ⇒ Object (protected)
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/wx/shapes/shapes/flex_grid_shape.rb', line 77 def find_cell(child_rect) # get maximum size of all managed (child) shapes per row and column row_sizes, col_sizes = get_max_child_sizes total_x = total_y = 0 # find the cell index where the new or dragged child is positioned above and in front of offset = get_bounding_box.top_left cell_count.times.find do |cell| col = (cell % @cols) row = (cell / @cols) if col == 0 total_x = 0 total_y += row_sizes[row-1] if row > 0 else total_x += col_sizes[col-1] end cell_rct = Wx::Rect.new(total_x + (col+1)*@cell_space, total_y + (row+1)*@cell_space, col_sizes[col], row_sizes[row]).offset!(offset) child_rect.right <= cell_rct.right && child_rect.bottom <= cell_rct.bottom end end |
#get_max_child_sizes ⇒ Object (protected)
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/wx/shapes/shapes/flex_grid_shape.rb', line 56 def get_max_child_sizes # initialize size arrays row_sizes = ::Array.new(@rows, 0) col_sizes = ::Array.new(@cols, 0) # get maximum size of all managed (child) shapes per row and column @cells.each_with_index do |shape, i| if shape col = (i % @cols) row = (i / @cols) curr_rect = shape.get_bounding_box # update maximum rows and columns sizes col_sizes[col] = curr_rect.width if (shape.get_h_align != HALIGN::EXPAND) && (curr_rect.width > col_sizes[col]) row_sizes[row] = curr_rect.height if (shape.get_v_align != VALIGN::EXPAND) && (curr_rect.height > row_sizes[row]) end end [row_sizes, col_sizes] end |