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 { pub start: T, pub point: Option } impl_axis_common!(FixedAxis u16); impl_axis_common!(FixedAxis usize); pub struct ScaledAxis { pub start: T, pub scale: T, pub point: Option } impl_axis_common!(ScaledAxis u16); impl_axis_common!(ScaledAxis usize); impl ScaledAxis { pub fn scale_mut (&mut self, cb: &impl Fn(T)->T) { self.scale = cb(self.scale) } }