wip: broken collect enum

This commit is contained in:
🪞👃🪞 2024-08-21 16:46:31 +03:00
parent bb0230b6e5
commit 72f47bc837
6 changed files with 301 additions and 157 deletions

View file

@ -0,0 +1,35 @@
use crate::*;
macro_rules! impl_axis_common { ($A:ident $T:ty) => {
impl $A<$T> {
pub fn start_inc (&mut self) -> $T {
self.start = self.start + 1;
self.start
}
pub fn start_dec (&mut self) -> $T {
self.start = self.start.saturating_sub(1);
self.start
}
pub fn point_inc (&mut self) -> Option<$T> {
self.point = self.point.map(|p|p + 1);
self.point
}
pub fn point_dec (&mut self) -> Option<$T> {
self.point = self.point.map(|p|p.saturating_sub(1));
self.point
}
}
} }
pub struct FixedAxis<T> { pub start: T, pub point: Option<T> }
impl_axis_common!(FixedAxis u16);
impl_axis_common!(FixedAxis usize);
pub struct ScaledAxis<T> { pub start: T, pub scale: T, pub point: Option<T> }
impl_axis_common!(ScaledAxis u16);
impl_axis_common!(ScaledAxis usize);
impl<T: Copy> ScaledAxis<T> {
pub fn scale_mut (&mut self, cb: &impl Fn(T)->T) {
self.scale = cb(self.scale)
}
}