Module: Tuile::Component::HasContent
Overview
A mixin interface for a component with one child tops. The host must provide a protected ‘layout(content)` method which repositions the content component; the mixin manages `@content` itself.
Instance Attribute Summary collapse
-
#content ⇒ Component?
The current content component.
Instance Method Summary collapse
- #children ⇒ Array<Component>
-
#handle_key(key) ⇒ Boolean
True if the key was handled, false if not.
- #handle_mouse(event) ⇒ void
- #on_focus ⇒ void
- #rect=(rect) ⇒ void
Instance Attribute Details
#content ⇒ Component?
Returns the current content component.
10 11 12 |
# File 'lib/tuile/component/has_content.rb', line 10 def content @content end |
Instance Method Details
#children ⇒ Array<Component>
25 |
# File 'lib/tuile/component/has_content.rb', line 25 def children = content.nil? ? [] : [content] |
#handle_key(key) ⇒ Boolean
Returns true if the key was handled, false if not.
14 15 16 |
# File 'lib/tuile/component/has_content.rb', line 14 def handle_key(key) content.nil? || !content.active? ? false : content.handle_key(key) end |
#handle_mouse(event) ⇒ void
This method returns an undefined value.
20 21 22 |
# File 'lib/tuile/component/has_content.rb', line 20 def handle_mouse(event) content.handle_mouse(event) if !content.nil? && content.rect.contains?(event.point) end |
#on_focus ⇒ void
This method returns an undefined value.
61 62 63 64 65 66 |
# File 'lib/tuile/component/has_content.rb', line 61 def on_focus super # Let the content component receive focus, so that it can immediately # start responding to key presses. screen.focused = content if !content.nil? && content.focusable? end |
#rect=(rect) ⇒ void
This method returns an undefined value.
55 56 57 58 |
# File 'lib/tuile/component/has_content.rb', line 55 def rect=(rect) super layout(content) unless content.nil? end |