Class: RETerm::Layouts::Grid
- Inherits:
-
RETerm::Layout
- Object
- Component
- RETerm::Layout
- RETerm::Layouts::Grid
- Defined in:
- lib/reterm/layouts/grid.rb
Overview
Layout which permits the user to arrainge items anywhere on screen
Constant Summary
Constants included from NavControls
NavControls::DOWN_CONTROLS, NavControls::ENTER_CONTROLS, NavControls::LEFT_CONTROLS, NavControls::MOVEMENT_CONTROLS, NavControls::QUIT_CONTROLS, NavControls::RIGHT_CONTROLS, NavControls::UP_CONTROLS
Constants included from MouseInput
MouseInput::ALL_EVENTS, MouseInput::MOUSE_MAP
Constants included from RETerm::LogHelpers
Instance Attribute Summary
Attributes inherited from RETerm::Layout
Attributes included from NavInput
Attributes inherited from Component
#activatable, #activate_focus, #highlight_focus, #window
Instance Method Summary collapse
- #current_cols ⇒ Object
- #current_rows ⇒ Object
- #exceeds_bounds_with?(child) ⇒ Boolean
-
#next_focus(ch) ⇒ Object
Cycle through components child position on grid.
- #valid_input?(ch, from_parent) ⇒ Boolean
Methods inherited from RETerm::Layout
#activatable?, #activate!, #add_child, #child_windows, #children, #contains?, #draw!, #empty?, #exceeds_bounds?, #expandable?, #highlight_focus?, #layout_containing, #parent, #parent?
Methods included from NavInput
#focusable, #focusable?, #handle_input
Methods included from NavControls
Methods included from MouseInput
#mouse_paste?, #on_button, #process_mouse
Methods inherited from Component
#activatable?, #activate!, #activate_focus?, #cdk?, #colored?, #colors=, #deactivate!, #deactivate?, #distance_from, #extra_padding, #finalize!, #highlight_focus?, #initialize, #reactivate!, #requested_cols, #requested_rows, #resize, #sync!, #sync_getch
Methods included from KeyBindings
#bind_key, #invoke_key_bindings, #key_bindings, #key_bound?
Methods included from RETerm::LogHelpers
Methods included from EventDispatcher
Constructor Details
This class inherits a constructor from RETerm::Component
Instance Method Details
#current_cols ⇒ Object
10 11 12 13 |
# 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 ⇒ Object
5 6 7 8 |
# 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) ⇒ Boolean
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# 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) ⇒ Object
Cycle through components child position on grid
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# 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) ⇒ Boolean
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# 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 |