mirror of
https://github.com/griffi-gh/hUI.git
synced 2024-12-22 12:28:19 -06:00
impl from stuff
This commit is contained in:
parent
a0dc882799
commit
d430996e14
|
@ -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<f32> for FramePoint {
|
||||
fn from(value: f32) -> Self {
|
||||
Self::absolute(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Size> 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<Size> for FramePoint2d {
|
||||
fn from(size: Size) -> Self {
|
||||
Self {
|
||||
x: size.into(),
|
||||
y: size.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Size2d> for FramePoint2d {
|
||||
fn from(size: Size2d) -> 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 {
|
||||
pub const TOP_LEFT: Self = Self {
|
||||
x: FramePoint::BEGIN,
|
||||
|
|
Loading…
Reference in a new issue