class TkComponent::Builder::GridMap
Public Class Methods
new()
click to toggle source
# File lib/tk_component/builder/grid_map.rb, line 4 def initialize @rows = [] @row_weights = [] @column_weights = [] end
Public Instance Methods
column_indexes()
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# File lib/tk_component/builder/grid_map.rb, line 44 def row_indexes used_indexes(@rows) end
row_weight(row)
click to toggle source
# File lib/tk_component/builder/grid_map.rb, line 29 def row_weight(row) @row_weights[row] || 0 end
set(row, col, val)
click to toggle source
# 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 = {})
click to toggle source
# 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()
click to toggle source
# File lib/tk_component/builder/grid_map.rb, line 61 def to_s @rows.to_s end
Private Instance Methods
used_indexes(array)
click to toggle source
# File lib/tk_component/builder/grid_map.rb, line 67 def used_indexes(array) return [] if array.nil? array.map.with_index { |o, i| o.present? ? i : nil }.compact end