summaryrefslogtreecommitdiff
path: root/src/layout
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2019-10-11 17:53:28 +0200
committerLaurenz <laurmaedje@gmail.com>2019-10-11 17:53:28 +0200
commitc0e4fd55e6fa738cfc5dcc851d0fc3ee2d0f2cd2 (patch)
treee5531e605d0ab9e06dc950b4cd9b7a8caa116d34 /src/layout
parent8f788f9a4f5e970bbe6147987b711470d57aca8d (diff)
Create test runner which renders layouts to images 🗺
Diffstat (limited to 'src/layout')
-rw-r--r--src/layout/boxed.rs11
-rw-r--r--src/layout/flex.rs3
2 files changed, 14 insertions, 0 deletions
diff --git a/src/layout/boxed.rs b/src/layout/boxed.rs
index afcd5278..5bd909d4 100644
--- a/src/layout/boxed.rs
+++ b/src/layout/boxed.rs
@@ -1,5 +1,6 @@
//! Block-style layouting of boxes.
+use std::io::{self, Write};
use crate::doc::{Document, Page, LayoutAction};
use crate::size::{Size, Size2D};
use super::{ActionList, LayoutSpace, Alignment, LayoutResult, LayoutError};
@@ -25,6 +26,16 @@ impl BoxLayout {
}],
}
}
+
+ /// Serialize this layout into a string representation.
+ pub fn serialize<W: Write>(&self, f: &mut W) -> io::Result<()> {
+ writeln!(f, "{:.4} {:.4}", self.dimensions.x.to_pt(), self.dimensions.y.to_pt())?;
+ for action in &self.actions {
+ action.serialize(f)?;
+ writeln!(f)?;
+ }
+ Ok(())
+ }
}
/// The context for layouting boxes.
diff --git a/src/layout/flex.rs b/src/layout/flex.rs
index 8b692691..8c099553 100644
--- a/src/layout/flex.rs
+++ b/src/layout/flex.rs
@@ -157,6 +157,9 @@ impl FlexFinisher {
/// Layout the glue.
fn glue(&mut self, glue: BoxLayout) {
+ if let Some(glue) = self.glue.take() {
+ self.append(glue);
+ }
self.glue = Some(glue);
}