From 23a5ccd05ecb3a00437fc748310222942e0d1e26 Mon Sep 17 00:00:00 2001 From: Shadow Cat Date: Mon, 11 Aug 2025 02:41:14 -0400 Subject: [PATCH] span direction (sign) now works --- src/base/span.rs | 5 ++++- src/layout/region.rs | 24 ++++++++++++++++++++---- src/testing/mod.rs | 2 +- src/util/math.rs | 9 +++++++++ 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/base/span.rs b/src/base/span.rs index 8c6e2fe..2500f07 100644 --- a/src/base/span.rs +++ b/src/base/span.rs @@ -1,4 +1,4 @@ -use crate::{Dir, Painter, UINum, UIRegion, UIScalar, Widget, WidgetId}; +use crate::{Dir, Painter, Sign, UINum, UIRegion, UIScalar, Widget, WidgetId}; pub struct Span { pub children: Vec<(WidgetId, SpanLen)>, @@ -30,6 +30,9 @@ impl Widget for Span { axis.bot_right.set(start); } } + if self.dir.sign == Sign::Neg { + child_region.flip(); + } painter.draw_within(child, child_region); } } diff --git a/src/layout/region.rs b/src/layout/region.rs index a21e770..76427fe 100644 --- a/src/layout/region.rs +++ b/src/layout/region.rs @@ -40,10 +40,10 @@ impl UIPos { let anchor = self .anchor .lerp(region.top_left.anchor, region.bot_right.anchor); - let offset = self.offset; - // + self - // .anchor - // .lerp(region.top_left.offset, region.bot_right.offset); + let offset = self.offset + + self + .anchor + .lerp(region.top_left.offset, region.bot_right.offset); UIPos { anchor, offset } } @@ -59,6 +59,16 @@ impl UIPos { }, } } + + pub fn flip(&mut self) { + self.anchor = 1.0 - self.anchor; + self.offset = -self.offset; + } + + pub fn flipped(mut self) -> Self { + self.flip(); + self + } } #[derive(Clone, Copy, Debug)] @@ -133,6 +143,12 @@ impl UIRegion { bot_right: self.bot_right.axis_mut(axis), } } + + pub fn flip(&mut self) { + self.top_left.flip(); + self.bot_right.flip(); + std::mem::swap(&mut self.top_left, &mut self.bot_right); + } } pub struct UIRegionAxisView<'a> { diff --git a/src/testing/mod.rs b/src/testing/mod.rs index e0f6d2b..b4978d7 100644 --- a/src/testing/mod.rs +++ b/src/testing/mod.rs @@ -54,7 +54,7 @@ impl Client { rect.color(UIColor::RED), ) .span( - Dir::RIGHT, + Dir::LEFT, [ fixed(100), ratio(1), diff --git a/src/util/math.rs b/src/util/math.rs index caeeb27..fdf7189 100644 --- a/src/util/math.rs +++ b/src/util/math.rs @@ -40,6 +40,15 @@ macro_rules! impl_op { } } } + impl const $op<$T> for f32 { + type Output = $T; + + fn $fn(self, rhs: $T) -> Self::Output { + $T { + $($field: self.$fn(rhs.$field),)* + } + } + } impl $opa for $T { fn $fna(&mut self, rhs: f32) { $(self.$field.$fna(rhs);)*