Class: Potty::Widgets::Base
- Inherits:
-
Object
- Object
- Potty::Widgets::Base
- Includes:
- Events
- Defined in:
- lib/potty/widgets/base.rb
Overview
Base class for all widgets
Direct Known Subclasses
Animator, Button, CheckboxGroup, Container, Countdown, FlashMessage, Label, List, RadioGroup, Spinner, StatusBar, TextInput, Toggle
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#focused ⇒ Object
Returns the value of attribute focused.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#rect ⇒ Object
Returns the value of attribute rect.
Instance Method Summary collapse
-
#activate ⇒ Object
Lifecycle.
- #blur ⇒ Object
-
#can_focus? ⇒ Boolean
Focus.
- #deactivate ⇒ Object
- #focus ⇒ Object
- #handle_escape ⇒ Object
-
#handle_key(ch) ⇒ Object
Input.
- #hide ⇒ Object
-
#initialize(app) ⇒ Base
constructor
A new instance of Base.
- #layout(rect) ⇒ Object
- #on_blur ⇒ Object
- #on_focus ⇒ Object
- #on_layout ⇒ Object
-
#preferred_height(width) ⇒ Object
Layout.
-
#render(window) ⇒ Object
Rendering.
- #show ⇒ Object
-
#theme ⇒ Object
Helpers.
-
#tick(now) ⇒ Object
Time-based update hook.
- #visible=(flag) ⇒ Object
-
#visible? ⇒ Boolean
Visibility.
Methods included from Events
#emit, #listeners?, #off, #on
Constructor Details
#initialize(app) ⇒ Base
Returns a new instance of Base.
14 15 16 17 18 19 20 |
# File 'lib/potty/widgets/base.rb', line 14 def initialize(app) @app = app @rect = nil @parent = nil @focused = false @visible = true end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
12 13 14 |
# File 'lib/potty/widgets/base.rb', line 12 def app @app end |
#focused ⇒ Object
Returns the value of attribute focused.
11 12 13 |
# File 'lib/potty/widgets/base.rb', line 11 def focused @focused end |
#parent ⇒ Object
Returns the value of attribute parent.
11 12 13 |
# File 'lib/potty/widgets/base.rb', line 11 def parent @parent end |
#rect ⇒ Object
Returns the value of attribute rect.
11 12 13 |
# File 'lib/potty/widgets/base.rb', line 11 def rect @rect end |
Instance Method Details
#activate ⇒ Object
Lifecycle
23 24 25 |
# File 'lib/potty/widgets/base.rb', line 23 def activate # Override in subclasses end |
#blur ⇒ Object
80 81 82 83 84 |
# File 'lib/potty/widgets/base.rb', line 80 def blur @focused = false on_blur emit(:blur, self) end |
#can_focus? ⇒ Boolean
Focus
70 71 72 |
# File 'lib/potty/widgets/base.rb', line 70 def can_focus? false # Override in interactive widgets end |
#deactivate ⇒ Object
27 28 29 |
# File 'lib/potty/widgets/base.rb', line 27 def deactivate # Override in subclasses end |
#focus ⇒ Object
74 75 76 77 78 |
# File 'lib/potty/widgets/base.rb', line 74 def focus @focused = true on_focus emit(:focus, self) end |
#handle_escape ⇒ Object
65 66 67 |
# File 'lib/potty/widgets/base.rb', line 65 def handle_escape false # Return true if handled end |
#handle_key(ch) ⇒ Object
Input
61 62 63 |
# File 'lib/potty/widgets/base.rb', line 61 def handle_key(ch) false # Return true if handled end |
#hide ⇒ Object
99 100 101 102 |
# File 'lib/potty/widgets/base.rb', line 99 def hide @visible = false self end |
#layout(rect) ⇒ Object
36 37 38 39 |
# File 'lib/potty/widgets/base.rb', line 36 def layout(rect) @rect = rect on_layout end |
#on_blur ⇒ Object
87 |
# File 'lib/potty/widgets/base.rb', line 87 def on_blur; end |
#on_focus ⇒ Object
86 |
# File 'lib/potty/widgets/base.rb', line 86 def on_focus; end |
#on_layout ⇒ Object
41 42 43 |
# File 'lib/potty/widgets/base.rb', line 41 def on_layout # Override for custom layout logic end |
#preferred_height(width) ⇒ Object
Layout
32 33 34 |
# File 'lib/potty/widgets/base.rb', line 32 def preferred_height(width) 1 # Default to single line end |
#render(window) ⇒ Object
Rendering
46 47 48 49 |
# File 'lib/potty/widgets/base.rb', line 46 def render(window) return unless @visible && @rect # Override in subclasses end |
#show ⇒ Object
94 95 96 97 |
# File 'lib/potty/widgets/base.rb', line 94 def show @visible = true self end |
#theme ⇒ Object
Helpers
109 110 111 |
# File 'lib/potty/widgets/base.rb', line 109 def theme @app.theme end |
#tick(now) ⇒ Object
Time-based update hook. Called once per event-loop frame when the Application has a tick_interval set. ‘now` is a single Time read shared across all widgets in the frame (so playback stays in sync and is deterministic to unit-test). Override in time-driven widgets such as Animator and Countdown.
56 57 58 |
# File 'lib/potty/widgets/base.rb', line 56 def tick(now) # Override in time-driven subclasses end |
#visible=(flag) ⇒ Object
104 105 106 |
# File 'lib/potty/widgets/base.rb', line 104 def visible=(flag) flag ? show : hide end |
#visible? ⇒ Boolean
Visibility
90 91 92 |
# File 'lib/potty/widgets/base.rb', line 90 def visible? @visible end |