Class: TkWrapper::Widgets::Grid
- Inherits:
-
Base::Widget
- Object
- Base::Widget
- TkWrapper::Widgets::Grid
- Defined in:
- lib/widgets/grid.rb
Overview
classification of TkGrid
Constant Summary collapse
- Widget =
TkWrapper::Widgets::Base::Widget
Instance Attribute Summary collapse
-
#matrix ⇒ Object
readonly
Returns the value of attribute matrix.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Attributes inherited from Base::Widget
#cell, #childs, #config, #font, #ids, #manager, #opts, #winfo
Instance Method Summary collapse
- #configure_cells_for_grid ⇒ Object
- #configure_colspan(cell, row_i, col_i) ⇒ Object
- #configure_rowspan(cell, row_i, col_i) ⇒ Object
-
#initialize(**arguments) ⇒ Grid
constructor
A new instance of Grid.
- #tk_class ⇒ Object
Methods inherited from Base::Widget
#create_tk_widget, #each, #init_id, #initialize_utilities, #normalize_childs, #push, #tk_widget
Constructor Details
#initialize(**arguments) ⇒ Grid
Returns a new instance of Grid.
15 16 17 18 19 20 21 22 |
# File 'lib/widgets/grid.rb', line 15 def initialize(**arguments) parent = arguments.delete(:parent) super(**arguments) @childs.map! { |row| row.is_a?(Array) ? row : [row] } configure_cells_for_grid @childs.flatten! && @childs.select! { |cell| cell.is_a?(Widget) } parent&.push(self) end |
Instance Attribute Details
#matrix ⇒ Object (readonly)
Returns the value of attribute matrix.
7 8 9 |
# File 'lib/widgets/grid.rb', line 7 def matrix @matrix end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
7 8 9 |
# File 'lib/widgets/grid.rb', line 7 def parent @parent end |
Instance Method Details
#configure_cells_for_grid ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/widgets/grid.rb', line 24 def configure_cells_for_grid @childs.each_with_index do |row, row_i| row.each_with_index do |cell, col_i| next unless cell.is_a?(Widget) cell.config.merge({ grid: { row: row_i, column: col_i } }) configure_colspan(cell, row_i, col_i) configure_rowspan(cell, row_i, col_i) end end end |
#configure_colspan(cell, row_i, col_i) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/widgets/grid.rb', line 37 def configure_colspan(cell, row_i, col_i) cols_after_cell = @childs[row_i][(col_i + 1)..] colspan = cols_after_cell.reduce(1) do |span, content| content == :right ? span + 1 : (break span) end cell.config.merge({ grid: { columnspan: colspan } }) end |
#configure_rowspan(cell, row_i, col_i) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/widgets/grid.rb', line 45 def configure_rowspan(cell, row_i, col_i) rows_after_cell = @childs[(row_i + 1)..] rowspan = rows_after_cell.reduce(1) do |span, row| row[col_i] == :bottom ? span + 1 : (break span) end cell.config.merge({ grid: { rowspan: rowspan } }) end |
#tk_class ⇒ Object
11 12 13 |
# File 'lib/widgets/grid.rb', line 11 def tk_class Tk::Tile::Frame end |