From b1b4e52af9e2da8f8ae1fc17a81ed6cbcbb8f525 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Mon, 13 Feb 2023 15:14:25 +0100 Subject: Block sizing --- src/doc.rs | 20 ++++++++++++-------- src/geom/mod.rs | 4 ++-- src/geom/path.rs | 4 ++-- 3 files changed, 16 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/doc.rs b/src/doc.rs index a15fbca9..0ca930bf 100644 --- a/src/doc.rs +++ b/src/doc.rs @@ -17,7 +17,7 @@ use crate::model::{ use crate::util::EcoString; /// A finished document with metadata and page frames. -#[derive(Debug, Default, Clone)] +#[derive(Debug, Default, Clone, Hash)] pub struct Document { /// The page frames. pub pages: Vec, @@ -28,7 +28,7 @@ pub struct Document { } /// A finished layout with elements at fixed positions. -#[derive(Default, Clone)] +#[derive(Default, Clone, Hash)] pub struct Frame { /// The size of the frame. size: Size, @@ -304,12 +304,16 @@ impl Frame { /// Arbitrarily transform the contents of the frame. pub fn transform(&mut self, transform: Transform) { - self.group(|g| g.transform = transform); + if !self.is_empty() { + self.group(|g| g.transform = transform); + } } /// Clip the contents of a frame to its size. pub fn clip(&mut self) { - self.group(|g| g.clips = true); + if !self.is_empty() { + self.group(|g| g.clips = true); + } } /// Wrap the frame's contents in a group and modify that group with `f`. @@ -386,7 +390,7 @@ impl Debug for Frame { } /// The building block frames are composed of. -#[derive(Clone)] +#[derive(Clone, Hash)] pub enum Element { /// A group of elements. Group(Group), @@ -413,7 +417,7 @@ impl Debug for Element { } /// A group of elements with optional clipping. -#[derive(Clone)] +#[derive(Clone, Hash)] pub struct Group { /// The group's frame. pub frame: Frame, @@ -442,7 +446,7 @@ impl Debug for Group { } /// A run of shaped text. -#[derive(Clone, Eq, PartialEq)] +#[derive(Clone, Eq, PartialEq, Hash)] pub struct Text { /// The font the glyphs are contained in. pub font: Font, @@ -477,7 +481,7 @@ impl Debug for Text { } /// A glyph in a run of shaped text. -#[derive(Debug, Copy, Clone, Eq, PartialEq)] +#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] pub struct Glyph { /// The glyph's index in the font. pub id: u16, diff --git a/src/geom/mod.rs b/src/geom/mod.rs index 225eb10d..ebe4436c 100644 --- a/src/geom/mod.rs +++ b/src/geom/mod.rs @@ -73,7 +73,7 @@ pub trait Get { } /// A geometric shape with optional fill and stroke. -#[derive(Debug, Clone, Eq, PartialEq)] +#[derive(Debug, Clone, Eq, PartialEq, Hash)] pub struct Shape { /// The shape's geometry. pub geometry: Geometry, @@ -84,7 +84,7 @@ pub struct Shape { } /// A shape's geometry. -#[derive(Debug, Clone, Eq, PartialEq)] +#[derive(Debug, Clone, Eq, PartialEq, Hash)] pub enum Geometry { /// A line to a point (relative to its position). Line(Point), diff --git a/src/geom/path.rs b/src/geom/path.rs index ffd3db1c..3a7c3033 100644 --- a/src/geom/path.rs +++ b/src/geom/path.rs @@ -1,11 +1,11 @@ use super::*; /// A bezier path. -#[derive(Debug, Default, Clone, Eq, PartialEq)] +#[derive(Debug, Default, Clone, Eq, PartialEq, Hash)] pub struct Path(pub Vec); /// An element in a bezier path. -#[derive(Debug, Clone, Eq, PartialEq)] +#[derive(Debug, Clone, Eq, PartialEq, Hash)] pub enum PathElement { MoveTo(Point), LineTo(Point), -- cgit v1.2.3