Skip to main content

Spinner

Struct Spinner 

Source
pub struct Spinner { /* private fields */ }
Expand description

An indeterminate activity indicator: an arc that goes round and round.

Not interactive, not focusable, not a tab stop, and it holds no value — a spinner that could show progress would be RadialProgress.

§It must be started, and it must be stopped

This is the widget that can keep a device awake. It is unbounded by nature: animate never answers Wake::Never while the node is visible, which is exactly what Ui::request_animation says it is allowed to do and exactly what it costs.

So it does not start itself. A spinner receives no events, so it cannot ask for frames from an event handler; the application asks, at the moment it decides something is loading:

let id = ui.add(root, Spinner::new(), Rect::new(100, 80, 48, 48))?;
ui.request_animation(id);

That is not an awkwardness to paper over with a constructor that does it invisibly. Keeping a CPU awake is a decision, and this puts it at the line where somebody made it.

Stopping is hiding. Ui::set_visible(id, false) — or removing the node — takes it out of the animating set, and Ui::animating drops back to zero. A spinner left visible on a screen nobody is looking at is a device that never idles, and nothing in the toolkit will notice on your behalf.

§Shape

A faint full ring with a brighter arc turning inside it, inscribed in the rectangle it is given like RadialProgress and sharing its geometry — the same centre, radius and thickness rules, so a spinner and a ring of the same size are the same ring.

Implementations§

Source§

impl Spinner

Source

pub fn new() -> Self

A spinner in Role::Primary, one revolution a second.

Source

pub fn with_role(self, role: Role) -> Self

Sets the colour of the moving arc.

Source

pub fn with_thickness(self, thickness: i32) -> Self

Sets the ring’s thickness in pixels, instead of deriving it from the radius.

Source

pub fn with_period_ms(self, period_ms: u64) -> Self

Sets how long one revolution takes.

Clamped to the default sampling interval, Motion::DEFAULT_INTERVAL_MS: a period shorter than a frame turns more than a full circle between them, which looks stopped or, worse, looks like it is going backwards.

Source

pub fn with_frame_ms(self, frame_ms: u64) -> Self

Gives this spinner its own sampling interval, in milliseconds.

Almost nothing should call this. The rate belongs to the tree — Ui::set_motion — so that one decision covers every moving thing on the panel and a deployment can turn all of it down at once. This is the escape hatch for the spinner that genuinely differs from everything around it: a ring that must keep turning smoothly on a panel whose other animation has been coarsened, or a decorative one that should cost less than the rest.

It overrides Motion::Every and is overridden by Motion::None in turn — reduced motion is a person’s decision, and a widget does not get to opt out of it.

Source

pub fn angle(&self) -> i32

Where the arc currently starts, in TURN units.

Source

pub fn set_role(&mut self, role: Role)

Replaces the colour role.

Source

pub fn set_period_ms(&mut self, period_ms: u64)

Replaces the revolution period, clamped as Spinner::with_period_ms.

Source

pub fn set_frame_ms(&mut self, frame_ms: Option<u64>)

Sets or clears this spinner’s own sampling interval — see Spinner::with_frame_ms, which is where the argument for not using it is written down.

Trait Implementations§

Source§

impl Clone for Spinner

Source§

fn clone(&self) -> Spinner

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 Copy for Spinner

Source§

impl Debug for Spinner

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Spinner

Source§

fn default() -> Self

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

impl Describe for Spinner

Source§

const KIND: &'static str = "spinner"

The name a form file uses for this widget. Kebab-case.
Source§

const DOC: &'static str = "A turning arc, for when all there is to say is that something is happening."

One line saying what this widget is, for somebody choosing one. Read more
Source§

const GROUP: Group = Group::Indicator

Which shelf of the catalogue this belongs on.
Source§

const ICON: &'static Icon

The widget’s glyph: a small portrait of the thing, for a palette to draw beside — or instead of — its name. Read more
Source§

const PROPERTIES: &'static [Property]

Every property, in the order an inspector should show them.
Source§

fn get(&self, name: &str) -> Option<Value>

The current value. Read more
Source§

fn apply(&mut self, name: &str, value: Value) -> Result<(), Mismatch>

Applies a value, reporting only what went wrong. Read more
Source§

fn set(&mut self, name: &str, value: Value) -> Result<(), PropertyError>

Applies a value, reporting what went wrong and where.
Source§

impl<M: 'static> Widget<M> for Spinner

Source§

fn snap(&mut self, _now_ms: u64) -> Animation

Nothing to land: a spinner has no end state to arrive at, so under Motion::None it simply stops turning and leaves a still ring. That is the honest reading of “no motion” for the one widget that is nothing but motion.

Source§

fn describe(&self) -> Option<&dyn DynDescribe>

This widget’s property description, if it has one. Read more
Source§

fn describe_mut(&mut self) -> Option<&mut dyn DynDescribe>

The mutable half of describe.
Source§

fn paint(&self, ctx: &mut PaintCtx<'_>, canvas: &mut Pen<'_>)

Draws into canvas, which is already clipped to this widget’s bounds intersected with the damage region being repainted. Read more
Source§

fn animate(&mut self, now_ms: u64) -> Animation

Advances time-based state. Called only while this widget has asked to animate — see EventCtx::request_animation — and stops being called the moment it answers Wake::Never. Read more
Source§

fn on_event(&mut self, event: &Event<'_>, ctx: &mut EventCtx<'_, M>) -> Handled

Reacts to an event routed to this widget.
Source§

fn measure(&self, ctx: &mut MeasureCtx<'_>, offered: Offer) -> Measured

How big this widget would like to be, given what the caller can promise. Read more
Source§

fn accepts_pointer(&self) -> bool

Returns true if the pointer can hit this widget. Read more
Source§

fn focusable(&self) -> bool

Returns true if this widget can take keyboard focus.
Source§

fn preserves_focus(&self) -> bool

Returns true if a press on this widget should leave focus exactly where it is. 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> AsAny for T
where T: Any,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Borrows as dyn Any.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Mutably borrows as dyn Any.
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> DynDescribe for T
where T: Describe,

Source§

fn kind(&self) -> &'static str

Source§

fn properties(&self) -> &'static [Property]

Source§

fn get_property(&self, name: &str) -> Option<Value>

Source§

fn set_property( &mut self, name: &str, value: Value, ) -> Result<(), PropertyError>

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.