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:



19
# File 'lib/tuile/component/has_content.rb', line 19

def children = content.nil? ? [] : [content]

#handle_mouse(event) ⇒ void

This method returns an undefined value.

Parameters:



14
15
16
# File 'lib/tuile/component/has_content.rb', line 14

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.



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

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:



49
50
51
52
# File 'lib/tuile/component/has_content.rb', line 49

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