From 010cc2effc2fd0e1c4e52d5c914cb4d74506bc0a Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 9 Nov 2022 18:16:59 +0100 Subject: New block spacing model --- library/src/structure/table.rs | 39 ++++++++++++++------------------------- 1 file changed, 14 insertions(+), 25 deletions(-) (limited to 'library/src/structure/table.rs') diff --git a/library/src/structure/table.rs b/library/src/structure/table.rs index 8c6191be..72ea3da5 100644 --- a/library/src/structure/table.rs +++ b/library/src/structure/table.rs @@ -1,8 +1,8 @@ -use crate::layout::{BlockSpacing, GridNode, TrackSizing, TrackSizings}; +use crate::layout::{GridNode, TrackSizing, TrackSizings}; use crate::prelude::*; /// A table of items. -#[derive(Debug, Hash)] +#[derive(Debug, Clone, Hash)] pub struct TableNode { /// Defines sizing for content rows and columns. pub tracks: Axes>, @@ -12,7 +12,7 @@ pub struct TableNode { pub cells: Vec, } -#[node(Show, Finalize)] +#[node(Show, LayoutBlock)] impl TableNode { /// How to fill the cells. #[property(referenced)] @@ -23,13 +23,6 @@ impl TableNode { /// How much to pad the cells's content. pub const PADDING: Rel = Abs::pt(5.0).into(); - /// The spacing above the table. - #[property(resolve, shorthand(around))] - pub const ABOVE: Option = Some(Ratio::one().into()); - /// The spacing below the table. - #[property(resolve, shorthand(around))] - pub const BELOW: Option = Some(Ratio::one().into()); - fn construct(_: &mut Vm, args: &mut Args) -> SourceResult { let TrackSizings(columns) = args.named("columns")?.unwrap_or_default(); let TrackSizings(rows) = args.named("rows")?.unwrap_or_default(); @@ -67,11 +60,18 @@ impl Show for TableNode { .pack() } - fn show( + fn show(&self, _: Tracked, _: StyleChain) -> SourceResult { + Ok(self.clone().pack()) + } +} + +impl LayoutBlock for TableNode { + fn layout_block( &self, world: Tracked, + regions: &Regions, styles: StyleChain, - ) -> SourceResult { + ) -> SourceResult> { let fill = styles.get(Self::FILL); let stroke = styles.get(Self::STROKE).map(PartialStroke::unwrap_or_default); let padding = styles.get(Self::PADDING); @@ -99,23 +99,12 @@ impl Show for TableNode { }) .collect::>()?; - Ok(GridNode { + GridNode { tracks: self.tracks.clone(), gutter: self.gutter.clone(), cells, } - .pack()) - } -} - -impl Finalize for TableNode { - fn finalize( - &self, - _: Tracked, - styles: StyleChain, - realized: Content, - ) -> SourceResult { - Ok(realized.spaced(styles.get(Self::ABOVE), styles.get(Self::BELOW))) + .layout_block(world, regions, styles) } } -- cgit v1.2.3