Class: TkComponent::Builder::GridMap

Inherits:
Object
  • Object
show all
Defined in:
lib/tk_component/builder/grid_map.rb

Instance Method Summary collapse

Constructor Details

#initializeGridMap

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_indexesObject



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_indexesObject



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_sObject



61
62
63
# File 'lib/tk_component/builder/grid_map.rb', line 61

def to_s
  @rows.to_s
end