summaryrefslogtreecommitdiff
path: root/library/src/layout/align.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-03-07 15:17:13 +0100
committerLaurenz <laurmaedje@gmail.com>2023-03-07 15:17:13 +0100
commit25b5bd117529cd04bb789e1988eb3a3db8025a0e (patch)
tree2fbb4650903123da047a1f1f11a0abda95286e12 /library/src/layout/align.rs
parent6ab7760822ccd24b4ef126d4737d41f1be15fe19 (diff)
Fully untyped model
Diffstat (limited to 'library/src/layout/align.rs')
-rw-r--r--library/src/layout/align.rs109
1 files changed, 52 insertions, 57 deletions
diff --git a/library/src/layout/align.rs b/library/src/layout/align.rs
index b84ccfdc..96c0ae3b 100644
--- a/library/src/layout/align.rs
+++ b/library/src/layout/align.rs
@@ -1,6 +1,5 @@
use crate::prelude::*;
-/// # Align
/// Align content horizontally and vertically.
///
/// ## Example
@@ -13,63 +12,59 @@ use crate::prelude::*;
/// A work of art, a visual throne
/// ```
///
-/// ## Parameters
-/// - body: `Content` (positional, required)
-/// The content to align.
-///
-/// - alignment: `Axes<Option<GenAlign>>` (positional, settable)
-/// The alignment along both axes.
-///
-/// Possible values for horizontal alignments are:
-/// - `start`
-/// - `end`
-/// - `left`
-/// - `center`
-/// - `right`
-///
-/// The `start` and `end` alignments are relative to the current [text
-/// direction]($func/text.dir).
-///
-/// Possible values for vertical alignments are:
-/// - `top`
-/// - `horizon`
-/// - `bottom`
-///
-/// To align along both axes at the same time, add the two alignments using
-/// the `+` operator to get a `2d alignment`. For example, `top + right`
-/// aligns the content to the top right corner.
-///
-/// ```example
-/// #set page(height: 6cm)
-/// #set text(lang: "ar")
-///
-/// مثال
-/// #align(
-/// end + horizon,
-/// rect(inset: 12pt)[ركن]
-/// )
-/// ```
-///
-/// ## Category
-/// layout
-#[func]
-#[capable]
-#[derive(Debug, Hash)]
-pub enum AlignNode {}
-
-#[node]
-impl AlignNode {
- /// The alignment.
- #[property(fold, skip)]
- pub const ALIGNS: Axes<Option<GenAlign>> =
- Axes::new(GenAlign::Start, GenAlign::Specific(Align::Top));
+/// Display: Align
+/// Category: layout
+#[node(Show)]
+#[set({
+ let aligns: Axes<Option<GenAlign>> = args.find()?.unwrap_or_default();
+ styles.set(Self::ALIGNMENT, aligns);
+})]
+pub struct AlignNode {
+ /// The content to align.
+ #[positional]
+ #[required]
+ pub body: Content,
- fn construct(_: &Vm, args: &mut Args) -> SourceResult<Content> {
- args.expect("body")
- }
+ /// The alignment along both axes.
+ ///
+ /// Possible values for horizontal alignments are:
+ /// - `start`
+ /// - `end`
+ /// - `left`
+ /// - `center`
+ /// - `right`
+ ///
+ /// The `start` and `end` alignments are relative to the current [text
+ /// direction]($func/text.dir).
+ ///
+ /// Possible values for vertical alignments are:
+ /// - `top`
+ /// - `horizon`
+ /// - `bottom`
+ ///
+ /// To align along both axes at the same time, add the two alignments using
+ /// the `+` operator to get a `2d alignment`. For example, `top + right`
+ /// aligns the content to the top right corner.
+ ///
+ /// ```example
+ /// #set page(height: 6cm)
+ /// #set text(lang: "ar")
+ ///
+ /// مثال
+ /// #align(
+ /// end + horizon,
+ /// rect(inset: 12pt)[ركن]
+ /// )
+ /// ```
+ #[settable]
+ #[fold]
+ #[skip]
+ #[default(Axes::new(GenAlign::Start, GenAlign::Specific(Align::Top)))]
+ pub alignment: Axes<Option<GenAlign>>,
+}
- fn set(...) {
- let aligns: Axes<Option<GenAlign>> = args.find()?.unwrap_or_default();
- styles.set(Self::ALIGNS, aligns);
+impl Show for AlignNode {
+ fn show(&self, _: &mut Vt, _: &Content, _: StyleChain) -> SourceResult<Content> {
+ Ok(self.body())
}
}