#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Position {
Top,
Right,
Bottom,
Left,
Center,
Closest,
}
impl Position {
pub fn opposite(self) -> Self {
match self {
Position::Top => Position::Bottom,
Position::Bottom => Position::Top,
Position::Left => Position::Right,
Position::Right => Position::Left,
Position::Center => Position::Center,
Position::Closest => Position::Closest,
}
}
pub fn is_horizontal(self) -> bool {
matches!(self, Position::Left | Position::Right)
}
pub fn is_vertical(self) -> bool {
matches!(self, Position::Top | Position::Bottom)
}
pub fn resolve_closest(self, from_center: egui::Pos2, to_center: egui::Pos2) -> Position {
match self {
Position::Closest => {
let dx = to_center.x - from_center.x;
let dy = to_center.y - from_center.y;
if dx.abs() > dy.abs() {
if dx > 0.0 { Position::Right } else { Position::Left }
} else if dy > 0.0 {
Position::Bottom
} else {
Position::Top
}
}
other => other,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Dimensions {
pub width: f32,
pub height: f32,
}
impl Dimensions {
pub fn new(width: f32, height: f32) -> Self {
Self { width, height }
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CoordinateExtent {
pub min: egui::Pos2,
pub max: egui::Pos2,
}
impl CoordinateExtent {
pub const INFINITE: Self = Self {
min: egui::pos2(f32::NEG_INFINITY, f32::NEG_INFINITY),
max: egui::pos2(f32::INFINITY, f32::INFINITY),
};
pub fn new(min: egui::Pos2, max: egui::Pos2) -> Self {
Self { min, max }
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Transform {
pub x: f32,
pub y: f32,
pub scale: f32,
}
impl Default for Transform {
fn default() -> Self {
Self {
x: 0.0,
y: 0.0,
scale: 1.0,
}
}
}
pub type SnapGrid = [f32; 2];
pub type NodeOrigin = [f32; 2];