mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
wip(p60,e90): impl macros
This commit is contained in:
parent
f4a4b08c8a
commit
9d4fcaa32b
17 changed files with 748 additions and 1083 deletions
|
|
@ -33,33 +33,49 @@ impl<T> Coordinate for T where T: Send + Sync + Copy
|
|||
+ Into<f64>
|
||||
{}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct FixedAxis<T> {
|
||||
pub start: T,
|
||||
pub point: Option<T>,
|
||||
pub clamp: Option<T>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ScaledAxis<T> {
|
||||
pub start: T,
|
||||
pub scale: T,
|
||||
pub point: Option<T>,
|
||||
pub clamp: Option<T>,
|
||||
}
|
||||
|
||||
macro_rules! impl_axis_common { ($A:ident $T:ty) => {
|
||||
impl $A<$T> {
|
||||
#[inline] pub fn start_plus (&mut self, n: $T) -> $T {
|
||||
(self.start + n).min(self.clamp.unwrap_or(<$T>::MAX))
|
||||
}
|
||||
#[inline] pub fn start_inc (&mut self, n: $T) -> $T {
|
||||
self.start = (self.start + n).min(self.clamp.unwrap_or(<$T>::MAX));
|
||||
self.start = self.start_plus(n);
|
||||
self.start
|
||||
}
|
||||
#[inline] pub fn start_minus (&mut self, n: $T) -> $T {
|
||||
self.start.saturating_sub(n)
|
||||
}
|
||||
#[inline] pub fn start_dec (&mut self, n: $T) -> $T {
|
||||
self.start = self.start.saturating_sub(n);
|
||||
self.start = self.start_minus(n);
|
||||
self.start
|
||||
}
|
||||
#[inline] pub fn point_plus (&mut self, n: $T) -> Option<$T> {
|
||||
self.point.map(|p|(p + n).min(self.clamp.unwrap_or(<$T>::MAX)))
|
||||
}
|
||||
#[inline] pub fn point_inc (&mut self, n: $T) -> Option<$T> {
|
||||
self.point = self.point.map(|p|(p + n).min(self.clamp.unwrap_or(<$T>::MAX)));
|
||||
self.point = self.point_plus(n);
|
||||
self.point
|
||||
}
|
||||
#[inline] pub fn point_minus (&mut self, n: $T) -> Option<$T> {
|
||||
self.point.map(|p|p.saturating_sub(n))
|
||||
}
|
||||
#[inline] pub fn point_dec (&mut self, n: $T) -> Option<$T> {
|
||||
self.point = self.point.map(|p|p.saturating_sub(n));
|
||||
self.point = self.point_minus(n);
|
||||
self.point
|
||||
}
|
||||
}
|
||||
|
|
@ -871,9 +887,17 @@ impl<E: Engine, A: Widget<Engine = E>, B: Widget<Engine = E>> Widget for Split<E
|
|||
}
|
||||
|
||||
/// A widget that tracks its render width and height
|
||||
#[derive(Debug)]
|
||||
pub struct Measure<E: Engine>(PhantomData<E>, AtomicUsize, AtomicUsize);
|
||||
|
||||
impl<E: Engine> std::fmt::Debug for Measure<E> {
|
||||
fn fmt (&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
|
||||
f.debug_struct("Measure")
|
||||
.field("width", &self.0)
|
||||
.field("height", &self.1)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: Engine> Measure<E> {
|
||||
pub fn w (&self) -> usize { self.1.load(Ordering::Relaxed) }
|
||||
pub fn h (&self) -> usize { self.2.load(Ordering::Relaxed) }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue