Module: RETerm::NavInput
Overview
Helper mixin defining standard navigation controls. Used by layouts and top level components this tightly defines keyboard navigation and allows the user to seemlessly move between and activate/decativate components.
Constant Summary
Constants included from NavControls
RETerm::NavControls::DOWN_CONTROLS, RETerm::NavControls::ENTER_CONTROLS, RETerm::NavControls::LEFT_CONTROLS, RETerm::NavControls::MOVEMENT_CONTROLS, RETerm::NavControls::QUIT_CONTROLS, RETerm::NavControls::RIGHT_CONTROLS, RETerm::NavControls::UP_CONTROLS
Constants included from MouseInput
MouseInput::ALL_EVENTS, MouseInput::MOUSE_MAP
Instance Attribute Summary collapse
-
#ch_select ⇒ Object
Used internally to specify which movement command we should follow.
-
#nav_select ⇒ Object
Used internally to specify component which we should navigate to.
Instance Method Summary collapse
-
#focusable ⇒ Object
Return children which are focusabled/activable.
-
#focusable? ⇒ Boolean
Return boolean indicating if any children are focusable.
-
#handle_input(from_parent = false) ⇒ Object
Helper to be internally invoked by navigation component on activation.
-
#valid_input?(ch, from_parent) ⇒ Boolean
May be overridden by subclass to indicate if the specified input / context is valid.
Methods included from NavControls
Methods included from MouseInput
#mouse_paste?, #on_button, #process_mouse
Instance Attribute Details
#ch_select ⇒ Object
Used internally to specify which movement command we should follow
17 18 19 |
# File 'lib/reterm/mixins/nav_input.rb', line 17 def ch_select @ch_select end |
#nav_select ⇒ Object
Used internally to specify component which we should navigate to
13 14 15 |
# File 'lib/reterm/mixins/nav_input.rb', line 13 def nav_select @nav_select end |
Instance Method Details
#focusable ⇒ Object
Return children which are focusabled/activable
20 21 22 |
# File 'lib/reterm/mixins/nav_input.rb', line 20 def focusable children.select { |c| c.activatable? } end |
#focusable? ⇒ Boolean
Return boolean indicating if any children are focusable
25 26 27 |
# File 'lib/reterm/mixins/nav_input.rb', line 25 def focusable? !focusable.empty? end |
#handle_input(from_parent = false) ⇒ Object
Helper to be internally invoked by navigation component on activation
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/reterm/mixins/nav_input.rb', line 37 def handle_input(from_parent=false) @focus ||= 0 # focus on first component ch = handle_focused unless nav_select # Repeat until quit until quit_nav?(ch) # Navigate to the specified component (nav_select) if self.nav_select # it is a descendent of this one if self.contains?(self.nav_select) nav_to_selected # specified component is not a descendent, else nav_to_parent return nil end elsif ENTER_CONTROLS.include?(ch) focused.activate! elsif MOVEMENT_CONTROLS.include?(ch) handle_movement(ch, from_parent) elsif mev = process_mouse(ch) handle_mouse(mev) else dispatch(:entry, ch) end return ch unless sanitize_focus!(from_parent) ch = handle_focused unless nav_select || shutdown? || deactivate? end ch end |
#valid_input?(ch, from_parent) ⇒ Boolean
May be overridden by subclass to indicate if the specified input / context is valid
31 32 33 |
# File 'lib/reterm/mixins/nav_input.rb', line 31 def valid_input?(ch, from_parent) true end |