GRID SNAP!

This commit is contained in:
RustyStriker 2022-08-04 17:50:21 +03:00
parent 10b120512f
commit f76cab4129
5 changed files with 66 additions and 11 deletions

View file

@ -7,11 +7,35 @@ pub mod create;
pub mod helpers;
pub mod modify;
pub mod ui;
pub use ui::{action_bar_sys, shape_tree_sys};
pub use modify::modify_sys;
pub use create::create_sys;
pub use helpers::*;
#[derive(Debug, Clone)]
pub struct SnapGrid {
pub width: f32,
pub height: f32,
pub snap: bool,
pub offset: Vec2,
}
impl SnapGrid {
pub fn snap_to_grid(&self, v: Vec2) -> Vec2 {
if self.snap {
let w = v - self.offset;
let snapped = Vec2::new(w.x - w.x % self.width, w.y - w.y % self.height);
snapped + self.offset
}
else {
v
}
}
}
impl Default for SnapGrid {
fn default() -> Self {
Self { width: 15.0, height: 15.0, snap: false, offset: Vec2::ZERO }
}
}
#[derive(Clone, Debug)]
pub struct PointSize(pub f32);