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
impl Progress
Sourcepub fn new(value: f32) -> Self
pub fn new(value: f32) -> Self
A bar at value, which is clamped — see Progress::set_value.
Sourcepub fn with_role(self, role: Role) -> Self
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.
Sourcepub fn set_value(&mut self, value: f32)
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.
Sourcepub fn update(&mut self, value: f32) -> bool
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.
Trait Implementations§
impl Copy for Progress
Source§impl Describe for Progress
impl Describe for Progress
Source§const DOC: &'static str = "A bar that fills to show how far along something is."
const DOC: &'static str = "A bar that fills to show how far along something is."
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 Progress
impl<M: 'static> Widget<M> for Progress
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 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 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 moreAuto Trait Implementations§
impl Freeze for Progress
impl RefUnwindSafe for Progress
impl Send for Progress
impl Sync for Progress
impl Unpin for Progress
impl UnsafeUnpin for Progress
impl UnwindSafe for Progress
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.