Module: Tuile::Component::HasContent

Included in:
Overlay, 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 provides a protected layout(content) positioning the child; the mixin owns the swap:

class Slot < Component
include Component::HasContent

def initialize = (super; @content = nil)

protected

def layout(content) = content.rect = 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

#contentComponent?

@return — the current content component.

Returns:



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

def content
  @content
end

Instance Method Details

#handle_focusvoid

This method returns an undefined value.



85
86
87
88
89
90
91
92
# File 'lib/tuile/component/has_content.rb', line 85

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

#rect=(rect) ⇒ void

This method returns an undefined value.

@param rect

Parameters:



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

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