center anchors on 0 0
This commit is contained in:
1 parent
848347e6b3
commit
f2cbf90d1d
7 files changed
+24
-20
No files matched your search
@@ -1,7 +1,7 @@
|
||||
use crate::primitive::{point::point, Point};
|
||||
use crate::primitive::{Point, point::point};
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, bytemuck::Pod, bytemuck::Zeroable, Default)]
|
||||
#[derive(Debug, Copy, Clone, bytemuck::Pod, bytemuck::Zeroable, Default)]
|
||||
pub struct UIPos {
|
||||
pub anchor: Point,
|
||||
pub offset: Point,
|
||||
@@ -16,7 +16,7 @@ impl UIPos {
|
||||
}
|
||||
|
||||
pub const fn top_left() -> Self {
|
||||
Self::anchor_offset(0.0, 0.0, 0.0, 0.0)
|
||||
Self::anchor_offset(-1.0, -1.0, 0.0, 0.0)
|
||||
}
|
||||
|
||||
pub const fn bottom_right() -> Self {
|
||||
@@ -24,15 +24,14 @@ impl UIPos {
|
||||
}
|
||||
|
||||
pub const fn within(&self, region: &UIRegion) -> UIPos {
|
||||
let range = region.bot_right.anchor - region.top_left.anchor;
|
||||
let region_offset = region
|
||||
.top_left
|
||||
.offset
|
||||
.lerp(region.bot_right.offset, self.anchor);
|
||||
UIPos {
|
||||
anchor: region.top_left.anchor + self.anchor * range,
|
||||
offset: self.offset + region_offset,
|
||||
}
|
||||
let lerp = self.anchor_01();
|
||||
let anchor = region.top_left.anchor.lerp(region.bot_right.anchor, lerp);
|
||||
let offset = self.offset + region.top_left.offset.lerp(region.bot_right.offset, lerp);
|
||||
UIPos { anchor, offset }
|
||||
}
|
||||
|
||||
pub const fn anchor_01(&self) -> Point {
|
||||
(self.anchor + 1.0) / 2.0
|
||||
}
|
||||
|
||||
pub fn axis_mut(&mut self, axis: Axis) -> UIPosAxisView<'_> {
|
||||
|
||||
Reference in new issue
Block a user