Class: RETerm::Layouts::Horizontal

Inherits:
RETerm::Layout show all
Defined in:
lib/reterm/layouts/horizontal.rb

Overview

Layout which arainges items horizontally across screen cols

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

RETerm::LogHelpers::LOG_FILE

Instance Attribute Summary

Attributes inherited from RETerm::Layout

#expand

Attributes included from NavInput

#ch_select, #nav_select

Attributes inherited from Component

#activatable, #activate_focus, #highlight_focus, #window

Instance Method Summary collapse

Methods inherited from RETerm::Layout

#activatable?, #activate!, #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

#quit_nav?

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

#logger

Methods included from EventDispatcher

#dispatch, #handle

Constructor Details

This class inherits a constructor from RETerm::Component

Instance Method Details

#add_child(h = {}) ⇒ Object



28
29
30
31
# File 'lib/reterm/layouts/horizontal.rb', line 28

def add_child(h={})
  # set x/y to next appropriate location
  super(h.merge(:y => 1, :x => current_cols))
end

#current_colsObject



10
11
12
13
# File 'lib/reterm/layouts/horizontal.rb', line 10

def current_cols
  return 1 if empty?
  child_windows.sum { |c| c.cols } + 1
end

#current_rowsObject



5
6
7
8
# File 'lib/reterm/layouts/horizontal.rb', line 5

def current_rows
  return 1 if empty?
  child_windows.max { |w1, w2| w1.rows <=> w2.rows }.rows
end

#exceeds_bounds_with?(child) ⇒ Boolean



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/reterm/layouts/horizontal.rb', line 15

def exceeds_bounds_with?(child)
  rows = child.is_a?(Hash) ?
         [current_rows, child[:rows]].compact.max :
         [current_rows, child.rows].max

  cols = child.is_a?(Hash) ?
    current_cols + child[:cols] :
    current_cols + child.cols

  rows > window.rows ||
  cols > window.cols
end

#valid_input?(ch, from_parent) ⇒ Boolean



33
34
35
36
37
# File 'lib/reterm/layouts/horizontal.rb', line 33

def valid_input?(ch, from_parent)
  return true unless from_parent
  !((UP_CONTROLS.include?(ch)   && window.first_child?) ||
    (DOWN_CONTROLS.include?(ch) && window.last_child?))
end