use tiny_led_matrix::Render;
use crate::scrolling::{Animate, ScrollingState, Scrollable};
#[derive(Copy, Clone)]
pub struct ScrollingStatics<T: Render + 'static> {
images: &'static [T],
state: ScrollingState,
}
impl<T: Render + 'static> ScrollingStatics<T> {
pub fn set_images(&mut self, images: &'static [T]) {
self.images = images;
self.reset();
}
}
impl<T: Render + 'static> Default for ScrollingStatics<T> {
fn default() -> ScrollingStatics<T> {
ScrollingStatics {
images: &[],
state: Default::default(),
}
}
}
impl<T: Render + 'static> Scrollable for ScrollingStatics<T> {
type Subimage = T;
fn length(&self) -> usize {
self.images.len()
}
fn state(&self) -> &ScrollingState {
&self.state
}
fn state_mut(&mut self) -> &mut ScrollingState {
&mut self.state
}
fn subimage(&self, index: usize) -> &T {
&self.images[index]
}
}
impl<T: Render + 'static> Render for ScrollingStatics<T> {
fn brightness_at(&self, x: usize, y: usize) -> u8 {
self.current_brightness_at(x, y)
}
}