Rain

Struct Rain 

Source
pub struct Rain { /* private fields */ }

Implementations§

Source§

impl Rain

Source

pub fn new_matrix(elapsed: Duration) -> Rain

Construct a new rain widget with defaults for matrix rain.

Source

pub fn new_rain(elapsed: Duration) -> Rain

Construct a new rain widget with defaults for standard rain.

Source

pub fn new_snow(elapsed: Duration) -> Rain

Construct a new rain widget with defaults for snow.

Source

pub fn new_emoji_soup(elapsed: Duration) -> Rain

Construct a new rain widget with defaults for emoji soup.

Terminals that render emojis as two characters wide will not enjoy this.

Source

pub fn with_seed(self, seed: u64) -> Rain

Set the random seed for the generation.

The random seed can be configured. Given a constant screen size, results should be reproducible across executions, operating systems, and architectures.

use std::time::Duration;
use tui_rain::Rain;

let elapsed = Duration::from_secs(5);

Rain::new_matrix(elapsed)
    .with_seed(1234);
Source

pub fn with_rain_density(self, rain_density: RainDensity) -> Rain

Set the target density for the rain.

This can be configured as an absolute number of drops:

use std::time::Duration;
use tui_rain::{Rain, RainDensity};

Rain::new_matrix(Duration::from_secs(0))
    .with_rain_density(RainDensity::Absolute {
        num_drops: 100,
    });

Or a ratio of screen pixels to drops (lower is more dense):

use std::time::Duration;
use tui_rain::{Rain, RainDensity};

Rain::new_matrix(Duration::from_secs(0))
    .with_rain_density(RainDensity::Relative {
        sparseness: 50,
    });

The actual number of drops on the screen at any time is randomly distributed between 0 and twice the target.

Preset relative options include:

  • RainDensity::Sparse
  • RainDensity::Normal
  • RainDensity::Dense
Source

pub fn with_rain_speed(self, rain_speed: RainSpeed) -> Rain

Set the target speed for the rain.

Speed can be configured as an absolute value of pixels per second, or as a preset.

For an absolute speed in pixels per second:

use std::time::Duration;
use tui_rain::{Rain, RainSpeed};

let elapsed = Duration::from_secs(5);

Rain::new_matrix(elapsed)
    .with_rain_speed(RainSpeed::Absolute {
        speed: 10.0,
    });

Preset options include:

  • RainSpeed::Slow
  • RainSpeed::Normal
  • RainSpeed::Fast
Source

pub fn with_rain_speed_variance(self, rain_speed_variance: f64) -> Rain

Set the rain speed variance.

To avoid perfectly consistent patterns, you can configure some variance in the speed of each drop. This can also give an impression of parallax (depth).

For example, a value of 0.1 will cause each drop’s speed to be uniformly distrbuted within ±10% of the target speed:

use std::time::Duration;
use tui_rain::Rain;

let elapsed = Duration::from_secs(5);

Rain::new_matrix(elapsed)
    .with_rain_speed_variance(0.1);

The speed of an individual drop will never go below 0.001 pixels / second, but can vary arbitrarily high.

Source

pub fn with_tail_lifespan(self, tail_lifespan: Duration) -> Rain

Set the tail lifespan for the rain.

You can make the rain drop tails appear shorter / longer by configuring how long the tail effect lasts:

use std::time::Duration;
use tui_rain::Rain;

let elapsed = Duration::from_secs(5);

Rain::new_matrix(elapsed)
    .with_tail_lifespan(Duration::from_secs(5));

The drop length is capped at the screen height to avoid strange wraparound effects.

Source

pub fn with_color(self, color: Color) -> Rain

Set the color for the rain.

You can change the tail color for each drop:

use std::time::Duration;
use tui_rain::Rain;

let elapsed = Duration::from_secs(5);

Rain::new_matrix(elapsed)
    .with_color(ratatui::style::Color::LightGreen);

The color of the head is independently configured. The bold / dim effects that automatically get applied over a drop’s length may tweak the color inadvertently, but this can be disabled.

Source

pub fn with_head_color(self, head_color: Color) -> Rain

Set the head color for the rain.

You can change the head color for each drop:

use std::time::Duration;
use tui_rain::Rain;

let elapsed = Duration::from_secs(5);

Rain::new_matrix(elapsed)
    .with_head_color(ratatui::style::Color::Green);

The color of the tail is independently configured. The bold / dim effects that automatically get applied over a drop’s length may tweak the color inadvertently, but this can be disabled.

Source

pub fn with_bold_dim_effect(self, bold_dim_effect: bool) -> Rain

Set whether to apply the bold / dim effect.

By default, the lower third of each drop has the bold effect applied, and the upper third has the dim effect applied. This produces an impression of the drop fading instead of abruptly ending.

This may tweak the color of glyphs away from the base color on some terminals, so it can be disabled if desired:

use std::time::Duration;
use tui_rain::Rain;

let elapsed = Duration::from_secs(5);

Rain::new_matrix(elapsed)
    .with_bold_dim_effect(false);
Source

pub fn with_noise_interval(self, noise_interval: Duration) -> Rain

Set the interval between random character changes.

A more subtle effect is that glyphs already rendered in a drop occasionally switch characters before dissapearing. The time interval between each character switch is per-glyph, and can be adjusted:

use std::time::Duration;
use tui_rain::Rain;

let elapsed = Duration::from_secs(5);

Rain::new_matrix(elapsed)
    .with_noise_interval(Duration::from_secs(10));
Source

pub fn with_character_set(self, character_set: CharacterSet) -> Rain

Set the character set for the drops.

The simplest option is to provide an explicit set of characters to choose from:

use std::time::Duration;
use tui_rain::{CharacterSet, Rain};

let elapsed = Duration::from_secs(5);

Rain::new_matrix(elapsed)
    .with_character_set(CharacterSet::Explicit {
        options: vec!['a', 'b', 'c'],
    });

More performant is to provide a unicode range:

use std::time::Duration;
use tui_rain::{CharacterSet, Rain};

let elapsed = Duration::from_secs(5);

Rain::new_matrix(elapsed)
    .with_character_set(CharacterSet::UnicodeRange {
        start: 0x61,
        len: 26,
    });

Preset unicode ranges include:

  • CharacterSet::HalfKana is the half-width Japanese kana character set (used in the classic matrix rain)
  • CharacterSet::Lowercase is the lowercase English character set

Trait Implementations§

Source§

impl Clone for Rain

Source§

fn clone(&self) -> Rain

Returns a duplicate 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 Rain

Source§

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

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

impl PartialEq for Rain

Source§

fn eq(&self, other: &Rain) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Widget for Rain

Source§

fn render(self, area: Rect, buf: &mut Buffer)

Draws the current state of the widget in the given buffer. That is the only method required to implement a custom widget.
Source§

impl StructuralPartialEq for Rain

Auto Trait Implementations§

§

impl Freeze for Rain

§

impl RefUnwindSafe for Rain

§

impl Send for Rain

§

impl Sync for Rain

§

impl Unpin for Rain

§

impl UnwindSafe for Rain

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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

Source§

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

Source§

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.