Class: HandyToolbox::Navigator
- Inherits:
-
Object
- Object
- HandyToolbox::Navigator
- Defined in:
- lib/handy_toolbox/navigator.rb
Instance Method Summary collapse
- #current_parent ⇒ Object
- #down(by = 1) ⇒ Object
- #enter(parent) ⇒ Object
- #enter_selected ⇒ Object
- #select_by_index(index) ⇒ Object
- #select_first ⇒ Object
- #select_last ⇒ Object
- #selection ⇒ Object
- #tool ⇒ Object
- #tool_selected? ⇒ Boolean
- #up(by = 1) ⇒ Object
Instance Method Details
#current_parent ⇒ Object
33 34 35 |
# File 'lib/handy_toolbox/navigator.rb', line 33 def current_parent @parent end |
#down(by = 1) ⇒ Object
59 60 61 |
# File 'lib/handy_toolbox/navigator.rb', line 59 def down(by = 1) @current_index = [@current_index + by, @children.size - 1].min end |
#enter(parent) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/handy_toolbox/navigator.rb', line 46 def enter(parent) @parent = parent parent.on_load if parent.is_a?(MenuLoader) @children = parent.children @current_index = 0 selection end |
#enter_selected ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/handy_toolbox/navigator.rb', line 37 def enter_selected old = selection if selection.id == Ids::BACK enter(old.parent) else enter(selection) end end |
#select_by_index(index) ⇒ Object
27 28 29 30 31 |
# File 'lib/handy_toolbox/navigator.rb', line 27 def select_by_index(index) if index >= 0 && index < @children.size @current_index = index end end |
#select_first ⇒ Object
19 20 21 |
# File 'lib/handy_toolbox/navigator.rb', line 19 def select_first select_by_index(0) end |
#select_last ⇒ Object
23 24 25 |
# File 'lib/handy_toolbox/navigator.rb', line 23 def select_last select_by_index(@children.size - 1) end |
#selection ⇒ Object
15 16 17 |
# File 'lib/handy_toolbox/navigator.rb', line 15 def selection @children[@current_index] end |
#tool ⇒ Object
9 10 11 12 13 |
# File 'lib/handy_toolbox/navigator.rb', line 9 def tool if tool_selected? selection.tool end end |
#tool_selected? ⇒ Boolean
5 6 7 |
# File 'lib/handy_toolbox/navigator.rb', line 5 def tool_selected? selection.is_a?(ToolMenuItem) end |
#up(by = 1) ⇒ Object
55 56 57 |
# File 'lib/handy_toolbox/navigator.rb', line 55 def up(by = 1) @current_index = [0, @current_index - by].max end |