summaryrefslogtreecommitdiff
path: root/src/layout/frame.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-10-17 14:38:48 +0200
committerLaurenz <laurmaedje@gmail.com>2021-10-23 20:23:47 +0200
commit5becb32ba463d6b0ace914ab06bb237483a94fbc (patch)
tree684efb242ddb04e71c54f9665cc59891f734e518 /src/layout/frame.rs
parentc627847cb39572c08f3b53db07ea325ef0d352fa (diff)
Introduce page / block / inline levels
Diffstat (limited to 'src/layout/frame.rs')
-rw-r--r--src/layout/frame.rs178
1 files changed, 89 insertions, 89 deletions
diff --git a/src/layout/frame.rs b/src/layout/frame.rs
index 0e986fe4..82f60e22 100644
--- a/src/layout/frame.rs
+++ b/src/layout/frame.rs
@@ -19,69 +19,6 @@ pub struct Frame {
pub children: Vec<(Point, FrameChild)>,
}
-/// A frame can contain two different kinds of children: a leaf element or a
-/// nested frame.
-#[derive(Clone, Eq, PartialEq, Serialize, Deserialize)]
-pub enum FrameChild {
- /// A leaf node in the frame tree.
- Element(Element),
- /// An interior group.
- Group(Rc<Frame>),
-}
-
-/// The building block frames are composed of.
-#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
-pub enum Element {
- /// Shaped text.
- Text(Text),
- /// A geometric shape and the paint which with it should be filled or
- /// stroked (which one depends on the kind of geometry).
- Geometry(Geometry, Paint),
- /// A raster image.
- Image(ImageId, Size),
- /// A link to an external resource.
- Link(String, Size),
-}
-
-/// A run of shaped text.
-#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
-pub struct Text {
- /// The font face the glyphs are contained in.
- pub face_id: FaceId,
- /// The font size.
- pub size: Length,
- /// The width of the text run.
- pub width: Length,
- /// Glyph color.
- pub fill: Paint,
- /// The glyphs.
- pub glyphs: Vec<Glyph>,
-}
-
-/// A glyph in a run of shaped text.
-#[derive(Debug, Copy, Clone, Eq, PartialEq, Serialize, Deserialize)]
-pub struct Glyph {
- /// The glyph's index in the face.
- pub id: u16,
- /// The advance width of the glyph.
- pub x_advance: Em,
- /// The horizontal offset of the glyph.
- pub x_offset: Em,
-}
-
-/// A geometric shape.
-#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
-pub enum Geometry {
- /// A filled rectangle with its origin in the topleft corner.
- Rect(Size),
- /// A filled ellipse with its origin in the center.
- Ellipse(Size),
- /// A stroked line to a point (relative to its position) with a thickness.
- Line(Point, Length),
- /// A filled bezier path.
- Path(Path),
-}
-
impl Frame {
/// Create a new, empty frame.
#[track_caller]
@@ -117,15 +54,52 @@ impl Frame {
}
}
- /// Wrap the frame with constraints.
- pub fn constrain(self, constraints: Constraints) -> Constrained<Rc<Self>> {
- Constrained { item: Rc::new(self), constraints }
- }
-
/// An iterator over all elements in the frame and its children.
pub fn elements(&self) -> Elements {
Elements { stack: vec![(0, Point::zero(), self)] }
}
+
+ /// Wrap the frame with constraints.
+ pub fn constrain(self, cts: Constraints) -> Constrained<Rc<Self>> {
+ Constrained { item: Rc::new(self), cts }
+ }
+}
+
+impl Debug for Frame {
+ fn fmt(&self, f: &mut Formatter) -> fmt::Result {
+ struct Children<'a>(&'a [(Point, FrameChild)]);
+
+ impl Debug for Children<'_> {
+ fn fmt(&self, f: &mut Formatter) -> fmt::Result {
+ f.debug_map().entries(self.0.iter().map(|(k, v)| (k, v))).finish()
+ }
+ }
+
+ f.debug_struct("Frame")
+ .field("size", &self.size)
+ .field("baseline", &self.baseline)
+ .field("children", &Children(&self.children))
+ .finish()
+ }
+}
+
+/// A frame can contain two different kinds of children: a leaf element or a
+/// nested frame.
+#[derive(Clone, Eq, PartialEq, Serialize, Deserialize)]
+pub enum FrameChild {
+ /// A leaf node in the frame tree.
+ Element(Element),
+ /// An interior group.
+ Group(Rc<Frame>),
+}
+
+impl Debug for FrameChild {
+ fn fmt(&self, f: &mut Formatter) -> fmt::Result {
+ match self {
+ Self::Element(element) => element.fmt(f),
+ Self::Group(frame) => frame.fmt(f),
+ }
+ }
}
/// An iterator over all elements in a frame, alongside with their positions.
@@ -159,29 +133,55 @@ impl<'a> Iterator for Elements<'a> {
}
}
-impl Debug for Frame {
- fn fmt(&self, f: &mut Formatter) -> fmt::Result {
- struct Children<'a>(&'a [(Point, FrameChild)]);
+/// The building block frames are composed of.
+#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
+pub enum Element {
+ /// Shaped text.
+ Text(Text),
+ /// A geometric shape and the paint which with it should be filled or
+ /// stroked (which one depends on the kind of geometry).
+ Geometry(Geometry, Paint),
+ /// A raster image.
+ Image(ImageId, Size),
+ /// A link to an external resource.
+ Link(String, Size),
+}
- impl Debug for Children<'_> {
- fn fmt(&self, f: &mut Formatter) -> fmt::Result {
- f.debug_map().entries(self.0.iter().map(|(k, v)| (k, v))).finish()
- }
- }
+/// A run of shaped text.
+#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
+pub struct Text {
+ /// The font face the glyphs are contained in.
+ pub face_id: FaceId,
+ /// The font size.
+ pub size: Length,
+ /// The width of the text run.
+ pub width: Length,
+ /// Glyph color.
+ pub fill: Paint,
+ /// The glyphs.
+ pub glyphs: Vec<Glyph>,
+}
- f.debug_struct("Frame")
- .field("size", &self.size)
- .field("baseline", &self.baseline)
- .field("children", &Children(&self.children))
- .finish()
- }
+/// A glyph in a run of shaped text.
+#[derive(Debug, Copy, Clone, Eq, PartialEq, Serialize, Deserialize)]
+pub struct Glyph {
+ /// The glyph's index in the face.
+ pub id: u16,
+ /// The advance width of the glyph.
+ pub x_advance: Em,
+ /// The horizontal offset of the glyph.
+ pub x_offset: Em,
}
-impl Debug for FrameChild {
- fn fmt(&self, f: &mut Formatter) -> fmt::Result {
- match self {
- Self::Element(element) => element.fmt(f),
- Self::Group(frame) => frame.fmt(f),
- }
- }
+/// A geometric shape.
+#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
+pub enum Geometry {
+ /// A filled rectangle with its origin in the topleft corner.
+ Rect(Size),
+ /// A filled ellipse with its origin in the center.
+ Ellipse(Size),
+ /// A stroked line to a point (relative to its position) with a thickness.
+ Line(Point, Length),
+ /// A filled bezier path.
+ Path(Path),
}