mirror of
https://github.com/penpot/penpot.git
synced 2026-07-01 20:05:26 +00:00
* ✨ Remove guides from svg overlay * 🎉 Draw guides in wasm * 🎉 Serialize guides to wasm * ✨ Store separate and sorted horizontal and vertical guides * 🎉 Implement collision detection with guides * 🎉 Right click on guides to change color or remove * ✨ Implement dragging guides * 🎉 Edit wasm guides by double clicking them * 🎉 Implement changing mouse cursor on hovering a guide * ✨ Show guide pill on hover * 🎉 Implement removing guide on hovering + Del * 🔧 Fix lint + fmt errors * 🎉 Clip out outer board guide lines * ♻️ Extract common code into guide-pill* component * 🎉 Draw dotted lines on hovering board guides * 🐛 Fix board rotation when it has guides * 🎉 Make foreign guides not visible in focus mode
58 lines
1.3 KiB
Rust
58 lines
1.3 KiB
Rust
use std::cmp::Ordering;
|
|
|
|
use crate::shapes::Color;
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
|
pub enum GuideKind {
|
|
Vertical(f32),
|
|
Horizontal(f32),
|
|
}
|
|
|
|
impl GuideKind {
|
|
fn value(self) -> f32 {
|
|
match self {
|
|
GuideKind::Vertical(x) => x,
|
|
GuideKind::Horizontal(y) => y,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl PartialOrd for GuideKind {
|
|
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
|
self.value().partial_cmp(&other.value())
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
|
pub struct Guide {
|
|
pub kind: GuideKind,
|
|
pub color: Color,
|
|
/// Index of the guide in the guide list (clojure side)
|
|
pub index: usize,
|
|
/// When the guide belongs to a board, the `[start, end]` range (along the
|
|
/// guide's line direction) of that board. The guide is drawn solid only
|
|
/// within this range and trimmed outside it. `None` for free guides, which
|
|
/// span the whole viewport.
|
|
pub frame_range: Option<(f32, f32)>,
|
|
}
|
|
|
|
impl Guide {
|
|
pub fn new(
|
|
kind: GuideKind,
|
|
color: Color,
|
|
index: Option<usize>,
|
|
frame_range: Option<(f32, f32)>,
|
|
) -> Self {
|
|
Self {
|
|
kind,
|
|
color,
|
|
index: index.unwrap_or_default(),
|
|
frame_range,
|
|
}
|
|
}
|
|
|
|
pub fn position(&self) -> f32 {
|
|
self.kind.value()
|
|
}
|
|
}
|