class RETerm::Layouts::Grid

Layout which permits the user to arrainge items anywhere on screen

Public Instance Methods

current_cols() click to toggle source
# File lib/reterm/layouts/grid.rb, line 10
def current_cols
  return 1 if empty?
  child_windows.max { |c1, c2| c1.cols <=> c2.cols }.cols + 1
end
current_rows() click to toggle source
# File lib/reterm/layouts/grid.rb, line 5
def current_rows
  return 1 if empty?
  child_windows.max { |c1, c2| c1.rows <=> c2.rows }.rows + 1
end
exceeds_bounds_with?(child) click to toggle source
# File lib/reterm/layouts/grid.rb, line 15
def exceeds_bounds_with?(child)
  x1 = child.is_a?(Hash) ? child[:x] : child.x
  y1 = child.is_a?(Hash) ? child[:y] : child.y

  x2 = child.is_a?(Hash) ?
        [current_cols, x1 + child[:cols]].compact.max :
        [current_cols, x1 + child.cols].max

  y2 = child.is_a?(Hash) ?
         [current_rows, y1 + child[:rows]].compact.max :
         [current_rows, y1 + child.rows].max

  x1 < window.x    || y1 < window.y ||
  x2 > window.cols || y2 > window.rows
end
next_focus(ch) click to toggle source

Cycle through components child position on grid

Calls superclass method RETerm::NavInput#next_focus
# File lib/reterm/layouts/grid.rb, line 47
def next_focus(ch)
  f = nil
  if     UP_CONTROLS.include?(ch)
    f = focusable.select { |f| f.window.y < focused.window.y }

  elsif  DOWN_CONTROLS.include?(ch)
    f = focusable.select { |f| f.window.y > focused.window.y }

  elsif  LEFT_CONTROLS.include?(ch)
    f = focusable.select { |f| f.window.x < focused.window.x }

  elsif RIGHT_CONTROLS.include?(ch)
    f = focusable.select { |f| f.window.x > focused.window.x }

  else
    return super
  end

  f.sort! { |a, b| focused.distance_from(a) <=> focused.distance_from(b) }

  focusable.index(f.first)
end
valid_input?(ch, from_parent) click to toggle source
# File lib/reterm/layouts/grid.rb, line 31
def valid_input?(ch, from_parent)
  if     UP_CONTROLS.include?(ch)
    return focusable.any? { |f| f.window.y < focused.window.y }

  elsif  DOWN_CONTROLS.include?(ch)
    return focusable.any? { |f| f.window.y > focused.window.y }

  elsif  LEFT_CONTROLS.include?(ch)
    focusable.any? { |f| f.window.x < focused.window.x }

  elsif RIGHT_CONTROLS.include?(ch)
    focusable.any? { |f| f.window.x > focused.window.x }
  end
end