WebpAnimation

Struct WebpAnimation 

Source
pub struct WebpAnimation { /* private fields */ }
Expand description

Represents a WebP animation, handling frame data, playback control, and rendering.

Implementations§

Source§

impl WebpAnimation

Source

pub fn from_file<P: AsRef<Path>>(path: P, app: &App) -> Result<Self, String>

Creates a new WebpAnimation instance by loading frames from a WebP file.

This function decodes the WebP file at the given path and prepares the animation for playback.

§Parameters
  • path: Path to the WebP file containing the animation.
  • app: Reference to the Nannou App instance, used for creating textures.
§Returns

A Result containing:

  • Ok(WebpAnimation): The animation instance if successful.
  • Err(String): An error message if loading fails.
§Errors

Returns an error if the file cannot be decoded or contains no frames.

Examples found in repository?
examples/basic_example.rs (line 18)
8fn model(app: &App) -> Model {
9    // Create a new window
10    app.new_window().view(view).build().unwrap();
11
12    // Load the WEBP animation
13    let assets = app.assets_path().expect("Failed to find assets directory");
14    let webp_path = assets.join("animation.webp"); // Place 'animation.webp' in the 'assets' directory
15
16    // Initialize the animation
17    let animation =
18        WebpAnimation::from_file(&webp_path, app).expect("Failed to load WEBP animation");
19
20    Model { animation }
21}
Source

pub fn update(&mut self)

Updates the animation’s current frame based on elapsed time.

This function should be called in each frame of the main loop to keep the animation in sync with its intended frame durations.

Examples found in repository?
examples/basic_example.rs (line 25)
23fn update(_app: &App, model: &mut Model, _update: Update) {
24    // Update the animation
25    model.animation.update();
26}
Source

pub fn texture(&self) -> &Texture

Returns a reference to the current texture.

§Returns

A reference to the Texture of the current frame.

Examples found in repository?
examples/basic_example.rs (line 42)
28fn view(app: &App, model: &Model, frame: Frame) {
29    // Clear the frame
30    frame.clear(BLACK);
31
32    let win = app.window_rect();
33
34    // Define the rectangle where the animation will be drawn
35    let r = Rect::from_w_h(
36        model.animation.width() as f32,
37        model.animation.height() as f32,
38    )
39    .top_left_of(win);
40
41    let draw = app.draw();
42    draw.texture(model.animation.texture())
43        .xy(r.xy())
44        .wh(r.wh());
45
46    draw.to_frame(app, &frame).unwrap();
47}
Source

pub fn width(&self) -> u32

Returns the width of the current frame.

§Returns

The width (in pixels) of the current frame’s texture.

Examples found in repository?
examples/basic_example.rs (line 36)
28fn view(app: &App, model: &Model, frame: Frame) {
29    // Clear the frame
30    frame.clear(BLACK);
31
32    let win = app.window_rect();
33
34    // Define the rectangle where the animation will be drawn
35    let r = Rect::from_w_h(
36        model.animation.width() as f32,
37        model.animation.height() as f32,
38    )
39    .top_left_of(win);
40
41    let draw = app.draw();
42    draw.texture(model.animation.texture())
43        .xy(r.xy())
44        .wh(r.wh());
45
46    draw.to_frame(app, &frame).unwrap();
47}
Source

pub fn height(&self) -> u32

Returns the height of the current frame.

§Returns

The height (in pixels) of the current frame’s texture.

Examples found in repository?
examples/basic_example.rs (line 37)
28fn view(app: &App, model: &Model, frame: Frame) {
29    // Clear the frame
30    frame.clear(BLACK);
31
32    let win = app.window_rect();
33
34    // Define the rectangle where the animation will be drawn
35    let r = Rect::from_w_h(
36        model.animation.width() as f32,
37        model.animation.height() as f32,
38    )
39    .top_left_of(win);
40
41    let draw = app.draw();
42    draw.texture(model.animation.texture())
43        .xy(r.xy())
44        .wh(r.wh());
45
46    draw.to_frame(app, &frame).unwrap();
47}
Source

pub fn set_looping(&mut self, looping: bool)

Sets whether the animation should loop after reaching the final frame.

§Parameters
  • looping: If true, the animation will loop indefinitely. If false, it will stop at the last frame.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
where T: Component + Float, Swp: WhitePoint, Dwp: WhitePoint, D: AdaptFrom<S, Swp, Dwp, T>,

Source§

fn adapt_into_using<M>(self, method: M) -> D
where M: TransformMatrix<Swp, Dwp, T>,

Convert the source color to the destination color using the specified method
Source§

fn adapt_into(self) -> D

Convert the source color to the destination color using the bradford method by default
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, U> ConvertInto<U> for T
where U: ConvertFrom<T>,

Source§

fn convert_into(self) -> U

Convert into T with values clamped to the color defined bounds Read more
Source§

fn convert_unclamped_into(self) -> U

Convert into T. The resulting color might be invalid in its color space Read more
Source§

fn try_convert_into(self) -> Result<U, OutOfBounds<U>>

Convert into T, returning ok if the color is inside of its defined range, otherwise an OutOfBounds error is returned which contains the unclamped color. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSync for T
where T: Sync,