pub struct RollCounter {
pub duration: f32,
pub ease: Ease,
/* private fields */
}Expand description
An integer display that rolls toward its target, like a score counter.
Every roll takes duration seconds regardless of size (eased, quick start
and gentle landing) and the shown number never passes the target.
use ferravex_play::tween::{Motion, RollCounter};
let mut score = RollCounter::new(0);
score.set_target(1_250);
let mut last = 0;
for _ in 0..20 {
let shown = score.advance(1. / 60., Motion::Full);
assert!(shown >= last && shown <= 1_250);
last = shown;
}
assert!(score.is_rolling());
for _ in 0..60 { score.advance(1. / 60., Motion::Full); }
assert_eq!(score.shown(), 1_250);
score.set_target(2_000);
assert_eq!(score.advance(0.016, Motion::Reduced), 2_000);Fields§
§duration: f32Seconds per roll (default 0.6).
ease: EaseRoll curve (default Ease::QuartOut).
Implementations§
Source§impl RollCounter
impl RollCounter
pub fn new(value: i64) -> RollCounter
Sourcepub fn set_target(&mut self, target: i64)
pub fn set_target(&mut self, target: i64)
Rolls from the currently shown value toward target.
pub fn target(&self) -> i64
pub fn is_rolling(&self) -> bool
Trait Implementations§
Source§impl Clone for RollCounter
impl Clone for RollCounter
Source§fn clone(&self) -> RollCounter
fn clone(&self) -> RollCounter
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for RollCounter
impl Debug for RollCounter
Source§impl PartialEq for RollCounter
impl PartialEq for RollCounter
impl Copy for RollCounter
impl StructuralPartialEq for RollCounter
Auto Trait Implementations§
impl Freeze for RollCounter
impl RefUnwindSafe for RollCounter
impl Send for RollCounter
impl Sync for RollCounter
impl Unpin for RollCounter
impl UnwindSafe for RollCounter
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