summaryrefslogtreecommitdiff
path: root/library/src/layout/align.rs
blob: 5426f5e28fe8f69f3e5d60809e3e1b35cd6f1def (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use crate::prelude::*;

/// Align content horizontally and vertically.
///
/// # Parameters
/// - body: Content (positional, required)
///   The content to align.
///
/// - alignment: Axes<Option<GenAlign>> (positional, settable)
///   The alignment along both axes.
///
/// # Tags
/// - 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));

    fn construct(_: &Vm, args: &mut Args) -> SourceResult<Content> {
        args.expect("body")
    }

    fn set(...) {
        let aligns: Axes<Option<GenAlign>> = args.find()?.unwrap_or_default();
        styles.set(Self::ALIGNS, aligns);
    }
}