From c0e4fd55e6fa738cfc5dcc851d0fc3ee2d0f2cd2 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Fri, 11 Oct 2019 17:53:28 +0200 Subject: =?UTF-8?q?Create=20test=20runner=20which=20renders=20layouts=20to?= =?UTF-8?q?=20images=20=F0=9F=97=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layout/boxed.rs | 11 +++++++++++ src/layout/flex.rs | 3 +++ 2 files changed, 14 insertions(+) (limited to 'src/layout') 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(&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); } -- cgit v1.2.3