diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-01-04 21:29:15 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-01-04 21:29:15 +0100 |
| commit | 2e77b1c836220766398e379ae0157736fb448874 (patch) | |
| tree | 70fc7d28f44193f26d880b5315ce55ed951af73c /src/library/mod.rs | |
| parent | 77c06ebc24ab3a43dc2268763ff8f10963f875b4 (diff) | |
Better value representations, type function 🌐
Diffstat (limited to 'src/library/mod.rs')
| -rw-r--r-- | src/library/mod.rs | 97 |
1 files changed, 54 insertions, 43 deletions
diff --git a/src/library/mod.rs b/src/library/mod.rs index 1cc7b9e9..f9047fc6 100644 --- a/src/library/mod.rs +++ b/src/library/mod.rs @@ -1,67 +1,78 @@ //! The standard library. +mod extend; mod insert; mod layout; mod style; +pub use extend::*; pub use insert::*; pub use layout::*; pub use style::*; use fontdock::{FontStretch, FontStyle, FontWeight}; -use crate::eval::Scope; +use crate::eval::{Scope, ValueAny, ValueFunc}; use crate::geom::Dir; /// The scope containing the standard library. pub fn _std() -> Scope { let mut std = Scope::new(); + macro_rules! set { + (func: $name:expr, $func:expr) => { + std.set($name, ValueFunc::new($name, $func)) + }; + (any: $var:expr, $any:expr) => { + std.set($var, ValueAny::new($any)) + }; + } // Functions. - std.set("align", align); - std.set("box", boxed); - std.set("font", font); - std.set("h", h); - std.set("image", image); - std.set("page", page); - std.set("pagebreak", pagebreak); - std.set("rgb", rgb); - std.set("v", v); + set!(func: "align", align); + set!(func: "box", box_); + set!(func: "font", font); + set!(func: "h", h); + set!(func: "image", image); + set!(func: "page", page); + set!(func: "pagebreak", pagebreak); + set!(func: "rgb", rgb); + set!(func: "type", type_); + set!(func: "v", v); // Constants. - std.set("left", Alignment::Left); - std.set("center", Alignment::Center); - std.set("right", Alignment::Right); - std.set("top", Alignment::Top); - std.set("bottom", Alignment::Bottom); - std.set("ltr", Dir::LTR); - std.set("rtl", Dir::RTL); - std.set("ttb", Dir::TTB); - std.set("btt", Dir::BTT); - std.set("serif", FontFamily::Serif); - std.set("sans-serif", FontFamily::SansSerif); - std.set("monospace", FontFamily::Monospace); - std.set("normal", FontStyle::Normal); - std.set("italic", FontStyle::Italic); - std.set("oblique", FontStyle::Oblique); - std.set("thin", FontWeight::THIN); - std.set("extralight", FontWeight::EXTRALIGHT); - std.set("light", FontWeight::LIGHT); - std.set("regular", FontWeight::REGULAR); - std.set("medium", FontWeight::MEDIUM); - std.set("semibold", FontWeight::SEMIBOLD); - std.set("bold", FontWeight::BOLD); - std.set("extrabold", FontWeight::EXTRABOLD); - std.set("black", FontWeight::BLACK); - std.set("ultra-condensed", FontStretch::UltraCondensed); - std.set("extra-condensed", FontStretch::ExtraCondensed); - std.set("condensed", FontStretch::Condensed); - std.set("semi-condensed", FontStretch::SemiCondensed); - std.set("normal", FontStretch::Normal); - std.set("semi-expanded", FontStretch::SemiExpanded); - std.set("expanded", FontStretch::Expanded); - std.set("extra-expanded", FontStretch::ExtraExpanded); - std.set("ultra-expanded", FontStretch::UltraExpanded); + set!(any: "left", Alignment::Left); + set!(any: "center", Alignment::Center); + set!(any: "right", Alignment::Right); + set!(any: "top", Alignment::Top); + set!(any: "bottom", Alignment::Bottom); + set!(any: "ltr", Dir::LTR); + set!(any: "rtl", Dir::RTL); + set!(any: "ttb", Dir::TTB); + set!(any: "btt", Dir::BTT); + set!(any: "serif", FontFamily::Serif); + set!(any: "sans-serif", FontFamily::SansSerif); + set!(any: "monospace", FontFamily::Monospace); + set!(any: "normal", FontStyle::Normal); + set!(any: "italic", FontStyle::Italic); + set!(any: "oblique", FontStyle::Oblique); + set!(any: "thin", FontWeight::THIN); + set!(any: "extralight", FontWeight::EXTRALIGHT); + set!(any: "light", FontWeight::LIGHT); + set!(any: "regular", FontWeight::REGULAR); + set!(any: "medium", FontWeight::MEDIUM); + set!(any: "semibold", FontWeight::SEMIBOLD); + set!(any: "bold", FontWeight::BOLD); + set!(any: "extrabold", FontWeight::EXTRABOLD); + set!(any: "black", FontWeight::BLACK); + set!(any: "ultra-condensed", FontStretch::UltraCondensed); + set!(any: "extra-condensed", FontStretch::ExtraCondensed); + set!(any: "condensed", FontStretch::Condensed); + set!(any: "semi-condensed", FontStretch::SemiCondensed); + set!(any: "normal", FontStretch::Normal); + set!(any: "semi-expanded", FontStretch::SemiExpanded); + set!(any: "expanded", FontStretch::Expanded); + set!(any: "extra-expanded", FontStretch::ExtraExpanded); + set!(any: "ultra-expanded", FontStretch::UltraExpanded); std } |
