diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-08-21 16:38:51 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-08-21 17:30:21 +0200 |
| commit | 0dd4ae0a7ac0c247078df492469ff20b8a90c886 (patch) | |
| tree | 07a55343b9ccab3fe76b0f1b0de9d1be310d8b14 /src/layout | |
| parent | f38eb10c2b54bd13ccef119454839f6a66448462 (diff) | |
Prune derives
Diffstat (limited to 'src/layout')
| -rw-r--r-- | src/layout/background.rs | 1 | ||||
| -rw-r--r-- | src/layout/constraints.rs | 10 | ||||
| -rw-r--r-- | src/layout/fixed.rs | 3 | ||||
| -rw-r--r-- | src/layout/grid.rs | 5 | ||||
| -rw-r--r-- | src/layout/image.rs | 1 | ||||
| -rw-r--r-- | src/layout/pad.rs | 1 | ||||
| -rw-r--r-- | src/layout/par.rs | 15 | ||||
| -rw-r--r-- | src/layout/shaping.rs | 87 | ||||
| -rw-r--r-- | src/layout/stack.rs | 2 | ||||
| -rw-r--r-- | src/layout/tree.rs | 60 |
10 files changed, 45 insertions, 140 deletions
diff --git a/src/layout/background.rs b/src/layout/background.rs index 793782fd..306afd67 100644 --- a/src/layout/background.rs +++ b/src/layout/background.rs @@ -1,7 +1,6 @@ use super::*; /// A node that places a rectangular filled background behind its child. -#[derive(Debug, Clone, Eq, PartialEq)] #[cfg_attr(feature = "layout-cache", derive(Hash))] pub struct BackgroundNode { /// The kind of shape to use as a background. diff --git a/src/layout/constraints.rs b/src/layout/constraints.rs index 1a26daeb..d808abd9 100644 --- a/src/layout/constraints.rs +++ b/src/layout/constraints.rs @@ -1,5 +1,3 @@ -use std::ops::Deref; - use super::*; /// Carries an item that is only valid in certain regions and the constraints @@ -12,14 +10,6 @@ pub struct Constrained<T> { pub constraints: Constraints, } -impl<T> Deref for Constrained<T> { - type Target = T; - - fn deref(&self) -> &Self::Target { - &self.item - } -} - /// Describe regions that match them. #[derive(Debug, Copy, Clone, Eq, PartialEq)] pub struct Constraints { diff --git a/src/layout/fixed.rs b/src/layout/fixed.rs index 7f292f14..02660d1d 100644 --- a/src/layout/fixed.rs +++ b/src/layout/fixed.rs @@ -3,7 +3,6 @@ use decorum::N64; use super::*; /// A node that can fix its child's width and height. -#[derive(Debug, Clone, Eq, PartialEq)] #[cfg_attr(feature = "layout-cache", derive(Hash))] pub struct FixedNode { /// The fixed width, if any. @@ -78,7 +77,7 @@ impl Layout for FixedNode { // relayout with expansion. if let Some(aspect) = aspect { if width.is_none() && height.is_none() { - let needed = frames[0].size.cap(size); + let needed = frames[0].item.size.cap(size); let width = needed.width.max(aspect * needed.height); regions.current = Size::new(width, width / aspect); regions.expand = Spec::splat(true); diff --git a/src/layout/grid.rs b/src/layout/grid.rs index d9b56b48..b4a1fe79 100644 --- a/src/layout/grid.rs +++ b/src/layout/grid.rs @@ -1,7 +1,6 @@ use super::*; /// A node that arranges its children in a grid. -#[derive(Debug, Clone, Eq, PartialEq)] #[cfg_attr(feature = "layout-cache", derive(Hash))] pub struct GridNode { /// The `main` and `cross` directions of this grid. @@ -256,7 +255,7 @@ impl<'a> GridLayouter<'a> { for node in (0 .. self.rows.len()).filter_map(|y| self.cell(x, y)) { let size = Gen::new(available, Length::inf()).to_size(self.main); let regions = Regions::one(size, size, Spec::splat(false)); - let frame = node.layout(ctx, ®ions).remove(0); + let frame = node.layout(ctx, ®ions).remove(0).item; resolved.set_max(frame.size.get(self.cross)); } @@ -353,7 +352,7 @@ impl<'a> GridLayouter<'a> { let mut sizes = node .layout(ctx, &self.regions) .into_iter() - .map(|frame| frame.size.get(self.main)); + .map(|frame| frame.item.size.get(self.main)); if let Some(size) = sizes.next() { first.set_max(size); diff --git a/src/layout/image.rs b/src/layout/image.rs index 02a907f5..e3e5e741 100644 --- a/src/layout/image.rs +++ b/src/layout/image.rs @@ -4,7 +4,6 @@ use crate::image::ImageId; use ::image::GenericImageView; /// An image node. -#[derive(Debug, Copy, Clone, Eq, PartialEq)] #[cfg_attr(feature = "layout-cache", derive(Hash))] pub struct ImageNode { /// The id of the image file. diff --git a/src/layout/pad.rs b/src/layout/pad.rs index 51025e3c..3075472b 100644 --- a/src/layout/pad.rs +++ b/src/layout/pad.rs @@ -1,7 +1,6 @@ use super::*; /// A node that adds padding to its child. -#[derive(Debug, Clone, Eq, PartialEq)] #[cfg_attr(feature = "layout-cache", derive(Hash))] pub struct PadNode { /// The amount of padding. diff --git a/src/layout/par.rs b/src/layout/par.rs index 317a91ad..84d784b0 100644 --- a/src/layout/par.rs +++ b/src/layout/par.rs @@ -1,4 +1,3 @@ -use std::fmt::{self, Debug, Formatter}; use std::rc::Rc; use unicode_bidi::{BidiInfo, Level}; @@ -11,7 +10,6 @@ use crate::util::{EcoString, RangeExt, SliceExt}; type Range = std::ops::Range<usize>; /// A node that arranges its children into a paragraph. -#[derive(Debug, Clone, Eq, PartialEq)] #[cfg_attr(feature = "layout-cache", derive(Hash))] pub struct ParNode { /// The inline direction of this paragraph. @@ -23,7 +21,6 @@ pub struct ParNode { } /// A child of a paragraph node. -#[derive(Clone, Eq, PartialEq)] #[cfg_attr(feature = "layout-cache", derive(Hash))] pub enum ParChild { /// Spacing between other nodes. @@ -94,18 +91,6 @@ impl From<ParNode> for LayoutNode { } } -impl Debug for ParChild { - fn fmt(&self, f: &mut Formatter) -> fmt::Result { - match self { - Self::Spacing(amount) => write!(f, "Spacing({:?})", amount), - Self::Text(text, align, _) => write!(f, "Text({:?}, {:?})", text, align), - Self::Any(any, align) => { - f.debug_tuple("Any").field(any).field(align).finish() - } - } - } -} - /// A paragraph representation in which children are already layouted and text /// is separated into shapable runs. struct ParLayouter<'a> { diff --git a/src/layout/shaping.rs b/src/layout/shaping.rs index ba8704ea..fad7f234 100644 --- a/src/layout/shaping.rs +++ b/src/layout/shaping.rs @@ -1,5 +1,4 @@ use std::borrow::Cow; -use std::fmt::{self, Debug, Formatter}; use std::ops::Range; use rustybuzz::UnicodeBuffer; @@ -11,12 +10,45 @@ use crate::geom::{Dir, Length, Point, Size}; use crate::layout::Geometry; use crate::util::SliceExt; +/// Shape text into [`ShapedText`]. +pub fn shape<'a>( + ctx: &mut LayoutContext, + text: &'a str, + dir: Dir, + state: &'a FontState, +) -> ShapedText<'a> { + let mut glyphs = vec![]; + if !text.is_empty() { + shape_segment( + ctx, + &mut glyphs, + 0, + text, + dir, + state.size, + state.variant(), + state.families(), + None, + ); + } + + let (size, baseline) = measure(ctx, &glyphs, state); + + ShapedText { + text, + dir, + state, + size, + baseline, + glyphs: Cow::Owned(glyphs), + } +} + /// The result of shaping text. /// /// This type contains owned or borrowed shaped text runs, which can be /// measured, used to reshape substrings more quickly and converted into a /// frame. -#[derive(Clone)] pub struct ShapedText<'a> { /// The text that was shaped. pub text: &'a str, @@ -33,7 +65,7 @@ pub struct ShapedText<'a> { } /// A single glyph resulting from shaping. -#[derive(Debug, Copy, Clone)] +#[derive(Copy, Clone)] pub struct ShapedGlyph { /// The font face the glyph is contained in. pub face_id: FaceId, @@ -51,13 +83,6 @@ pub struct ShapedGlyph { pub safe_to_break: bool, } -/// A visual side. -#[derive(Debug, Copy, Clone, Eq, PartialEq)] -enum Side { - Left, - Right, -} - impl<'a> ShapedText<'a> { /// Build the shaped text's frame. pub fn build(&self, ctx: &LayoutContext) -> Frame { @@ -174,44 +199,10 @@ impl<'a> ShapedText<'a> { } } -impl Debug for ShapedText<'_> { - fn fmt(&self, f: &mut Formatter) -> fmt::Result { - write!(f, "Shaped({:?})", self.text) - } -} - -/// Shape text into [`ShapedText`]. -pub fn shape<'a>( - ctx: &mut LayoutContext, - text: &'a str, - dir: Dir, - state: &'a FontState, -) -> ShapedText<'a> { - let mut glyphs = vec![]; - if !text.is_empty() { - shape_segment( - ctx, - &mut glyphs, - 0, - text, - dir, - state.size, - state.variant(), - state.families(), - None, - ); - } - - let (size, baseline) = measure(ctx, &glyphs, state); - - ShapedText { - text, - dir, - state, - size, - baseline, - glyphs: Cow::Owned(glyphs), - } +/// A visual side. +enum Side { + Left, + Right, } /// Shape text with font fallback using the `families` iterator. diff --git a/src/layout/stack.rs b/src/layout/stack.rs index 51d17807..d07f68d7 100644 --- a/src/layout/stack.rs +++ b/src/layout/stack.rs @@ -1,7 +1,6 @@ use super::*; /// A node that stacks its children. -#[derive(Debug, Clone, Eq, PartialEq)] #[cfg_attr(feature = "layout-cache", derive(Hash))] pub struct StackNode { /// The `main` and `cross` directions of this stack. @@ -14,7 +13,6 @@ pub struct StackNode { } /// A child of a stack node. -#[derive(Debug, Clone, Eq, PartialEq)] #[cfg_attr(feature = "layout-cache", derive(Hash))] pub enum StackChild { /// Spacing between other nodes. diff --git a/src/layout/tree.rs b/src/layout/tree.rs index 1899a4d2..05f94c38 100644 --- a/src/layout/tree.rs +++ b/src/layout/tree.rs @@ -1,7 +1,6 @@ use super::*; use std::any::Any; -use std::fmt::{self, Debug, Formatter}; #[cfg(feature = "layout-cache")] use std::hash::{Hash, Hasher}; @@ -10,7 +9,6 @@ use std::hash::{Hash, Hasher}; use fxhash::FxHasher64; /// A tree of layout nodes. -#[derive(Debug, Clone, Eq, PartialEq)] pub struct LayoutTree { /// Runs of pages with the same properties. pub runs: Vec<PageRun>, @@ -24,7 +22,6 @@ impl LayoutTree { } /// A run of pages that all have the same properties. -#[derive(Debug, Clone, Eq, PartialEq)] pub struct PageRun { /// The size of each page. pub size: Size, @@ -47,7 +44,7 @@ impl PageRun { /// A dynamic layouting node. pub struct LayoutNode { - node: Box<dyn Bounds>, + node: Box<dyn Layout>, #[cfg(feature = "layout-cache")] hash: u64, } @@ -57,7 +54,7 @@ impl LayoutNode { #[cfg(not(feature = "layout-cache"))] pub fn new<T>(node: T) -> Self where - T: Layout + Debug + Clone + Eq + PartialEq + 'static, + T: Layout + 'static, { Self { node: Box::new(node) } } @@ -66,7 +63,7 @@ impl LayoutNode { #[cfg(feature = "layout-cache")] pub fn new<T>(node: T) -> Self where - T: Layout + Debug + Clone + Eq + PartialEq + Hash + 'static, + T: Layout + Hash + 'static, { let hash = { let mut state = FxHasher64::default(); @@ -99,60 +96,9 @@ impl Layout for LayoutNode { } } -impl Debug for LayoutNode { - fn fmt(&self, f: &mut Formatter) -> fmt::Result { - self.node.fmt(f) - } -} - -impl Clone for LayoutNode { - fn clone(&self) -> Self { - Self { - node: self.node.dyn_clone(), - #[cfg(feature = "layout-cache")] - hash: self.hash, - } - } -} - -impl Eq for LayoutNode {} - -impl PartialEq for LayoutNode { - fn eq(&self, other: &Self) -> bool { - self.node.dyn_eq(other.node.as_ref()) - } -} - #[cfg(feature = "layout-cache")] impl Hash for LayoutNode { fn hash<H: Hasher>(&self, state: &mut H) { state.write_u64(self.hash); } } - -trait Bounds: Layout + Debug + 'static { - fn as_any(&self) -> &dyn Any; - fn dyn_eq(&self, other: &dyn Bounds) -> bool; - fn dyn_clone(&self) -> Box<dyn Bounds>; -} - -impl<T> Bounds for T -where - T: Layout + Debug + Eq + PartialEq + Clone + 'static, -{ - fn as_any(&self) -> &dyn Any { - self - } - - fn dyn_eq(&self, other: &dyn Bounds) -> bool { - if let Some(other) = other.as_any().downcast_ref::<Self>() { - self == other - } else { - false - } - } - - fn dyn_clone(&self) -> Box<dyn Bounds> { - Box::new(self.clone()) - } -} |
