Class: RETerm::Component
- Inherits:
-
Object
- Object
- RETerm::Component
- Includes:
- EventDispatcher, KeyBindings, LogHelpers
- Defined in:
- lib/reterm/component.rb
Overview
A Component is a generic widget container associated with a window. Subclasses each implement a specific UI artifact.
Direct Known Subclasses
RETerm::Components::AlphaList, RETerm::Components::AsciiText, RETerm::Components::Button, RETerm::Components::ButtonBox, RETerm::Components::Dial, RETerm::Components::Dialog, RETerm::Components::DropDownMenu, RETerm::Components::Entry, RETerm::Components::HSlider, RETerm::Components::Histogram, RETerm::Components::Image, RETerm::Components::Isometric, RETerm::Components::Label, RETerm::Components::Matrix, RETerm::Components::MultiLineEntry, RETerm::Components::Radio, RETerm::Components::RevealingLabel, RETerm::Components::Rocker, RETerm::Components::ScrollList, RETerm::Components::ScrollingArea, RETerm::Components::SelectList, RETerm::Components::Splash, RETerm::Components::Template, RETerm::Components::VSlider, Layout
Constant Summary
Constants included from LogHelpers
Instance Attribute Summary collapse
-
#activatable ⇒ Object
writeonly
Sets the attribute activatable.
-
#activate_focus ⇒ Object
writeonly
Sets the attribute activate_focus.
-
#highlight_focus ⇒ Object
writeonly
Sets the attribute highlight_focus.
-
#window ⇒ Object
Returns the value of attribute window.
Instance Method Summary collapse
-
#activatable? ⇒ Boolean
Returns a boolean indicating if the user should be able to focus on and activate the component.
-
#activate!(*input) ⇒ Object
Actual activation mechanism, invoked by the navigation logic when the user has selected an activatable? component.
- #activate_focus? ⇒ Boolean
-
#cdk? ⇒ Boolean
Overridden by CDK components.
-
#colored? ⇒ Boolean
Return a boolean indicating if a ColorPair has been assign to component.
-
#colors=(c) ⇒ Object
Assign the specified ColorPair to the component.
-
#deactivate! ⇒ Object
This method is invoked when component loses focus (when navigating to another component, window closed, etc).
-
#deactivate? ⇒ Boolean
Flag indicating that this component should be deactivated.
- #distance_from(c) ⇒ Object
-
#extra_padding ⇒ Object
Return extra padding to be given to component.
-
#finalize! ⇒ Object
This method is invoked to cleanup the component on shutdown.
-
#highlight_focus? ⇒ Boolean
Return boolean indicating if this component should be highlighted on focus (default true).
-
#initialize(args = {}) ⇒ Component
constructor
A new instance of Component.
-
#reactivate! ⇒ Object
Reset deactivation.
-
#requested_cols ⇒ Object
This method is invoked when adding component to layout to determine cols needed.
-
#requested_rows ⇒ Object
This method is invoked when adding component to layout to determine rows needed.
-
#resize(rows, cols) ⇒ Object
Dispatch to window.resize.
-
#sync! ⇒ Object
Method to periodically synchronize component if needed.
- #sync_getch ⇒ Object
Methods included from KeyBindings
#bind_key, #invoke_key_bindings, #key_bindings, #key_bound?
Methods included from LogHelpers
Methods included from EventDispatcher
Constructor Details
#initialize(args = {}) ⇒ Component
Returns a new instance of Component.
21 22 23 24 25 26 |
# File 'lib/reterm/component.rb', line 21 def initialize(args={}) self.highlight_focus = args[:highlight_focus] if args.key?(:highlight_focus) self.activate_focus = args[:activate_focus] if args.key?(:activate_focus) self.activatable = args[:activatable] if args.key?(:activatable) init_cdk(args) if cdk? end |
Instance Attribute Details
#activatable=(value) ⇒ Object (writeonly)
Sets the attribute activatable
57 58 59 |
# File 'lib/reterm/component.rb', line 57 def activatable=(value) @activatable = value end |
#activate_focus=(value) ⇒ Object (writeonly)
Sets the attribute activate_focus
101 102 103 |
# File 'lib/reterm/component.rb', line 101 def activate_focus=(value) @activate_focus = value end |
#highlight_focus=(value) ⇒ Object (writeonly)
Sets the attribute highlight_focus
93 94 95 |
# File 'lib/reterm/component.rb', line 93 def highlight_focus=(value) @highlight_focus = value end |
#window ⇒ Object
Returns the value of attribute window.
9 10 11 |
# File 'lib/reterm/component.rb', line 9 def window @window end |
Instance Method Details
#activatable? ⇒ Boolean
Returns a boolean indicating if the user should be able to focus on and activate the component. By default this is false, but interactive components should override and return true.
63 64 65 |
# File 'lib/reterm/component.rb', line 63 def activatable? defined?(@activatable) && @activatable end |
#activate!(*input) ⇒ Object
Actual activation mechanism, invoked by the navigation logic when the user has selected an activatable? component. Should be overriden by interactive subcomponents to process user inpute specific to that component
71 72 73 |
# File 'lib/reterm/component.rb', line 71 def activate!(*input) raise RuntimeError, "should not be activated" end |
#activate_focus? ⇒ Boolean
103 104 105 |
# File 'lib/reterm/component.rb', line 103 def activate_focus? defined?(@activate_focus) && @activate_focus end |
#cdk? ⇒ Boolean
Overridden by CDK components
123 124 125 |
# File 'lib/reterm/component.rb', line 123 def cdk? false end |
#colored? ⇒ Boolean
Return a boolean indicating if a RETerm::ColorPair has been assign to component
48 49 50 |
# File 'lib/reterm/component.rb', line 48 def colored? !!@colors end |
#colors=(c) ⇒ Object
Assign the specified RETerm::ColorPair to the component
53 54 55 |
# File 'lib/reterm/component.rb', line 53 def colors=(c) @colors = c end |
#deactivate! ⇒ Object
This method is invoked when component loses focus (when navigating to another component, window closed, etc). Subclasses may override to hide / cleanup resources
78 79 80 |
# File 'lib/reterm/component.rb', line 78 def deactivate! @deactivate = true end |
#deactivate? ⇒ Boolean
Flag indicating that this component should be deactivated
84 85 86 |
# File 'lib/reterm/component.rb', line 84 def deactivate? !!(@deactivate ||= false) end |
#distance_from(c) ⇒ Object
17 18 19 |
# File 'lib/reterm/component.rb', line 17 def distance_from(c) window.distance_from(c.kind_of?(Window) ? c : c.window) end |
#extra_padding ⇒ Object
Return extra padding to be given to component
108 109 110 |
# File 'lib/reterm/component.rb', line 108 def extra_padding (activatable? && highlight_focus?) ? 3 : 0 end |
#finalize! ⇒ Object
This method is invoked to cleanup the component on shutdown. It should be be overriden by subclasses that needs to clean resources before being deallocated
43 44 |
# File 'lib/reterm/component.rb', line 43 def finalize! end |
#highlight_focus? ⇒ Boolean
Return boolean indicating if this component should be highlighted on focus (default true)
97 98 99 |
# File 'lib/reterm/component.rb', line 97 def highlight_focus? !defined?(@highlight_focus) || @highlight_focus end |
#reactivate! ⇒ Object
Reset deactivation
89 90 91 |
# File 'lib/reterm/component.rb', line 89 def reactivate! @deactivate = false end |
#requested_cols ⇒ Object
This method is invoked when adding component to layout to determine cols needed
36 37 38 |
# File 'lib/reterm/component.rb', line 36 def requested_cols 1 end |
#requested_rows ⇒ Object
This method is invoked when adding component to layout to determine rows needed
30 31 32 |
# File 'lib/reterm/component.rb', line 30 def requested_rows 1 end |
#resize(rows, cols) ⇒ Object
Dispatch to window.resize
117 118 119 120 |
# File 'lib/reterm/component.rb', line 117 def resize(rows, cols) window.resize(rows, cols) self end |
#sync! ⇒ Object
Method to periodically synchronize component if needed
113 114 |
# File 'lib/reterm/component.rb', line 113 def sync! end |
#sync_getch ⇒ Object
127 128 129 130 131 132 |
# File 'lib/reterm/component.rb', line 127 def sync_getch c = window.sync_getch c = nil if key_bound?(c) && invoke_key_bindings(c) c end |