summaryrefslogtreecommitdiff
path: root/library/src/layout/align.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-12-09 10:21:11 +0100
committerLaurenz <laurmaedje@gmail.com>2022-12-09 10:21:11 +0100
commitcd089b6194c57b2e8dff70efaa7cbd53035f7327 (patch)
treef5466a0e2f8633aa609276c0c2794911c7e9252a /library/src/layout/align.rs
parent495b525694aa5901385f3acad043b4a9f3ebb911 (diff)
Align set rule
Diffstat (limited to 'library/src/layout/align.rs')
-rw-r--r--library/src/layout/align.rs64
1 files changed, 12 insertions, 52 deletions
diff --git a/library/src/layout/align.rs b/library/src/layout/align.rs
index ae60b4c6..506ef684 100644
--- a/library/src/layout/align.rs
+++ b/library/src/layout/align.rs
@@ -1,62 +1,22 @@
-use super::{HorizontalAlign, ParNode};
use crate::prelude::*;
-/// Align content along the layouting axes.
+/// Just an empty shell to scope styles.
#[derive(Debug, Hash)]
-pub struct AlignNode {
- /// How to align the content horizontally and vertically.
- pub aligns: Axes<Option<GenAlign>>,
- /// The content to be aligned.
- pub body: Content,
-}
+pub enum AlignNode {}
-#[node(Layout)]
+#[node]
impl AlignNode {
- fn construct(_: &Vm, args: &mut Args) -> SourceResult<Content> {
- let aligns: Axes<Option<GenAlign>> = args.find()?.unwrap_or_default();
- let body: Content = args.expect("body")?;
+ /// The alignment.
+ #[property(fold, skip)]
+ pub const ALIGNS: Axes<Option<GenAlign>> =
+ Axes::new(GenAlign::Start, GenAlign::Specific(Align::Top));
- if let Axes { x: Some(x), y: None } = aligns {
- if !body.has::<dyn Layout>() || body.has::<dyn Inline>() {
- return Ok(body.styled(ParNode::ALIGN, HorizontalAlign(x)));
- }
- }
-
- Ok(Self { aligns, body }.pack())
+ fn construct(_: &Vm, args: &mut Args) -> SourceResult<Content> {
+ args.expect("body")
}
-}
-impl Layout for AlignNode {
- fn layout(
- &self,
- vt: &mut Vt,
- styles: StyleChain,
- regions: Regions,
- ) -> SourceResult<Fragment> {
- // The child only needs to expand along an axis if there's no alignment.
- let mut pod = regions.clone();
- pod.expand &= self.aligns.as_ref().map(Option::is_none);
-
- // Align paragraphs inside the child.
- let mut map = StyleMap::new();
- if let Some(align) = self.aligns.x {
- map.set(ParNode::ALIGN, HorizontalAlign(align));
- }
-
- // Layout the child.
- let mut fragment = self.body.layout(vt, styles.chain(&map), pod)?;
- for (region, frame) in regions.iter().zip(&mut fragment) {
- // Align in the target size. The target size depends on whether we
- // should expand.
- let target = regions.expand.select(region, frame.size());
- let aligns = self
- .aligns
- .map(|align| align.resolve(styles))
- .unwrap_or(Axes::new(Align::Left, Align::Top));
-
- frame.resize(target, aligns);
- }
-
- Ok(fragment)
+ fn set(...) {
+ let aligns: Axes<Option<GenAlign>> = args.find()?.unwrap_or_default();
+ styles.set(Self::ALIGNS, aligns);
}
}