Module: Tuile::Component::HasContent

Included in:
FormItem, Overlay, Scroller, Slot, Window
Defined in:
lib/tuile/component/has_content.rb,
sig/tuile.rbs

Overview

A component with a primary child named content: this is my content, which you populate; my other children are mine to manage, not yours to address. Include it wherever addressing that child is the point — a Slot is a bare region for one, a Window frames one, an Overlay floats one.

It says nothing about arity: Window has two app-settable children, and this mixin names which of them is the content. Nor about permanence — an Overlay's body is permanent and public both. A container with several populatable regions gives each one a Slot rather than including this twice.

The includer initializes @content to nil and positions the child from its own #relayout; the mixin owns the swap, and the swap marks, so nothing here places anything itself:

class Slot < Component
include Component::HasContent

def initialize = (super; @content = nil)

protected

def relayout = content&.rect = local_rect
end

A child that is private machinery stays out, because #content= ships public and re-checks nothing its owner depends on — swapping in a component of the wrong type succeeds, and breaks the owner at the next call. Such a component owns its child outright instead, with add_child in the constructor and placement from rect=. Both in-tree shapes are worth knowing: AbstractWrappingField hides its editor completely, while CheckboxGroup and RadioGroup expose theirs read-only as list — an app tunes that List, but never supplies it. Populate is the word doing the work here: addressable is not the same as yours.

A tree walk finds content generically through is_a?(HasContent) plus a content compare, which is why this is a mixin rather than a per-class accessor — the same reason HasCaption is one. Under the rule above such a walk reaches only public contents, never a widget's private editor.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#content ⇒ Component?

@return — the current content component.

Returns:



47
48
49
# File 'lib/tuile/component/has_content.rb', line 47

def content
  @content
end

Instance Method Details

#handle_focus ⇒ void

This method returns an undefined value.



78
79
80
81
82
83
84
85
# File 'lib/tuile/component/has_content.rb', line 78

def handle_focus
  super
  # Let the content component receive focus, so that it can immediately
  # start responding to key presses. Hidden content is left alone, so
  # focus parks here — where a container with nothing to forward to
  # leaves it anyway.
  screen.focused = content if !content.nil? && content.visible? && content.focusable?
end