pub struct AnimationLoopBuilder { /* private fields */ }Expand description
Builder for constructing AnimationLoop instances.
Created by AnimationLoop::new() and configured with fluent methods
like fps(). The builder is finalized by calling
on_frame() which returns an AnimationLoop.
§Examples
use dotmax::animation::AnimationLoop;
// Full builder chain
AnimationLoop::new(80, 24)
.fps(60)
.on_frame(|frame, buffer| {
// Draw frame content
Ok(true)
})
.run()?;use dotmax::animation::AnimationLoop;
// Check default FPS
let builder = AnimationLoop::new(80, 24);
// Default FPS is 60Implementations§
Source§impl AnimationLoopBuilder
impl AnimationLoopBuilder
Sourcepub fn fps(self, fps: u32) -> Self
pub fn fps(self, fps: u32) -> Self
Sets the target frames per second.
The FPS value is clamped to the valid range of 1-240. Values outside this range are silently corrected to the nearest valid value.
Higher FPS provides smoother animation but uses more CPU. For most terminal animations, 30-60 FPS is sufficient.
§Arguments
fps- Target frames per second (1-240, clamped if out of range)
§Returns
Self for method chaining.
§Examples
use dotmax::animation::AnimationLoop;
// 30 FPS for lower CPU usage
let builder = AnimationLoop::new(80, 24).fps(30);
// 120 FPS for smooth motion
let builder = AnimationLoop::new(80, 24).fps(120);
// Values are clamped to valid range
let builder = AnimationLoop::new(80, 24).fps(0); // Becomes 1
let builder = AnimationLoop::new(80, 24).fps(500); // Becomes 240Sourcepub const fn on_frame<F>(self, callback: F) -> AnimationLoop<F>
pub const fn on_frame<F>(self, callback: F) -> AnimationLoop<F>
Sets the frame callback and builds the AnimationLoop.
The callback is called once per frame with:
frame: Frame number starting at 0, incrementing each framebuffer: Mutable reference to the back buffer (BrailleGrid)
The back buffer is cleared before each callback, so you only need to draw the current frame content.
§Arguments
callback- Function called each frame to draw content
§Returns
An AnimationLoop ready to be run.
§Callback Return Values
Ok(true): Continue to the next frameOk(false): Stop the animation gracefullyErr(...): Stop with an error
§Examples
use dotmax::animation::AnimationLoop;
AnimationLoop::new(80, 24)
.fps(60)
.on_frame(|frame, buffer| {
// frame starts at 0 and increments each frame
let x = (frame as usize * 2) % 160;
buffer.set_dot(x, 48)?;
// Return false after 1000 frames to stop
Ok(frame < 1000)
})
.run()?;Auto Trait Implementations§
impl Freeze for AnimationLoopBuilder
impl RefUnwindSafe for AnimationLoopBuilder
impl Send for AnimationLoopBuilder
impl Sync for AnimationLoopBuilder
impl Unpin for AnimationLoopBuilder
impl UnwindSafe for AnimationLoopBuilder
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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