diff options
Diffstat (limited to 'src/library/structure/table.rs')
| -rw-r--r-- | src/library/structure/table.rs | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/src/library/structure/table.rs b/src/library/structure/table.rs index 191d3dd3..7b3f2ac5 100644 --- a/src/library/structure/table.rs +++ b/src/library/structure/table.rs @@ -1,4 +1,4 @@ -use crate::library::layout::{GridNode, TrackSizing}; +use crate::library::layout::{BlockSpacing, GridNode, TrackSizing}; use crate::library::prelude::*; /// A table of items. @@ -15,16 +15,24 @@ pub struct TableNode { #[node(showable)] impl TableNode { /// The primary cell fill color. + #[property(shorthand(fill))] pub const PRIMARY: Option<Paint> = None; /// The secondary cell fill color. + #[property(shorthand(fill))] pub const SECONDARY: Option<Paint> = None; /// How to stroke the cells. #[property(resolve, fold)] pub const STROKE: Option<RawStroke> = Some(RawStroke::default()); - /// How much to pad the cells's content. pub const PADDING: Relative<RawLength> = Length::pt(5.0).into(); + /// The spacing above the table. + #[property(resolve, shorthand(around))] + pub const ABOVE: Option<BlockSpacing> = Some(Ratio::one().into()); + /// The spacing below the table. + #[property(resolve, shorthand(around))] + pub const BELOW: Option<BlockSpacing> = Some(Ratio::one().into()); + fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> { let columns = args.named("columns")?.unwrap_or_default(); let rows = args.named("rows")?.unwrap_or_default(); @@ -40,16 +48,6 @@ impl TableNode { cells: args.all()?, })) } - - fn set(args: &mut Args) -> TypResult<StyleMap> { - let mut styles = StyleMap::new(); - let fill = args.named("fill")?; - styles.set_opt(Self::PRIMARY, args.named("primary")?.or(fill)); - styles.set_opt(Self::SECONDARY, args.named("secondary")?.or(fill)); - styles.set_opt(Self::STROKE, args.named("stroke")?); - styles.set_opt(Self::PADDING, args.named("padding")?); - Ok(styles) - } } impl Show for TableNode { @@ -99,4 +97,13 @@ impl Show for TableNode { cells, })) } + + fn finalize( + &self, + _: &mut Context, + styles: StyleChain, + realized: Content, + ) -> TypResult<Content> { + Ok(realized.spaced(styles.get(Self::ABOVE), styles.get(Self::BELOW))) + } } |
