summaryrefslogtreecommitdiff
path: root/src/layout/boxed.rs
diff options
context:
space:
mode:
authorLaurenz Mädje <laurmaedje@gmail.com>2019-06-02 18:01:22 +0200
committerLaurenz Mädje <laurmaedje@gmail.com>2019-06-02 18:01:22 +0200
commit221934df4b586250b0063282ef8885c475dec7a7 (patch)
treeea91eb6fe6fbad71377f2dbf1c23a3a808dbf970 /src/layout/boxed.rs
parentc4eb4ee36261be8832b2649cc075edee188be5c7 (diff)
Add margins with basic box layouter 📖
Diffstat (limited to 'src/layout/boxed.rs')
-rw-r--r--src/layout/boxed.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/layout/boxed.rs b/src/layout/boxed.rs
new file mode 100644
index 00000000..cfdf51f2
--- /dev/null
+++ b/src/layout/boxed.rs
@@ -0,0 +1,37 @@
+//! Layouting of layout boxes.
+
+use crate::doc::TextAction;
+use super::{Layouter, Layout, LayoutContext, LayoutResult, Position};
+
+
+/// Layouts sublayouts within the constraints of a layouting context.
+#[derive(Debug)]
+pub struct BoxLayouter<'a, 'p> {
+ ctx: &'a LayoutContext<'a, 'p>,
+ actions: Vec<TextAction>,
+}
+
+impl<'a, 'p> BoxLayouter<'a, 'p> {
+ /// Create a new box layouter.
+ pub fn new(ctx: &'a LayoutContext<'a, 'p>) -> BoxLayouter<'a, 'p> {
+ BoxLayouter {
+ ctx,
+ actions: vec![],
+ }
+ }
+
+ /// Add a sublayout.
+ pub fn add_layout_absolute(&mut self, position: Position, layout: Layout) {
+ self.actions.push(TextAction::MoveNewline(position));
+ self.actions.extend(layout.actions);
+ }
+}
+
+impl Layouter for BoxLayouter<'_, '_> {
+ fn finish(self) -> LayoutResult<Layout> {
+ Ok(Layout {
+ extent: self.ctx.max_extent.clone(),
+ actions: self.actions
+ })
+ }
+}