From d430996e14a7ee7377db91cb90f6198249cffe6b Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Fri, 22 Mar 2024 19:35:00 +0100 Subject: [PATCH] impl from stuff --- hui/src/frame.rs | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/hui/src/frame.rs b/hui/src/frame.rs index c4a8934..ee8fb66 100644 --- a/hui/src/frame.rs +++ b/hui/src/frame.rs @@ -1,5 +1,3 @@ -//TODO finish dis - use glam::{Vec2, vec2}; use derive_more::{Add, AddAssign, Sub, SubAssign}; use crate::{ @@ -8,6 +6,8 @@ use crate::{ layout::{Size, Size2d} }; +//TODO finish dis, slider component would be a great place to test it + /// Point inside a frame /// /// Can be absolute, relative, or a combination of both\ @@ -21,6 +21,12 @@ pub struct FramePoint { pub relative: f32, } +impl From for FramePoint { + fn from(value: f32) -> Self { + Self::absolute(value) + } +} + impl From for FramePoint { /// Convert a `Size` into a `FramePoint` /// @@ -76,11 +82,27 @@ impl FramePoint { } } +#[derive(Clone, Copy, Debug, Default, Add, AddAssign, Sub, SubAssign)] pub struct FramePoint2d { pub x: FramePoint, pub y: FramePoint, } +impl From<(FramePoint, FramePoint)> for FramePoint2d { + fn from((x, y): (FramePoint, FramePoint)) -> Self { + Self { x, y } + } +} + +impl From for FramePoint2d { + fn from(size: Size) -> Self { + Self { + x: size.into(), + y: size.into(), + } + } +} + impl From for FramePoint2d { fn from(size: Size2d) -> Self { Self { @@ -90,6 +112,24 @@ impl From for FramePoint2d { } } +impl From<(f32, f32)> for FramePoint2d { + fn from((x, y): (f32, f32)) -> Self { + Self { + x: FramePoint::absolute(x), + y: FramePoint::absolute(y), + } + } +} + +impl From for FramePoint2d { + fn from(vec: Vec2) -> Self { + Self { + x: FramePoint::absolute(vec.x), + y: FramePoint::absolute(vec.y), + } + } +} + impl FramePoint2d { pub const TOP_LEFT: Self = Self { x: FramePoint::BEGIN,