pub struct RepaintTrigger { /* private fields */ }Expand description
Marks the widgets it is attached to for repaint, relayout or a pull from any thread, and wakes only their windows.
For content that changes off the UI thread: a terminal’s child printing, a background task’s progress, a status a service publishes. The producer stores the new state where the widget will read it, then requests; the widget reads it in the frame the request wakes. Requests coalesce: one wake per window until the widget has consumed the request.
request_repaint: only what the widget paints changed. Its window redraws, and the widget alone repaints.request_relayout: its size or what layout reads changed. It and its ancestors relayout, also in a window that draws nothing.request_pull: the widget has data to take in on the UI thread whether or not it is shown, through the hook it registered withBuildContext::on_trigger_pull. A widget that is not shown takes it in without its window drawing a frame.
A relayout or a pull reaches a window that draws nothing (minimised, covered, its frames withheld by the compositor), whose event loop then runs the layout half of a frame for it; a repaint waits there for the window to draw again.
Attach it in every build() with BuildContext::attach_repaint_trigger;
a rebuild or the widget’s destruction releases the attachment, and the
tree’s drop releases the rest. One trigger may be attached to several
widgets, in several windows. Send + Sync; a clone shares the trigger.
Do not request from paint() or a frame-tick effect: the widget would
repaint at display rate. Inside an event handler, the widget’s own
invalidation (EventContext::request_repaint) is cheaper.
Implementations§
Source§impl RepaintTrigger
impl RepaintTrigger
Sourcepub fn request_repaint(&self)
pub fn request_repaint(&self)
Only what the attached widgets paint changed. Each window wakes at most once until the widget’s next paint. A widget that is not painted (dormant, clipped out) keeps the request for when it is, and costs one wake until then, however many requests follow.
Sourcepub fn request_relayout(&self)
pub fn request_relayout(&self)
The attached widgets’ size or what layout reads changed: they and their ancestors relayout, and repaint. Each window wakes at most once until the widget’s next layout pass, and the wake reaches a window that draws nothing.
Sourcepub fn request_pull(&self)
pub fn request_pull(&self)
The attached widgets have data to take in on the UI thread, shown or
not: their pull hook (BuildContext::on_trigger_pull) runs in
their window’s next frame. The window draws that frame when a widget
with a pull pending was shown in its last one, and otherwise runs
one that draws nothing. Each window wakes at most once until the hook
has run. A widget with no hook is repainted as by
request_repaint.
Sourcepub fn is_attached(&self) -> bool
pub fn is_attached(&self) -> bool
Whether the trigger is attached to at least one live widget.
Sourcepub fn stats(&self) -> RepaintTriggerStats
pub fn stats(&self) -> RepaintTriggerStats
What the trigger did so far.