pub struct Frames { /* private fields */ }Expand description
A periodic glyph cycle on a caller-supplied clock.
Pure phase arithmetic: the frame at now and the instant of the next
change derive from now mod interval, so cycles stay aligned no matter
when or how often they are sampled.
Implementations§
Source§impl Frames
impl Frames
Sourcepub const SPINNER_ASCII: Self
pub const SPINNER_ASCII: Self
Four-spoke spinner safe for 7-bit ASCII terminals.
Sourcepub const fn new(frames: &'static [&'static str], interval: Duration) -> Self
pub const fn new(frames: &'static [&'static str], interval: Duration) -> Self
Creates a cycle stepping through frames every interval.
§Panics
When frames is empty or interval is zero.
Sourcepub const fn at(&self, now: Duration) -> &'static str
pub const fn at(&self, now: Duration) -> &'static str
The glyph on screen at time now.
Examples found in repository?
More examples
examples/chat/demo.rs (line 581)
576 fn brand_segment(&self, now: Duration) -> Segment {
577 let work = self.work.borrow();
578 let brand = if work.working {
579 fmts!(
580 "{} {}",
581 self.charset.spinner().at(now),
582 elapsed_label(now.saturating_sub(work.since))
583 )
584 } else {
585 fmts!("{} omp", self.charset.icon(Icon::Omp))
586 };
587 Segment::new()
588 .label(brand)
589 .with(Prop::Fg, work.fade.sample(now))
590 }Sourcepub const fn next_change(&self, now: Duration) -> Duration
pub const fn next_change(&self, now: Duration) -> Duration
When the glyph after now appears — the deadline to pass to
crate::PaintCtx::wake.
Examples found in repository?
examples/chat/demo.rs (line 687)
664 fn paint(&mut self, pc: &mut PaintCtx<'_>, rect: Rect) {
665 let mut left = self.left_group(pc.now);
666 let (_, left_width) = left.measure(pc.ctx);
667 let (_, right_width) = self.right.measure(pc.ctx);
668 if left_width.saturating_add(2).saturating_add(right_width) <= rect.width {
669 left.paint(pc, Rect::new(rect.x, rect.y, left_width, 1));
670 let dock = rect
671 .x
672 .saturating_add(rect.width)
673 .saturating_sub(right_width);
674 self
675 .right
676 .paint(pc, Rect::new(dock, rect.y, right_width, 1));
677 } else {
678 let mut combined = self.combined(pc.now);
679 combined.paint(pc, rect);
680 }
681 let work = self.work.borrow();
682 let fade_frame = work
683 .fade
684 .settles_at()
685 .min(pc.now.saturating_add(FADE_FRAME));
686 let deadline = match (work.working, work.fade.is_settled(pc.now)) {
687 (true, true) => Some(pc.ctx.charset.spinner().next_change(pc.now)),
688 (true, false) => Some(pc.ctx.charset.spinner().next_change(pc.now).min(fade_frame)),
689 (false, false) => Some(fade_frame),
690 (false, true) => None,
691 };
692 if let Some(at) = deadline {
693 pc.wake(self.slot, at);
694 }
695 }Trait Implementations§
Auto Trait Implementations§
impl Freeze for Frames
impl RefUnwindSafe for Frames
impl Send for Frames
impl Sync for Frames
impl Unpin for Frames
impl UnsafeUnpin for Frames
impl UnwindSafe for Frames
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more