mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-10 21:56:42 +01:00
33 lines
1 KiB
Rust
33 lines
1 KiB
Rust
macro_rules! impl_axis_common { ($A:ident $T:ty) => {
|
|
impl $A<$T> {
|
|
pub fn start_inc (&mut self) -> $T {
|
|
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)
|
|
}
|
|
}
|