diff options
| author | Laurenz <laurmaedje@gmail.com> | 2020-02-04 21:36:29 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2020-02-04 21:36:29 +0100 |
| commit | 751812f45141a7b2022d0dba138457f3c21950b0 (patch) | |
| tree | 8f5125f5c475313c460f4a98ec174c11cb0e9c02 /src/layout/mod.rs | |
| parent | e63ce52ae0d929506a1fa238477f039d14d53813 (diff) | |
Serialize layouts with serde ðŸ”
Diffstat (limited to 'src/layout/mod.rs')
| -rw-r--r-- | src/layout/mod.rs | 33 |
1 files changed, 3 insertions, 30 deletions
diff --git a/src/layout/mod.rs b/src/layout/mod.rs index b29d87e3..01d402db 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -1,8 +1,8 @@ //! Layouting types and engines. -use std::io::{self, Write}; use std::fmt::{self, Display, Formatter}; use smallvec::SmallVec; +use serde::Serialize; use toddle::query::FontIndex; use crate::size::{Size, Size2D, SizeBox}; @@ -32,11 +32,12 @@ pub mod prelude { pub type MultiLayout = Vec<Layout>; /// A finished box with content at fixed positions. -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Serialize)] pub struct Layout { /// The size of the box. pub dimensions: Size2D, /// How to align this layout in a parent container. + #[serde(skip)] pub alignment: LayoutAlignment, /// The actions composing this layout. pub actions: Vec<LayoutAction>, @@ -57,34 +58,6 @@ impl Layout { } } -/// Layout components that can be serialized. -pub trait Serialize { - /// Serialize the data structure into an output writable. - fn serialize<W: Write>(&self, f: &mut W) -> io::Result<()>; -} - -impl Serialize for Layout { - fn serialize<W: Write>(&self, f: &mut W) -> io::Result<()> { - writeln!(f, "{:.4} {:.4}", self.dimensions.x.to_pt(), self.dimensions.y.to_pt())?; - writeln!(f, "{}", self.actions.len())?; - for action in &self.actions { - action.serialize(f)?; - writeln!(f)?; - } - Ok(()) - } -} - -impl Serialize for MultiLayout { - fn serialize<W: Write>(&self, f: &mut W) -> io::Result<()> { - writeln!(f, "{}", self.len())?; - for layout in self { - layout.serialize(f)?; - } - Ok(()) - } -} - /// A vector of layout spaces, that is stack allocated as long as it only /// contains at most 2 spaces. pub type LayoutSpaces = SmallVec<[LayoutSpace; 2]>; |
