impl from stuff

This commit is contained in:
griffi-gh 2024-03-22 19:35:00 +01:00
parent 388b71ebd0
commit 918597585d

View file

@ -1,5 +1,3 @@
//TODO finish dis
use glam::{Vec2, vec2}; use glam::{Vec2, vec2};
use derive_more::{Add, AddAssign, Sub, SubAssign}; use derive_more::{Add, AddAssign, Sub, SubAssign};
use crate::{ use crate::{
@ -8,6 +6,8 @@ use crate::{
layout::{Size, Size2d} layout::{Size, Size2d}
}; };
//TODO finish dis, slider component would be a great place to test it
/// Point inside a frame /// Point inside a frame
/// ///
/// Can be absolute, relative, or a combination of both\ /// Can be absolute, relative, or a combination of both\
@ -21,6 +21,12 @@ pub struct FramePoint {
pub relative: f32, pub relative: f32,
} }
impl From<f32> for FramePoint {
fn from(value: f32) -> Self {
Self::absolute(value)
}
}
impl From<Size> for FramePoint { impl From<Size> for FramePoint {
/// Convert a `Size` into a `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 struct FramePoint2d {
pub x: FramePoint, pub x: FramePoint,
pub y: FramePoint, pub y: FramePoint,
} }
impl From<(FramePoint, FramePoint)> for FramePoint2d {
fn from((x, y): (FramePoint, FramePoint)) -> Self {
Self { x, y }
}
}
impl From<Size> for FramePoint2d {
fn from(size: Size) -> Self {
Self {
x: size.into(),
y: size.into(),
}
}
}
impl From<Size2d> for FramePoint2d { impl From<Size2d> for FramePoint2d {
fn from(size: Size2d) -> Self { fn from(size: Size2d) -> Self {
Self { Self {
@ -90,6 +112,24 @@ impl From<Size2d> 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<Vec2> for FramePoint2d {
fn from(vec: Vec2) -> Self {
Self {
x: FramePoint::absolute(vec.x),
y: FramePoint::absolute(vec.y),
}
}
}
impl FramePoint2d { impl FramePoint2d {
pub const TOP_LEFT: Self = Self { pub const TOP_LEFT: Self = Self {
x: FramePoint::BEGIN, x: FramePoint::BEGIN,