Teek::UI::Node Class
A single element of the retained-mode tree - a widget, layout container, reactive var, or deferred build-time op (the categories from the architecture doc; this class itself is generic across all of them). Plain Ruby, no Tk: constructible, mutable, and traversable with no interpreter, which is what makes the tree headless-testable.
key is this node’s stable identity - the explicit name if given,
else whatever the owning Document assigns. realized stays nil for
the whole build phase; a realizer fills it in later with a live
handle.
Inherits: Object
Instance Methods ↑
display_name
A short, human label for this node - its type, plus the explicit
name if it has one (e.g. "column" or "column(:ctrl)"). Used by
TreeInspector and the build stack’s own current_path breadcrumb
(WidgetDSL#current_path) - deliberately bare (no leading marker,
no “unnamed” filler text) since both of those read as a sequence
of these, not a single prose sentence the way Realizer’s own
private describe does.
Returns String
each(&block)
Depth-first, pre-order traversal of this node and its descendants.
Returns Enumerator — if no block given
@yieldparam node Node
initialize(type:, name: nil, key: nil, opts: {}, scope: Scope::TOP_LEVEL, document: nil)
Parameters
typeSymbol— node kind, e.g.:button,:column,:varnameSymbol, nil— explicit stable name, for addressing (ui[:name])keyString, nil— stable identity; defaults toname's string formoptsHash— widget/node options as plain Ruby valuesscopeScope— the component scope this node was built in -Scope::TOP_LEVEL(the default) for a build that never callsWidgetDSL#componentdocumentDocument, nil— back-reference to the owningDocument- set byDocument#create;nilfor a rawNode.newbuilt directly (headless tests, mostly). LetsHandle#destroy!unregister a destroyed node's own name(s) without every caller needing to thread a Document reference through by hand.
Returns Node — a new instance of Node
lazy?
Returns Boolean — whether this node is excluded from the ambient
create/link tree walk (Realizer#realize, Realizer#realize_subtree)
- true only for a container built with lazy: true (see
WidgetDSL#append_container). A lazy node stays a normal,
attached member of the retained tree; it just never gets a real
Tk widget until something explicitly realizes it (see
Handle#realize!).
logical_path
This node’s address, computed purely from the retained tree
(name/key ` #parent) - no Tk involved, correct before realize.
For an ordinary widget this already equals the real Tk path
(Realizer#allocate_path walks this identical parent/segment
structure); for anything without an independent Tk path of its
own (a menu entry, say), an Addressing strategy extends past
this with its own marker rather than pretending it’s a real one.
The other documented exception: a reusable component mounted more
than once under the same real parent - Realizer#allocate_path
only discovers that repeat (and disambiguates the later mounts’
paths) at realize, so this can’t predict it ahead of time either.
A node that isn’t attached anywhere yet (`parent+ nil, and not
itself the root) is treated as top-level - the best answer
available without a tree to place it in.
Returns String — e.g. ".", ".toolbar", ".toolbar.save"
pending_destroy?
Returns Boolean — whether a deferred Handle#destroy! is
currently scheduled (via after idle) but hasn't run yet -
lets a second destroy! call on the same still-pending handle
no-op instead of double-scheduling.
remove_child(node)
Unlinks node from this node’s own children - the symmetric
counterpart to #add_child, used by Handle#destroy! so a
destroyed node stops being reachable from the retained tree at
all (not just Tk-dead - actually gone from children, so a
later sibling addition never iterates it, and it becomes
collectable once nothing else references it).
Parameters
nodeNode
Returns Node — the node just removed
Attributes ↑
children [R]
Returns the value of attribute children.
document [R]
Returns the value of attribute document.
events [R]
Returns the value of attribute events.
key [R]
Returns the value of attribute key.
layout [R]
Returns the value of attribute layout.
name [R]
Returns the value of attribute name.
opts [R]
Returns the value of attribute opts.
parent [R]
Returns the value of attribute parent.
pending_destroy= [W]
Sets the attribute pending_destroy
Parameters
value— the value to set the attribute pending_destroy to.
realized [R]
Returns the value of attribute realized.
scope [R]
Returns the value of attribute scope.
type [R]
Returns the value of attribute type.