class RETerm::Layout

Provides mechanism to orgranize on screen components according to rules defined by subclasses.

Layouts themselves are specialized types of components as they are intended to be associated with windows in which to be rendered

Attributes

expand[RW]

Flag indicating if layout should expand to be able to contain childen (if false error will be throw if trying to add child to layout that cannot contain it)

Public Instance Methods

activatable?() click to toggle source

Return boolean indicating if any child component is activatable

# File lib/reterm/layout.rb, line 97
def activatable?
  return false if empty?
  children.any? { |c| c.activatable? }
end
activate!(*input) click to toggle source

Activates layout by dispatching to navigation input system.

@see NavInput

# File lib/reterm/layout.rb, line 190
def activate!(*input)
  reactivate!

  draw!
  update_reterm
  handle_input(*input)
  deactivate!
end
add_child(h={}) click to toggle source

Create new child window and add it to layout

# File lib/reterm/layout.rb, line 107
def add_child(h={})
  c = nil

  if h.key?(:component)
    c = h[:component]

    h = {:rows => c.requested_rows + c.extra_padding,
         :cols => c.requested_cols + c.extra_padding}.merge(h)
  end

  raise ArgumentError, "must specify x/y" unless h.key?(:x) &&
                                                 h.key?(:y)

  raise ArgumentError, "must specify rows/cols" unless h.key?(:rows) &&
                                                       h.key?(:cols)

  h[:rows], h[:cols] = *Window.adjust_proportional(window, h[:rows], h[:cols])
  h[:x],    h[:y]    = *Window.align(window, h[:x], h[:y], h[:rows], h[:cols])
  h[:rows], h[:cols] = *Window.fill_parent(parent? ? parent.window : Terminal,
                                           h[:x], h[:y],
                                           h[:rows], h[:cols]) if h[:fill]

  if exceeds_bounds_with?(h)
    if expandable? # ... && can_expand_to?(h)
      expand(h)

    else
      raise ArgumentError, "child exceeds bounds"

    end
  end

  child = window.create_child(h)

  # TODO need to reverse expansion if operation fails at any
  # point on, or verify expandable before create_child but
  # do not expand until after

  if child.win.nil?
    raise ArgumentError, "could not create child window"
  end

  if exceeds_bounds?
    window.del_child(child) unless child.win.nil?
    raise ArgumentError, "child exceeds bounds"
  end

  child.component = c unless c.nil?

  update_reterm
  child
end
child_windows() click to toggle source
# File lib/reterm/layout.rb, line 30
def child_windows
  window.children
end
children() click to toggle source
# File lib/reterm/layout.rb, line 21
def children
  window.children.collect { |w| w.component }
end
contains?(child) click to toggle source

Return boolean indicating if layout contains specified child

# File lib/reterm/layout.rb, line 89
def contains?(child)
  children.any? { |c|
    (c.kind_of?(Layout) && c.contains?(child)) || c == child
  }
end
current_cols() click to toggle source

Subclasses should override this method returning current cols in layout

# File lib/reterm/layout.rb, line 52
def current_cols
  raise "NotImplemented"
end
current_rows() click to toggle source

Subclasses should override this method returning current rows in layout

# File lib/reterm/layout.rb, line 46
def current_rows
  raise "NotImplemented"
end
draw!() click to toggle source

Draw all layout children

# File lib/reterm/layout.rb, line 181
def draw!
  children.each { |c| c.draw! }
  draw_focus!
end
empty?() click to toggle source
# File lib/reterm/layout.rb, line 25
def empty?
  return true if window.nil?
  window.children.empty?
end
exceeds_bounds?() click to toggle source

Returns boolean indicating if current layout exceeds bounds of window

# File lib/reterm/layout.rb, line 65
def exceeds_bounds?
  current_cols > window.cols ||
  current_rows > window.rows
end
exceeds_bounds_with?(child) click to toggle source

Subclasses should overrid this method returning boolean indicating if boundries will be exceeded when child is added

# File lib/reterm/layout.rb, line 59
def exceeds_bounds_with?(child)
  raise "NotImplemented"
end
expandable?() click to toggle source
# File lib/reterm/layout.rb, line 16
def expandable?
  (!defined?(@expand) || !!@expand) &&
  (!parent? || parent.expandable?)
end
highlight_focus?() click to toggle source
# File lib/reterm/layout.rb, line 102
def highlight_focus?
  false
end
layout_containing(component) click to toggle source

Return layout containing component If coordinates are contained in a child in current layout

# File lib/reterm/layout.rb, line 73
def layout_containing(component)
  return self if children.include?(component)

  found = nil
  children.each { |c|
    next if found

    if c.kind_of?(Layout)
      found = c unless c.layout_containing(component).nil?
    end
  }

  found
end
parent() click to toggle source
# File lib/reterm/layout.rb, line 38
def parent
  window.parent.component
end
parent?() click to toggle source
# File lib/reterm/layout.rb, line 34
def parent?
  window.parent?
end