Class: Tuile::Component::Slot

Inherits:
Component
  • Object
show all
Includes:
HasContent
Defined in:
lib/tuile/component/slot.rb,
sig/tuile.rbs

Overview

A one-child region: a place in the tree reserved for content that may be absent, arrive late, or be swapped. The occupant fills the slot's #rect.

Wire one per region at construction, then swap occupants through HasContent#content= — which is how Window holds its footer:

@footer_slot = Slot.new
add_child(@footer_slot)             # the region, wired once

@footer_slot.content = new_footer   # the occupant, swapped at will

Because the slot never leaves #children, a swap's insert index is always 0 — never a function of which other regions happen to be occupied, which is the whole reason to reach for one (D_slots).

An empty slot does not collapse: it keeps its rect and clears it, so a dialog with no message shows the hole. Close the gap with a zero extent from the parent, or assign an empty Rect to suppress the clear entirely (what Window does with an absent footer); never detach it.

Transparent to input: not #focusable?, #handle_mouse descends through it, and a departing occupant's focus repair is handed to the container.

Instance Attribute Summary

Attributes included from HasContent

#content

Instance Method Summary collapse

Constructor Details

#initialize(content = nil) ⇒ Slot

@param content — the initial occupant.

Parameters:

  • content (Component, nil) (defaults to: nil)


32
33
34
35
36
# File 'lib/tuile/component/slot.rb', line 32

def initialize(content = nil)
  super()
  @content = nil
  self.content = content unless content.nil?
end

Instance Method Details

#layout(content) ⇒ void

This method returns an undefined value.

@param content

Parameters:



51
# File 'lib/tuile/component/slot.rb', line 51

def layout(content) = content.rect = rect

#on_child_removed(child) ⇒ void

This method returns an undefined value.

Hands the repair to the container rather than doing it here: the default would move focus to self, and a slot is inert — no cursor, no keys, nothing to bubble from.

@param child — the just-detached occupant.

Parameters:



43
44
45
# File 'lib/tuile/component/slot.rb', line 43

def on_child_removed(child)
  parent&.on_child_removed(child)
end

#on_focusvoid

This method returns an undefined value.



2422
# File 'sig/tuile.rbs', line 2422

def on_focus: () -> void

#rect=void

This method returns an undefined value.

@param rect

Parameters:



2420
# File 'sig/tuile.rbs', line 2420

def rect=: (Rect rect) -> void