Skip to main content

oino_ui/extras/
spinner.rs

1//! `Spinner` node (§4.5.2).
2
3use serde::{Deserialize, Serialize};
4
5use crate::node::{Common, IntoNode, Node};
6use crate::text::Line;
7
8/// An activity indicator (§4.5.2). TUI: braille spinner on the shared ticker;
9/// app: CSS animation (static dot under `prefers-reduced-motion`).
10#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
11#[serde(rename_all = "camelCase")]
12pub struct Spinner {
13    /// Common node props (`key`, `style`, `block`, `fallback`).
14    #[serde(flatten)]
15    pub common: Common,
16    /// Optional label next to the spinner.
17    #[serde(default, skip_serializing_if = "Option::is_none")]
18    pub label: Option<Line>,
19}
20
21impl Spinner {
22    /// A spinner with a label.
23    #[must_use]
24    pub fn new(label: impl Into<Line>) -> Self {
25        Self {
26            common: Common::new(),
27            label: Some(label.into()),
28        }
29    }
30
31    /// Sets the label.
32    #[must_use]
33    pub fn label(mut self, label: impl Into<Line>) -> Self {
34        self.label = Some(label.into());
35        self
36    }
37}
38
39impl IntoNode for Spinner {}
40impl From<Spinner> for Node {
41    fn from(s: Spinner) -> Self {
42        Node::Spinner(s)
43    }
44}