Skip to main content

RepaintTrigger

Struct RepaintTrigger 

Source
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 with BuildContext::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

Source

pub fn new() -> Self

A trigger attached to nothing yet.

Source

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.

Source

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.

Source

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.

Source

pub fn is_attached(&self) -> bool

Whether the trigger is attached to at least one live widget.

Source

pub fn stats(&self) -> RepaintTriggerStats

What the trigger did so far.

Source

pub fn ptr_eq(&self, other: &Self) -> bool

Whether self and other are the same trigger.

Trait Implementations§

Source§

impl Clone for RepaintTrigger

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RepaintTrigger

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Counters only: never takes the list lock, so it is safe to print from anywhere, while a request is in progress included.

Source§

impl Default for RepaintTrigger

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.