The mounted widget tree of a running application.
One of these is built from the element tree render/1 returns and is what
routes events, resolves selectors and remembers where each widget was drawn.
Drafter.Test.get_widget_hierarchy/1 hands the whole struct to a test; the
functions here are otherwise called by the framework rather than by an
application.
The fields a test reads most:
:widgets- every mounted widget by id, each carrying its:module,:state,:parent,:childrenand:pid:widget_rects- the rect a widget was last drawn into, by id, as%{x:, y:, width:, height:}in zero-based screen cells:focused_widget- the id holding keyboard focus, ornil:hover_widget- the id under the pointer, ornil:root- the id of the outermost widget
Summary
Functions
Clear the per-dispatch consumption flag before routing a new event.
Snapshot the calling process's session context, as Drafter.Session.Context.capture/0.
The freshest state for a widget info map.
Record that a widget handled the event currently being routed.
Store widget_info under widget_id, replacing whatever was there.
Record how a widget should mark content that does not fit its width.
Stop every widget server the hierarchy holds.
Push new props into a widget.
Replace a widget's info map with fun.(info).
Reparent a widget. A widget the hierarchy does not hold is left alone.
Record a widget's rect and re-render it.
Replace a widget's whole state.
How a widget marks content that does not fit, defaulting to clipping.
Types
@type t() :: %Drafter.WidgetHierarchy{ drag_capture_widget: term(), event_consumed: term(), focused_widget: widget_id() | nil, hidden_widgets: term(), hover_widget: widget_id() | nil, preferred_sizes: term(), root: widget_id() | nil, scroll_containers: %{required(widget_id()) => scroll_info()}, widget_counter: integer(), widget_overflow: term(), widget_rects: %{required(widget_id()) => rect()}, widget_scroll_parents: %{required(widget_id()) => widget_id()}, widgets: %{ required(widget_id()) => %{ module: module(), state: map(), parent: widget_id() | nil, children: [widget_id()], pid: pid() | nil, order: integer() } } }
Functions
Clear the per-dispatch consumption flag before routing a new event.
Snapshot the calling process's session context, as Drafter.Session.Context.capture/0.
The freshest state for a widget info map.
Asks the widget's server when it has one, falling back to the cached state if the server cannot answer. Returns the cached state directly for an inline widget.
Record that a widget handled the event currently being routed.
Consumption comes from the handler's own verdict, not from whether its state
changed. Cleared before each dispatch by clear_consumed/1.
Store widget_info under widget_id, replacing whatever was there.
Record how a widget should mark content that does not fit its width.
:clip is the default and is not stored. Read back with widget_overflow/2.
@spec stop_all_servers(t() | nil) :: :ok
Stop every widget server the hierarchy holds.
Widgets held inline and servers that have already exited are skipped, and a server
that exits while being stopped is ignored. Always returns :ok, including for a
nil hierarchy.
Push new props into a widget.
A widget backed by a live server has them sent to it and the hierarchy comes back unchanged; a widget held inline has them merged into its cached state. A widget the hierarchy does not hold is ignored.
Replace a widget's info map with fun.(info).
A widget the hierarchy does not hold is left alone and fun is not called.
Reparent a widget. A widget the hierarchy does not hold is left alone.
Record a widget's rect and re-render it.
The widget is re-rendered on every call, including when the rect is unchanged, so its strips reflect any state that moved since the last pass.
Replace a widget's whole state.
A widget backed by a live server has the state set on it and the hierarchy comes back unchanged; a widget held inline has its cached state replaced. A widget the hierarchy does not hold is ignored.
How a widget marks content that does not fit, defaulting to clipping.