Skip to main content

dioxus_type_animation/
speed.rs

1const DEFAULT_SPEED: u64 = 40;
2
3/// Speed configuration equivalent to the React library's `speed` and
4/// `deletionSpeed` props.
5#[derive(Clone, Copy, Debug, PartialEq, Eq)]
6pub enum Speed {
7    /// React-compatible speed value, normally `1..=99`.
8    ///
9    /// Like `react-type-animation`, this is normalized to `abs(value - 100)`
10    /// milliseconds per keystroke before random jitter is applied.
11    Preset(u64),
12    /// Direct keystroke delay in milliseconds, equivalent to
13    /// `{ type: "keyStrokeDelayInMs", value }` in the React API.
14    KeyStrokeDelayInMs(u64),
15}
16
17impl Default for Speed {
18    fn default() -> Self {
19        Self::Preset(DEFAULT_SPEED)
20    }
21}
22
23impl From<u64> for Speed {
24    fn from(value: u64) -> Self {
25        Self::Preset(value)
26    }
27}
28
29impl From<usize> for Speed {
30    fn from(value: usize) -> Self {
31        Self::Preset(value as u64)
32    }
33}