pub struct LinearSpinner<'a> { /* private fields */ }Expand description
A linear spinner that animates either horizontally or vertically.
Pass a monotonically increasing tick counter (typically incremented once
per render frame) and call .direction(), .linear_style(), and colour
methods to customise the appearance.
§Horizontal (default)
tick 0–2 : ●●·
tick 3–5 : ·●●
tick 6–8 : ··● (window wraps)
tick 9–11: ●··§Vertical (bounce)
tick 0–2 : ● ← slot 0 lit
·
·
tick 3–5 : ·
● ← slot 1 lit
·
tick 6–8 : ·
·
● ← slot 2 lit
tick 9–11: ·
● ← slot 1 lit (bouncing back)
·§Examples
use ratatui::Frame;
use ratatui::layout::Rect;
use tui_spinner::{Direction, LinearStyle, LinearSpinner};
fn draw(frame: &mut Frame, area: Rect, tick: u64) {
// Horizontal ellipsis
frame.render_widget(LinearSpinner::new(tick), area);
// Vertical bounce with diamond symbols
frame.render_widget(
LinearSpinner::new(tick)
.direction(Direction::Vertical)
.linear_style(LinearStyle::Diamond),
area,
);
}Implementations§
Source§impl<'a> LinearSpinner<'a>
impl<'a> LinearSpinner<'a>
Sourcepub fn new(tick: u64) -> Self
pub fn new(tick: u64) -> Self
Creates a new LinearSpinner at the given animation tick with all
defaults: 3 slots, 2 lit, horizontal, classic style, 3 ticks/step.
§Examples
use tui_spinner::LinearSpinner;
let spinner = LinearSpinner::new(0);Sourcepub const fn direction(self, direction: Direction) -> Self
pub const fn direction(self, direction: Direction) -> Self
Sets the animation direction (default: Direction::Horizontal).
Direction::Horizontal— scrolling window across a row.Direction::Vertical— bouncing symbol down a column.
§Examples
use tui_spinner::{Direction, LinearSpinner};
let vertical = LinearSpinner::new(0).direction(Direction::Vertical);Sourcepub const fn flow(self, flow: Flow) -> Self
pub const fn flow(self, flow: Flow) -> Self
Sets the animation flow direction (default: Flow::Forwards).
Flow::Forwards— normal playback (left-to-right / upward-first bounce).Flow::Backwards— reversed playback (right-to-left / downward-first bounce).
§Examples
use tui_spinner::{Flow, LinearSpinner};
let backwards = LinearSpinner::new(0).flow(Flow::Backwards);Sourcepub const fn linear_style(self, style: LinearStyle) -> Self
pub const fn linear_style(self, style: LinearStyle) -> Self
Sets the symbol pair used to draw active and inactive slots
(default: LinearStyle::Classic).
§Examples
use tui_spinner::{LinearStyle, LinearSpinner};
let spinner = LinearSpinner::new(0).linear_style(LinearStyle::Square);Sourcepub fn total_slots(self, n: usize) -> Self
pub fn total_slots(self, n: usize) -> Self
Sets the total number of slots (default: 3, minimum: 1).
For Direction::Vertical this is the column height.
For Direction::Horizontal this is the row width.
§Examples
use tui_spinner::LinearSpinner;
let spinner = LinearSpinner::new(0).total_slots(5);Sourcepub fn lit_slots(self, n: usize) -> Self
pub fn lit_slots(self, n: usize) -> Self
Sets the number of consecutive slots lit at once (default: 2).
Only meaningful for Direction::Horizontal; ignored in vertical mode
where exactly one slot is always lit. Values are clamped at render time
to [1, total_slots].
§Examples
use tui_spinner::LinearSpinner;
let spinner = LinearSpinner::new(0).lit_slots(1);Sourcepub fn ticks_per_step(self, n: u64) -> Self
pub fn ticks_per_step(self, n: u64) -> Self
Sets how many ticks each animation step is held (default: 3).
Higher values slow the animation; lower values speed it up. Zero is silently clamped to 1.
§Examples
use tui_spinner::LinearSpinner;
let fast = LinearSpinner::new(0).ticks_per_step(1);Sourcepub const fn active_color(self, color: Color) -> Self
pub const fn active_color(self, color: Color) -> Self
Sets the colour of active (lit) symbols (default: Color::White).
§Examples
use ratatui::style::Color;
use tui_spinner::LinearSpinner;
let spinner = LinearSpinner::new(0).active_color(Color::Cyan);Sourcepub const fn inactive_color(self, color: Color) -> Self
pub const fn inactive_color(self, color: Color) -> Self
Sets the colour of inactive (dim) symbols (default: Color::DarkGray).
§Examples
use ratatui::style::Color;
use tui_spinner::LinearSpinner;
let spinner = LinearSpinner::new(0).inactive_color(Color::DarkGray);Trait Implementations§
Source§impl<'a> Clone for LinearSpinner<'a>
impl<'a> Clone for LinearSpinner<'a>
Source§fn clone(&self) -> LinearSpinner<'a>
fn clone(&self) -> LinearSpinner<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<'a> Debug for LinearSpinner<'a>
impl<'a> Debug for LinearSpinner<'a>
Source§impl<'a> PartialEq for LinearSpinner<'a>
impl<'a> PartialEq for LinearSpinner<'a>
Source§impl Styled for LinearSpinner<'_>
impl Styled for LinearSpinner<'_>
Source§impl Widget for &LinearSpinner<'_>
impl Widget for &LinearSpinner<'_>
Source§impl Widget for LinearSpinner<'_>
impl Widget for LinearSpinner<'_>
impl<'a> StructuralPartialEq for LinearSpinner<'a>
Auto Trait Implementations§
impl<'a> Freeze for LinearSpinner<'a>
impl<'a> RefUnwindSafe for LinearSpinner<'a>
impl<'a> Send for LinearSpinner<'a>
impl<'a> Sync for LinearSpinner<'a>
impl<'a> Unpin for LinearSpinner<'a>
impl<'a> UnsafeUnpin for LinearSpinner<'a>
impl<'a> UnwindSafe for LinearSpinner<'a>
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> 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>
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>
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 moreSource§impl<T, U> Stylize<'_, T> for Uwhere
U: Styled<Item = T>,
impl<T, U> Stylize<'_, T> for Uwhere
U: Styled<Item = T>,
fn bg<C>(self, color: C) -> T
fn fg<C>(self, color: C) -> T
fn add_modifier(self, modifier: Modifier) -> T
fn remove_modifier(self, modifier: Modifier) -> T
fn reset(self) -> T
Source§fn on_magenta(self) -> T
fn on_magenta(self) -> T
magenta.Source§fn on_dark_gray(self) -> T
fn on_dark_gray(self) -> T
dark_gray.Source§fn on_light_red(self) -> T
fn on_light_red(self) -> T
light_red.Source§fn light_green(self) -> T
fn light_green(self) -> T
light_green.Source§fn on_light_green(self) -> T
fn on_light_green(self) -> T
light_green.Source§fn light_yellow(self) -> T
fn light_yellow(self) -> T
light_yellow.Source§fn on_light_yellow(self) -> T
fn on_light_yellow(self) -> T
light_yellow.Source§fn light_blue(self) -> T
fn light_blue(self) -> T
light_blue.Source§fn on_light_blue(self) -> T
fn on_light_blue(self) -> T
light_blue.Source§fn light_magenta(self) -> T
fn light_magenta(self) -> T
light_magenta.Source§fn on_light_magenta(self) -> T
fn on_light_magenta(self) -> T
light_magenta.Source§fn light_cyan(self) -> T
fn light_cyan(self) -> T
light_cyan.Source§fn on_light_cyan(self) -> T
fn on_light_cyan(self) -> T
light_cyan.Source§fn not_italic(self) -> T
fn not_italic(self) -> T
italic modifier.Source§fn underlined(self) -> T
fn underlined(self) -> T
underlined modifier.Source§fn not_underlined(self) -> T
fn not_underlined(self) -> T
underlined modifier.Source§fn slow_blink(self) -> T
fn slow_blink(self) -> T
slow_blink modifier.Source§fn not_slow_blink(self) -> T
fn not_slow_blink(self) -> T
slow_blink modifier.Source§fn rapid_blink(self) -> T
fn rapid_blink(self) -> T
rapid_blink modifier.Source§fn not_rapid_blink(self) -> T
fn not_rapid_blink(self) -> T
rapid_blink modifier.Source§fn not_reversed(self) -> T
fn not_reversed(self) -> T
reversed modifier.hidden modifier.hidden modifier.Source§fn crossed_out(self) -> T
fn crossed_out(self) -> T
crossed_out modifier.Source§fn not_crossed_out(self) -> T
fn not_crossed_out(self) -> T
crossed_out modifier.