summaryrefslogtreecommitdiff
path: root/src/layout/boxed.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2019-06-17 10:08:16 +0200
committerLaurenz <laurmaedje@gmail.com>2019-06-17 10:08:16 +0200
commitb53ad6b1ec8b2fd05566a83c9b895f265e61d281 (patch)
tree1c6d590ead7180fbef12915cfcd04418c9ea7902 /src/layout/boxed.rs
parent236ebab23a106ca817de527ce6b6440d3b66c150 (diff)
Introduce flex layouting 🎈
Diffstat (limited to 'src/layout/boxed.rs')
-rw-r--r--src/layout/boxed.rs54
1 files changed, 45 insertions, 9 deletions
diff --git a/src/layout/boxed.rs b/src/layout/boxed.rs
index c240db0b..b75ea75a 100644
--- a/src/layout/boxed.rs
+++ b/src/layout/boxed.rs
@@ -1,10 +1,34 @@
-//! Layouting of layout boxes.
+//! Definitive layouting of boxes.
-use crate::doc::TextAction;
-use super::{Layouter, Layout, LayoutContext, LayoutResult, Position};
+use crate::doc::{Document, Page, TextAction};
+use crate::font::Font;
+use super::{Layouter, LayoutContext, Size2D};
-/// Layouts sublayouts within the constraints of a layouting context.
+/// A box layout has a fixed width and height and consists of actions.
+#[derive(Debug, Clone)]
+pub struct BoxLayout {
+ /// The size of the box.
+ dimensions: Size2D,
+ /// The actions composing this layout.
+ actions: Vec<TextAction>,
+}
+
+impl BoxLayout {
+ /// Convert this layout into a document given the list of fonts referenced by it.
+ pub fn into_doc(self, fonts: Vec<Font>) -> Document {
+ Document {
+ pages: vec![Page {
+ width: self.dimensions.x,
+ height: self.dimensions.y,
+ actions: self.actions,
+ }],
+ fonts,
+ }
+ }
+}
+
+/// Layouts boxes block-style.
#[derive(Debug)]
pub struct BoxLayouter<'a, 'p> {
ctx: &'a LayoutContext<'a, 'p>,
@@ -21,17 +45,29 @@ impl<'a, 'p> BoxLayouter<'a, 'p> {
}
/// Add a sublayout.
- pub fn add_layout_absolute(&mut self, position: Position, layout: Layout) {
+ pub fn add_box(&mut self, layout: BoxLayout) {
+ unimplemented!()
+ }
+
+ /// Add a sublayout at an absolute position.
+ pub fn add_box_absolute(&mut self, position: Size2D, layout: BoxLayout) {
self.actions.push(TextAction::MoveAbsolute(position));
self.actions.extend(layout.actions);
}
}
impl Layouter for BoxLayouter<'_, '_> {
- fn finish(self) -> LayoutResult<Layout> {
- Ok(Layout {
- extent: self.ctx.max_extent.clone(),
+ type Layout = BoxLayout;
+
+ /// Finish the layouting and create a box layout from this.
+ fn finish(self) -> BoxLayout {
+ BoxLayout {
+ dimensions: self.ctx.space.dimensions.clone(),
actions: self.actions
- })
+ }
+ }
+
+ fn is_empty(&self) -> bool {
+ self.actions.is_empty()
}
}