Class: TkComponent::Builder::GridMap
- Inherits:
-
Object
- Object
- TkComponent::Builder::GridMap
- Defined in:
- lib/tk_component/builder/grid_map.rb
Instance Method Summary collapse
- #column_indexes ⇒ Object
- #column_weight(col) ⇒ Object
- #fill(row, col, rowspan, columnspan, val) ⇒ Object
- #get(row, col) ⇒ Object
- #get_next_cell(current_row, current_col, going_down) ⇒ Object
-
#initialize ⇒ GridMap
constructor
A new instance of GridMap.
- #row_indexes ⇒ Object
- #row_weight(row) ⇒ Object
- #set(row, col, val) ⇒ Object
- #set_weights(row, col, weights = {}) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ GridMap
Returns a new instance of GridMap.
4 5 6 7 8 |
# File 'lib/tk_component/builder/grid_map.rb', line 4 def initialize @rows = [] @row_weights = [] @column_weights = [] end |
Instance Method Details
#column_indexes ⇒ Object
48 49 50 |
# File 'lib/tk_component/builder/grid_map.rb', line 48 def column_indexes @rows.reduce([]) { |accum, r| accum += used_indexes(r) }.uniq end |
#column_weight(col) ⇒ Object
33 34 35 |
# File 'lib/tk_component/builder/grid_map.rb', line 33 def column_weight(col) @column_weights[col] || 0 end |
#fill(row, col, rowspan, columnspan, val) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/tk_component/builder/grid_map.rb', line 21 def fill(row, col, rowspan, columnspan, val) for r in (row .. row + rowspan - 1) do for c in (col .. col + columnspan - 1) do set(r, c, val) end end end |
#get(row, col) ⇒ Object
10 11 12 13 14 |
# File 'lib/tk_component/builder/grid_map.rb', line 10 def get(row, col) return nil if row >= @rows.size return nil if (cols = @rows[row]).nil? || col >= cols.size cols[col] end |
#get_next_cell(current_row, current_col, going_down) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/tk_component/builder/grid_map.rb', line 52 def get_next_cell(current_row, current_col, going_down) if going_down while get(current_row, current_col) do current_row += 1 end else while get(current_row, current_col) do current_col += 1 end end [current_row, current_col] end |
#row_indexes ⇒ Object
44 45 46 |
# File 'lib/tk_component/builder/grid_map.rb', line 44 def row_indexes used_indexes(@rows) end |
#row_weight(row) ⇒ Object
29 30 31 |
# File 'lib/tk_component/builder/grid_map.rb', line 29 def row_weight(row) @row_weights[row] || 0 end |
#set(row, col, val) ⇒ Object
16 17 18 19 |
# File 'lib/tk_component/builder/grid_map.rb', line 16 def set(row, col, val) @rows[row] = [] if row > @rows.size || @rows[row].nil? @rows[row][col] = val end |
#set_weights(row, col, weights = {}) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/tk_component/builder/grid_map.rb', line 37 def set_weights(row, col, weights = {}) vw = weights[:y_flex] @row_weights[row] = ((rw = @row_weights[row]).present? ? [rw, vw].max : vw) if vw hw = weights[:x_flex] @column_weights[col] = ((cw = @column_weights[col]).present? ? [cw, hw].max : hw) if hw end |
#to_s ⇒ Object
61 62 63 |
# File 'lib/tk_component/builder/grid_map.rb', line 61 def to_s @rows.to_s end |