From fd0b89a1d8e4f811fcf3517d321a327a0cf72edf Mon Sep 17 00:00:00 2001 From: Laurenz Date: Thu, 8 Jul 2021 22:33:44 +0200 Subject: Rename Fill to Paint --- src/layout/background.rs | 15 ++++++--------- src/layout/frame.rs | 23 ++++++++++++----------- src/layout/shaping.rs | 6 ++---- 3 files changed, 20 insertions(+), 24 deletions(-) (limited to 'src/layout') diff --git a/src/layout/background.rs b/src/layout/background.rs index 013a887a..0e93c06f 100644 --- a/src/layout/background.rs +++ b/src/layout/background.rs @@ -6,8 +6,8 @@ use super::*; pub struct BackgroundNode { /// The kind of shape to use as a background. pub shape: BackgroundShape, - /// The background fill. - pub fill: Fill, + /// Background color / texture. + pub fill: Paint, /// The child node to be filled. pub child: AnyNode, } @@ -29,19 +29,16 @@ impl Layout for BackgroundNode { for frame in &mut frames { let mut new = Frame::new(frame.size, frame.baseline); - let (point, shape) = match self.shape { - BackgroundShape::Rect => (Point::zero(), Shape::Rect(frame.size)), + let (point, geometry) = match self.shape { + BackgroundShape::Rect => (Point::zero(), Geometry::Rect(frame.size)), BackgroundShape::Ellipse => { - (frame.size.to_point() / 2.0, Shape::Ellipse(frame.size)) + (frame.size.to_point() / 2.0, Geometry::Ellipse(frame.size)) } }; - let element = Element::Geometry(shape, self.fill); - new.push(point, element); - let prev = std::mem::take(&mut frame.item); + new.push(point, Element::Geometry(geometry, self.fill)); new.push_frame(Point::zero(), prev); - *Rc::make_mut(&mut frame.item) = new; } frames diff --git a/src/layout/frame.rs b/src/layout/frame.rs index b6cf4645..65a55857 100644 --- a/src/layout/frame.rs +++ b/src/layout/frame.rs @@ -110,8 +110,9 @@ enum Child { pub enum Element { /// Shaped text. Text(Text), - /// A filled geometric shape. - Geometry(Shape, Fill), + /// A geometric shape and the paint which with it should be filled or + /// stroked. + Geometry(Geometry, Paint), /// A raster image. Image(ImageId, Size), } @@ -123,8 +124,8 @@ pub struct Text { pub face_id: FaceId, /// The font size. pub size: Length, - /// The glyph's fill color. - pub fill: Fill, + /// Glyph color. + pub fill: Paint, /// The glyphs. pub glyphs: Vec, } @@ -155,20 +156,20 @@ impl Text { /// A geometric shape. #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] -pub enum Shape { - /// A rectangle with its origin in the topleft corner. +pub enum Geometry { + /// A filled rectangle with its origin in the topleft corner. Rect(Size), - /// An ellipse with its origin in the center. + /// A filled ellipse with its origin in the center. Ellipse(Size), - /// A line to a `Point` (relative to its position) with a stroke width. + /// A stroked line to a point (relative to its position) with a thickness. Line(Point, Length), - /// A bezier path. + /// A filled bezier path. Path(Path), } -/// How text and shapes are filled. +/// How a fill or stroke should be painted. #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)] -pub enum Fill { +pub enum Paint { /// A solid color. Color(Color), } diff --git a/src/layout/shaping.rs b/src/layout/shaping.rs index c37300f7..9b8774cc 100644 --- a/src/layout/shaping.rs +++ b/src/layout/shaping.rs @@ -8,7 +8,7 @@ use super::{Element, Frame, Glyph, LayoutContext, Text}; use crate::exec::{FontState, LineState}; use crate::font::{Face, FaceId, FontStyle, LineMetrics}; use crate::geom::{Dir, Length, Point, Size}; -use crate::layout::Shape; +use crate::layout::Geometry; use crate::util::SliceExt; /// The result of shaping text. @@ -412,9 +412,7 @@ fn decorate( let pos = Point::new(pos.x - extent, pos.y + offset); let target = Point::new(width + 2.0 * extent, Length::zero()); - let shape = Shape::Line(target, thickness); - let element = Element::Geometry(shape, stroke); - + let element = Element::Geometry(Geometry::Line(target, thickness), stroke); frame.push(pos, element); }; -- cgit v1.2.3