Skip to main content

Progress

Struct Progress 

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

A determinate progress bar, 0.0 to 1.0.

Not interactive, not focusable, not a tab stop. It reports; it does not take input.

The bar fills the rectangle it is given, rather than centring a fixed thickness inside it the way Checkbox and Toggle do. There is no theme metric for a bar’s thickness, and inventing one would mean a caller who wants a chunky bar has to fight it. Give it the rectangle you want filled.

§There is no text on it

A percentage drawn inside the bar sits on the fill at one end and on the track at the other, so it needs two colours in one string to stay readable. That is a real amount of machinery for a label, and the alternative is already good: a Label beside the bar, updated from the same number.

§There is no indeterminate mode

It used to be impossible — an indeterminate bar animates forever, and Ui::tick once animated only the focused widget, which a progress bar never is. #19 removed that limitation, so this is now a choice rather than a wall: an unbounded animation costs a wake per frame for as long as the node is visible, and the widget that already spends it is Spinner. A second way to say something is happening, in a widget whose whole job is saying how much has happened, has not earned its place.

Implementations§

Source§

impl Progress

Source

pub fn new(value: f32) -> Self

A bar at value, which is clamped — see Progress::set_value.

Source

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

Sets the colour of the filled portion.

Warning or Error for a bar that means something is running out rather than something is being achieved.

Source

pub const fn value(&self) -> f32

The current value, always in 0.0..=1.0.

Source

pub fn set_value(&mut self, value: f32)

Sets the value, clamped into range.

Clamped rather than asserted, and NaN is zero. The number a caller passes is nearly always done / total, and total is eventually zero — on the first frame, on an empty queue, on a job that was cancelled before it was measured. A debug assertion would fire on a developer’s machine and a release build would draw a bar of undefined width; a panic would take down a paint loop, and a panic inside a paint loop on a kiosk is a black screen with no way to report itself.

So: NaN draws an empty bar, negative draws an empty bar, and anything above one draws a full one.

Source

pub fn update(&mut self, value: f32) -> bool

Sets the value, reporting whether it actually changed.

The Label::update pattern, and for the same reason: a panel writes its readings every cycle whether or not they moved, and repainting for a value that did not change is how an idle device stops being idle.

Note what this compares. Two values a hundredth apart are different and will both report true, while on a bar 80 pixels wide they are the same drawing. A caller updating far faster than its bar is wide should quantise before calling — the widget cannot do it, because it does not know how wide it is until it paints.

Source

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

Replaces the colour role.

Trait Implementations§

Source§

impl Clone for Progress

Source§

fn clone(&self) -> Progress

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 Progress

Source§

impl Debug for Progress

Source§

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

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

impl Default for Progress

Source§

fn default() -> Self

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

impl Describe for Progress

Source§

const KIND: &'static str = "progress"

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

const DOC: &'static str = "A bar that fills to show how far along something is."

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 Progress

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 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
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 snap(&mut self, now_ms: u64) -> Animation

Lands whatever is in flight at its end state, without animating it. 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.