geometry: cut down on <> noise with associated types
This commit is contained in:
@ -17,13 +17,15 @@ use std::ops::IndexMut;
|
||||
pub trait HardwarePixel: Send + Sync + Rgb8Blend + Copy + AsMilliwatts + Default + From<Rgb<u8>> + Fract8Ops {}
|
||||
impl<T> HardwarePixel for T where T: Send + Sync + Rgb8Blend + Copy + AsMilliwatts + Default + From<Rgb<u8>> + Fract8Ops {}
|
||||
|
||||
pub trait Pixbuf<T: HardwarePixel>: AsMilliwatts + IndexMut<usize, Output=T> {
|
||||
pub trait Pixbuf: AsMilliwatts + IndexMut<usize, Output=Self::Pixel> {
|
||||
type Pixel: HardwarePixel;
|
||||
fn new() -> Self;
|
||||
fn blank(&mut self);
|
||||
fn iter_with_brightness(&self, brightness: u8) -> impl Iterator<Item = T> + Send;
|
||||
fn iter_with_brightness(&self, brightness: u8) -> impl Iterator<Item = Self::Pixel> + Send;
|
||||
}
|
||||
|
||||
impl<T: HardwarePixel, const PIXEL_NUM: usize> Pixbuf<T> for [T; PIXEL_NUM] {
|
||||
impl<T: HardwarePixel, const PIXEL_NUM: usize> Pixbuf for [T; PIXEL_NUM] {
|
||||
type Pixel = T;
|
||||
fn new() -> Self {
|
||||
[T::default(); PIXEL_NUM]
|
||||
}
|
||||
@ -37,7 +39,7 @@ impl<T: HardwarePixel, const PIXEL_NUM: usize> Pixbuf<T> for [T; PIXEL_NUM] {
|
||||
}
|
||||
}
|
||||
|
||||
struct SmartLedDisplay<T: FastWrite, S: Surface, P: Pixbuf<T::Color>> {
|
||||
struct SmartLedDisplay<T: FastWrite, S: Surface, P: Pixbuf<Pixel = T::Color>> {
|
||||
surfaces : Option<SurfacePool<S>>,
|
||||
pixmap: StrideMapping,
|
||||
target: T,
|
||||
@ -46,7 +48,7 @@ struct SmartLedDisplay<T: FastWrite, S: Surface, P: Pixbuf<T::Color>> {
|
||||
frame: usize
|
||||
}
|
||||
|
||||
impl<T: FastWrite, S: Surface, P: Pixbuf<T::Color>> Debug for SmartLedDisplay<T, S, P> {
|
||||
impl<T: FastWrite, S: Surface, P: Pixbuf<Pixel = T::Color>> Debug for SmartLedDisplay<T, S, P> {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result<(), std::fmt::Error> {
|
||||
f.debug_struct("SmartLedDisplay")
|
||||
.field("total_mw", &self.pixbuf.as_milliwatts())
|
||||
@ -55,7 +57,7 @@ impl<T: FastWrite, S: Surface, P: Pixbuf<T::Color>> Debug for SmartLedDisplay<T,
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: FastWrite, S: Surface, P: Pixbuf<T::Color>> SmartLedDisplay<T, S, P> {
|
||||
impl<T: FastWrite, S: Surface, P: Pixbuf<Pixel = T::Color>> SmartLedDisplay<T, S, P> {
|
||||
fn new(target: T, max_mw: u32, pixmap: StrideMapping, pixbuf: P) -> Self {
|
||||
SmartLedDisplay {
|
||||
pixbuf,
|
||||
@ -68,20 +70,11 @@ impl<T: FastWrite, S: Surface, P: Pixbuf<T::Color>> SmartLedDisplay<T, S, P> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, S, P> AsMilliwatts for SmartLedDisplay<T, S, P> where
|
||||
T: FastWrite,
|
||||
S: Surface,
|
||||
P: Pixbuf<T::Color> {
|
||||
fn as_milliwatts(&self) -> u32 {
|
||||
self.pixbuf.as_milliwatts()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, S, P> Surfaces<S> for SmartLedDisplay<T, S, P> where
|
||||
T: FastWrite,
|
||||
S: Surface,
|
||||
P: Pixbuf<T::Color> {
|
||||
fn new_surface(&mut self, area: &Rectangle<u8, Virtual>) -> Result<S, io::Error> {
|
||||
P: Pixbuf<Pixel = T::Color> {
|
||||
fn new_surface(&mut self, area: &Rectangle<Virtual>) -> Result<S, io::Error> {
|
||||
if let Some(ref mut s) = self.surfaces {
|
||||
s.new_surface(area)
|
||||
} else {
|
||||
@ -93,7 +86,7 @@ P: Pixbuf<T::Color> {
|
||||
impl<T, S, P> Display<S> for SmartLedDisplay<T, S, P> where
|
||||
T: FastWrite,
|
||||
S: Surface,
|
||||
P: Pixbuf<T::Color> {
|
||||
P: Pixbuf<Pixel = T::Color> {
|
||||
fn render_frame(&mut self) {
|
||||
let surfaces = self.surfaces.take().unwrap();
|
||||
for surface in surfaces.iter() {
|
||||
@ -126,7 +119,7 @@ trait FastWrite {
|
||||
impl<T, S, P> Framed for SmartLedDisplay<T, S, P> where
|
||||
T: FastWrite,
|
||||
S: Surface,
|
||||
P: Pixbuf<T::Color> {
|
||||
P: Pixbuf<Pixel = T::Color> {
|
||||
|
||||
fn start_frame(&mut self) {
|
||||
self.pixbuf.blank();
|
||||
|
Reference in New Issue
Block a user