Struct throbber_widgets_tui::widgets::ThrobberState

source ·
pub struct ThrobberState { /* private fields */ }
Expand description

State to be used for Throbber render.

Implementations§

source§

impl ThrobberState

source

pub fn index(&self) -> i8

Get a index.

source

pub fn calc_next(&mut self)

Increase index.

§Examples:
let mut throbber_state = throbber_widgets_tui::ThrobberState::default();
assert_eq!(throbber_state.index(), 0);
throbber_state.calc_next();
assert_eq!(throbber_state.index(), 1);
Examples found in repository?
examples/demo.rs (line 8)
7
8
9
    fn on_tick(&mut self) {
        self.states.iter_mut().for_each(|state| state.calc_next());
    }
source

pub fn calc_step(&mut self, step: i8)

Calculate the index by specifying step.

Negative numbers can also be specified for step.

If step is 0, the index is determined at random.

§Examples:
let mut throbber_state = throbber_widgets_tui::ThrobberState::default();
assert_eq!(throbber_state.index(), 0);
throbber_state.calc_step(2);
assert_eq!(throbber_state.index(), 2);
throbber_state.calc_step(-3);
assert_eq!(throbber_state.index(), -1);
throbber_state.calc_step(0); // random
assert!((std::i8::MIN..=std::i8::MAX).contains(&throbber_state.index()))
source

pub fn normalize(&mut self, throbber: &Throbber<'_>)

Set the index to the range of throbber_set.symbols.len().

This is called from render function automatically.

§Examples:
let mut throbber_state = throbber_widgets_tui::ThrobberState::default();
let throbber = throbber_widgets_tui::Throbber::default();
let len = 6; //throbber.throbber_set.symbols.len() as i8;

throbber_state.normalize(&throbber);
assert_eq!(throbber_state.index(), 0);

throbber_state.calc_step(len + 2);
assert_eq!(throbber_state.index(), len + 2);
throbber_state.normalize(&throbber);
assert_eq!(throbber_state.index(), 2);

// Negative numbers are indexed from backward
throbber_state.calc_step(-3 - len);
assert_eq!(throbber_state.index(), -1 - len);
throbber_state.normalize(&throbber);
assert_eq!(throbber_state.index(), len - 1);

Trait Implementations§

source§

impl Clone for ThrobberState

source§

fn clone(&self) -> ThrobberState

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for ThrobberState

source§

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

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

impl Default for ThrobberState

source§

fn default() -> ThrobberState

Returns the “default value” for a type. 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> 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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
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> IntoEither for T

source§

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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
source§

impl<T> ToOwned for T
where T: Clone,

§

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>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V