Module: Tuile::Component::HasContent

Included in:
Popup, Window
Defined in:
lib/tuile/component/has_content.rb

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

Instance Method Summary collapse

Instance Attribute Details

#contentComponent?

Returns the current content component.

Returns:

  • (Component, nil)

    the current content component.



10
11
12
# File 'lib/tuile/component/has_content.rb', line 10

def content
  @content
end

Instance Method Details

#childrenArray<Component>

Returns:



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.

Parameters:

  • key (String)

    a key.

Returns:

  • (Boolean)

    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.

Parameters:



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_focusvoid

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.

Parameters:



55
56
57
58
# File 'lib/tuile/component/has_content.rb', line 55

def rect=(rect)
  super
  layout(content) unless content.nil?
end