From 3ca5b238238e1128aa7bbfbd5db9e632045d8600 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Mon, 28 Feb 2022 15:50:48 +0100 Subject: Reorganize library --- src/library/elements/heading.rs | 150 ++++++++++++++++++++++++++++ src/library/elements/image.rs | 116 ++++++++++++++++++++++ src/library/elements/list.rs | 212 ++++++++++++++++++++++++++++++++++++++++ src/library/elements/math.rs | 37 +++++++ src/library/elements/mod.rs | 15 +++ src/library/elements/shape.rs | 166 +++++++++++++++++++++++++++++++ src/library/elements/table.rs | 100 +++++++++++++++++++ 7 files changed, 796 insertions(+) create mode 100644 src/library/elements/heading.rs create mode 100644 src/library/elements/image.rs create mode 100644 src/library/elements/list.rs create mode 100644 src/library/elements/math.rs create mode 100644 src/library/elements/mod.rs create mode 100644 src/library/elements/shape.rs create mode 100644 src/library/elements/table.rs (limited to 'src/library/elements') diff --git a/src/library/elements/heading.rs b/src/library/elements/heading.rs new file mode 100644 index 00000000..a67f4f24 --- /dev/null +++ b/src/library/elements/heading.rs @@ -0,0 +1,150 @@ +use crate::library::prelude::*; +use crate::library::text::{FontFamily, TextNode}; + +/// A section heading. +#[derive(Debug, Hash)] +pub struct HeadingNode { + /// The logical nesting depth of the section, starting from one. In the + /// default style, this controls the text size of the heading. + pub level: usize, + /// The heading's contents. + pub body: Template, +} + +#[class] +impl HeadingNode { + /// The heading's font family. Just the normal text family if `auto`. + pub const FAMILY: Leveled> = Leveled::Value(Smart::Auto); + /// The color of text in the heading. Just the normal text color if `auto`. + pub const FILL: Leveled> = Leveled::Value(Smart::Auto); + /// The size of text in the heading. + pub const SIZE: Leveled = Leveled::Mapping(|level| { + let upscale = (1.6 - 0.1 * level as f64).max(0.75); + Relative::new(upscale).into() + }); + /// Whether text in the heading is strengthend. + pub const STRONG: Leveled = Leveled::Value(true); + /// Whether text in the heading is emphasized. + pub const EMPH: Leveled = Leveled::Value(false); + /// Whether the heading is underlined. + pub const UNDERLINE: Leveled = Leveled::Value(false); + /// The extra padding above the heading. + pub const ABOVE: Leveled = Leveled::Value(Length::zero()); + /// The extra padding below the heading. + pub const BELOW: Leveled = Leveled::Value(Length::zero()); + /// Whether the heading is block-level. + pub const BLOCK: Leveled = Leveled::Value(true); + + fn construct(_: &mut Context, args: &mut Args) -> TypResult