pub struct MatrixRain<'a> { /* private fields */ }Expand description
The ratatui widget rendering the Matrix digital rain effect.
MatrixRain borrows the MatrixConfig for the lifetime of the render
call and consumes itself when rendered (per the
StatefulWidget contract). It is
intentionally stateful-only — there is no plain Widget implementation.
Animation requires per-frame state (column streams, RNG, timing, cached
color tier) that a stateless wrapper would either reset every frame or
hide behind surprising global mutable state.
§Example
use matrix_rain::{MatrixConfig, MatrixRain, MatrixRainState};
use ratatui::buffer::Buffer;
use ratatui::layout::Rect;
use ratatui::widgets::StatefulWidget;
let cfg = MatrixConfig::default();
let mut state = MatrixRainState::with_seed(0xC0FFEE);
let area = Rect::new(0, 0, 40, 12);
let mut buf = Buffer::empty(area);
// The widget is constructed once per frame and consumed by render().
MatrixRain::new(&cfg).render(area, &mut buf, &mut state);Inside a ratatui Terminal::draw closure:
ⓘ
terminal.draw(|f| {
f.render_stateful_widget(MatrixRain::new(&cfg), f.size(), &mut state);
})?;Implementations§
Source§impl<'a> MatrixRain<'a>
impl<'a> MatrixRain<'a>
Sourcepub fn new(config: &'a MatrixConfig) -> Self
pub fn new(config: &'a MatrixConfig) -> Self
Create a new MatrixRain widget bound to the given configuration.
The config is borrowed for the lifetime of the widget; build it once
outside the render loop and pass &cfg here each frame.
Trait Implementations§
Source§impl<'a> StatefulWidget for MatrixRain<'a>
impl<'a> StatefulWidget for MatrixRain<'a>
Auto Trait Implementations§
impl<'a> Freeze for MatrixRain<'a>
impl<'a> RefUnwindSafe for MatrixRain<'a>
impl<'a> Send for MatrixRain<'a>
impl<'a> Sync for MatrixRain<'a>
impl<'a> Unpin for MatrixRain<'a>
impl<'a> UnsafeUnpin for MatrixRain<'a>
impl<'a> UnwindSafe for MatrixRain<'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
Mutably borrows from an owned value. Read more
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>
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 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>
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