class Cura::FocusController

Public Class Methods

new(attributes={}) click to toggle source
Calls superclass method Cura::Attributes::HasAttributes::new
# File lib/cura/focus_controller.rb, line 13
def initialize(attributes={})
  @index = 0

  super

  # TODO: raise error if window or application is nil
end

Protected Instance Methods

focusable_children_of(component) click to toggle source

Recursively find all children which are focusable.

# File lib/cura/focus_controller.rb, line 74
def focusable_children_of(component)
  result = []

  component.children.each do |child|
    result << child if child.focusable?
    result << focusable_children_of(child) if child.respond_to?(:children)
  end

  result.flatten
end
set_index(value) click to toggle source
# File lib/cura/focus_controller.rb, line 56
def set_index(value)
  index = value.to_i
  focusable_children = focusable_children_of(@window.root)
  index %= focusable_children.length

  @window.application.dispatcher.target = focusable_children[index]

  index
end
validate_window(window) click to toggle source
# File lib/cura/focus_controller.rb, line 50
def validate_window(window)
  raise TypeError, "must be a Cura::Window" unless window.is_a?(Window)

  window
end