AnimationLoopBuilder

Struct AnimationLoopBuilder 

Source
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 60

Implementations§

Source§

impl AnimationLoopBuilder

Source

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 240
Source

pub const fn on_frame<F>(self, callback: F) -> AnimationLoop<F>
where F: FnMut(u64, &mut BrailleGrid) -> Result<bool, DotmaxError>,

Sets the frame callback and builds the AnimationLoop.

The callback is called once per frame with:

  • frame: Frame number starting at 0, incrementing each frame
  • buffer: 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 frame
  • Ok(false): Stop the animation gracefully
  • Err(...): 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§

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more