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
impl Spinner
Sourcepub fn new() -> Self
pub fn new() -> Self
A spinner in Role::Primary, one revolution a second.
Sourcepub fn with_thickness(self, thickness: i32) -> Self
pub fn with_thickness(self, thickness: i32) -> Self
Sets the ring’s thickness in pixels, instead of deriving it from the radius.
Sourcepub fn with_period_ms(self, period_ms: u64) -> Self
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.
Sourcepub fn with_frame_ms(self, frame_ms: u64) -> Self
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.
Sourcepub fn set_period_ms(&mut self, period_ms: u64)
pub fn set_period_ms(&mut self, period_ms: u64)
Replaces the revolution period, clamped as Spinner::with_period_ms.
Sourcepub fn set_frame_ms(&mut self, frame_ms: Option<u64>)
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§
impl Copy for Spinner
Source§impl Describe for Spinner
impl Describe for Spinner
Source§const DOC: &'static str = "A turning arc, for when all there is to say is that something is happening."
const DOC: &'static str = "A turning arc, for when all there is to say is that something is happening."
Source§const ICON: &'static Icon
const ICON: &'static Icon
Source§const PROPERTIES: &'static [Property]
const PROPERTIES: &'static [Property]
Source§impl<M: 'static> Widget<M> for Spinner
impl<M: 'static> Widget<M> for Spinner
Source§fn snap(&mut self, _now_ms: u64) -> Animation
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>
fn describe(&self) -> Option<&dyn DynDescribe>
Source§fn describe_mut(&mut self) -> Option<&mut dyn DynDescribe>
fn describe_mut(&mut self) -> Option<&mut dyn DynDescribe>
describe.Source§fn paint(&self, ctx: &mut PaintCtx<'_>, canvas: &mut Pen<'_>)
fn paint(&self, ctx: &mut PaintCtx<'_>, canvas: &mut Pen<'_>)
canvas, which is already clipped to this widget’s bounds
intersected with the damage region being repainted. Read moreSource§fn animate(&mut self, now_ms: u64) -> Animation
fn animate(&mut self, now_ms: u64) -> Animation
EventCtx::request_animation — and stops being called
the moment it answers Wake::Never. Read moreSource§fn on_event(&mut self, event: &Event<'_>, ctx: &mut EventCtx<'_, M>) -> Handled
fn on_event(&mut self, event: &Event<'_>, ctx: &mut EventCtx<'_, M>) -> Handled
Source§fn measure(&self, ctx: &mut MeasureCtx<'_>, offered: Offer) -> Measured
fn measure(&self, ctx: &mut MeasureCtx<'_>, offered: Offer) -> Measured
Source§fn accepts_pointer(&self) -> bool
fn accepts_pointer(&self) -> bool
true if the pointer can hit this widget. Read moreSource§fn preserves_focus(&self) -> bool
fn preserves_focus(&self) -> bool
true if a press on this widget should leave focus exactly where
it is. Read moreAuto Trait Implementations§
impl Freeze for Spinner
impl RefUnwindSafe for Spinner
impl Send for Spinner
impl Sync for Spinner
impl Unpin for Spinner
impl UnsafeUnpin for Spinner
impl UnwindSafe for Spinner
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> DynDescribe for Twhere
T: Describe,
impl<T> DynDescribe for Twhere
T: Describe,
Source§fn kind(&self) -> &'static str
fn kind(&self) -> &'static str
Describe::KIND.Source§fn properties(&self) -> &'static [Property]
fn properties(&self) -> &'static [Property]
Describe::PROPERTIES.Source§fn get_property(&self, name: &str) -> Option<Value>
fn get_property(&self, name: &str) -> Option<Value>
Describe::get.Source§fn set_property(
&mut self,
name: &str,
value: Value,
) -> Result<(), PropertyError>
fn set_property( &mut self, name: &str, value: Value, ) -> Result<(), PropertyError>
Describe::set.