pub struct Model {
pub spinner: Spinner,
pub style: Style,
/* private fields */
}Expand description
Model represents the state and configuration of a spinner component.
The Model struct contains all the state needed to render and animate a spinner, including the animation frames, styling, current position, and unique identifier for message routing. This matches the Go bubbles spinner.Model for full compatibility.
§Fields
spinner- The Spinner configuration (frames and timing)style- Lipgloss Style for visual formattingframe- Current animation frame index (private)id- Unique instance identifier for message routing (private)tag- Message sequence number to prevent flooding (private)
§Examples
use bubbletea_widgets::spinner::{new, with_spinner, DOT};
use lipgloss_extras::prelude::*;
let mut spinner = new(&[
with_spinner(DOT.clone())
]);
// Use in a bubbletea-rs application
let view = spinner.view(); // Returns current frame as a styled stringFields§
§spinner: SpinnerSpinner settings to use.
style: StyleStyle sets the styling for the spinner.
Implementations§
Source§impl Model
impl Model
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new spinner model with default settings.
Creates a spinner using the LINE animation with default styling. Each spinner instance gets a unique ID for message routing.
§Examples
use bubbletea_widgets::spinner::Model;
let spinner = Model::new();
assert!(spinner.id() > 0);Sourcepub fn new_with_options(opts: &[SpinnerOption]) -> Self
pub fn new_with_options(opts: &[SpinnerOption]) -> Self
Creates a new spinner model with custom configuration options.
This function implements the options pattern to create a customized spinner. It matches Go’s New function exactly for API compatibility.
§Arguments
opts- Slice of SpinnerOption values to configure the spinner
§Examples
use bubbletea_widgets::spinner::{Model, with_spinner, DOT};
let spinner = Model::new_with_options(&[with_spinner(DOT.clone())]);
assert_eq!(spinner.spinner.frames.len(), 8);Sourcepub fn with_spinner(self, spinner: Spinner) -> Self
pub fn with_spinner(self, spinner: Spinner) -> Self
Sourcepub fn with_style(self, style: Style) -> Self
pub fn with_style(self, style: Style) -> Self
Sourcepub fn id(&self) -> i64
pub fn id(&self) -> i64
Returns the spinner’s unique identifier.
Each spinner instance has a unique ID used for message routing to ensure tick messages are delivered to the correct spinner. Matches Go’s ID() method for API compatibility.
§Examples
use bubbletea_widgets::spinner::Model;
let spinner1 = Model::new();
let spinner2 = Model::new();
assert_ne!(spinner1.id(), spinner2.id());Sourcepub fn tick_msg(&self) -> TickMsg
pub fn tick_msg(&self) -> TickMsg
Creates a tick message to advance the spinner animation.
This method creates a TickMsg that can be sent through the bubbletea-rs message system to trigger the next animation frame. The message includes the current time, spinner ID, and tag for proper routing. Matches Go’s Tick() method for API compatibility.
§Examples
use bubbletea_widgets::spinner::Model;
let spinner = Model::new();
let tick_msg = spinner.tick_msg();
assert_eq!(tick_msg.id, spinner.id());Source§impl Model
impl Model
Sourcepub fn update(&mut self, msg: Msg) -> Option<Cmd>
pub fn update(&mut self, msg: Msg) -> Option<Cmd>
Processes messages and updates the spinner state.
This is the standard bubbletea-rs update function that processes incoming messages. It handles TickMsg messages to advance the animation and ignores other message types. The function includes ID and tag validation to ensure proper message routing and prevent animation rate issues. Matches Go’s Update method exactly.
§Arguments
msg- The message to process
§Returns
Returns Some(Cmd) to schedule the next tick, or None if the message was ignored.
§Examples
use bubbletea_widgets::spinner::Model;
let mut spinner = Model::new();
let tick_msg = spinner.tick_msg();
let cmd = spinner.update(Box::new(tick_msg));
assert!(cmd.is_some()); // Should return next tick commandSourcepub fn view(&self) -> String
pub fn view(&self) -> String
Renders the current spinner frame as a styled string.
This method returns the current animation frame with styling applied. It’s the standard bubbletea-rs view function that produces the visual output. Matches Go’s View method exactly.
§Returns
Returns the styled string representation of the current frame. Returns “(error)” if the frame index is invalid.
§Examples
use bubbletea_widgets::spinner::{new, with_spinner, LINE};
let spinner = new(&[with_spinner(LINE.clone())]);
let output = spinner.view();
assert_eq!(output, "|"); // First frame of LINE spinnerTrait Implementations§
Auto Trait Implementations§
impl Freeze for Model
impl !RefUnwindSafe for Model
impl Send for Model
impl Sync for Model
impl Unpin for Model
impl !UnwindSafe for Model
Blanket Implementations§
Source§impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
Source§fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
Source§fn adapt_into(self) -> D
fn adapt_into(self) -> D
Source§impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
Source§fn arrays_from(colors: C) -> T
fn arrays_from(colors: C) -> T
Source§impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
Source§fn arrays_into(self) -> C
fn arrays_into(self) -> C
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<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
Source§type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
parameters when converting.Source§fn cam16_into_unclamped(
self,
parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>,
) -> T
fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.Source§impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
Source§fn components_from(colors: C) -> T
fn components_from(colors: C) -> T
Source§impl<T> FromAngle<T> for T
impl<T> FromAngle<T> for T
Source§fn from_angle(angle: T) -> T
fn from_angle(angle: T) -> T
angle.Source§impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
Source§fn from_stimulus(other: U) -> T
fn from_stimulus(other: U) -> T
other into Self, while performing the appropriate scaling,
rounding and clamping.Source§impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
Source§fn into_angle(self) -> U
fn into_angle(self) -> U
T.Source§impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
Source§type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
parameters when converting.Source§fn into_cam16_unclamped(
self,
parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>,
) -> T
fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.Source§impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
Source§fn into_color(self) -> U
fn into_color(self) -> U
Source§impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
Source§fn into_color_unclamped(self) -> U
fn into_color_unclamped(self) -> U
Source§impl<T> IntoStimulus<T> for T
impl<T> IntoStimulus<T> for T
Source§fn into_stimulus(self) -> T
fn into_stimulus(self) -> T
self into T, while performing the appropriate scaling,
rounding and clamping.Source§impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
Source§type Error = <C as TryFromComponents<T>>::Error
type Error = <C as TryFromComponents<T>>::Error
try_into_colors fails to cast.Source§fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
Source§impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
Source§fn try_into_color(self) -> Result<U, OutOfBounds<U>>
fn try_into_color(self) -> Result<U, OutOfBounds<U>>
OutOfBounds error is returned which contains
the unclamped color. Read more