mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
Add align
parameter to stack
This commit is contained in:
parent
3de3813ca0
commit
3594e3e767
@ -1,6 +1,8 @@
|
|||||||
use typst_library::diag::{bail, SourceResult};
|
use typst_library::diag::{bail, SourceResult};
|
||||||
use typst_library::engine::Engine;
|
use typst_library::engine::Engine;
|
||||||
use typst_library::foundations::{Content, Packed, Resolve, StyleChain, StyledElem};
|
use typst_library::foundations::{
|
||||||
|
Content, Packed, Resolve, Smart, StyleChain, StyledElem,
|
||||||
|
};
|
||||||
use typst_library::introspection::{Locator, SplitLocator};
|
use typst_library::introspection::{Locator, SplitLocator};
|
||||||
use typst_library::layout::{
|
use typst_library::layout::{
|
||||||
Abs, AlignElem, Axes, Axis, Dir, FixedAlignment, Fr, Fragment, Frame, HElem, Point,
|
Abs, AlignElem, Axes, Axis, Dir, FixedAlignment, Fr, Fragment, Frame, HElem, Point,
|
||||||
@ -27,6 +29,8 @@ pub fn layout_stack(
|
|||||||
let spacing = elem.spacing(styles);
|
let spacing = elem.spacing(styles);
|
||||||
let mut deferred = None;
|
let mut deferred = None;
|
||||||
|
|
||||||
|
let align = elem.align(styles);
|
||||||
|
|
||||||
for child in &elem.children {
|
for child in &elem.children {
|
||||||
match child {
|
match child {
|
||||||
StackChild::Spacing(kind) => {
|
StackChild::Spacing(kind) => {
|
||||||
@ -52,7 +56,15 @@ pub fn layout_stack(
|
|||||||
layouter.layout_spacing(kind);
|
layouter.layout_spacing(kind);
|
||||||
}
|
}
|
||||||
|
|
||||||
layouter.layout_block(engine, block, styles)?;
|
if let Smart::Custom(alignment) = align {
|
||||||
|
layouter.layout_block(
|
||||||
|
engine,
|
||||||
|
&block.clone().aligned(alignment),
|
||||||
|
styles,
|
||||||
|
)?;
|
||||||
|
} else {
|
||||||
|
layouter.layout_block(engine, block, styles)?;
|
||||||
|
}
|
||||||
deferred = spacing;
|
deferred = spacing;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,10 @@ use std::fmt::{self, Debug, Formatter};
|
|||||||
|
|
||||||
use crate::diag::SourceResult;
|
use crate::diag::SourceResult;
|
||||||
use crate::engine::Engine;
|
use crate::engine::Engine;
|
||||||
use crate::foundations::{cast, elem, Content, NativeElement, Packed, Show, StyleChain};
|
use crate::foundations::{
|
||||||
use crate::layout::{BlockElem, Dir, Spacing};
|
cast, elem, Content, NativeElement, Packed, Show, Smart, StyleChain,
|
||||||
|
};
|
||||||
|
use crate::layout::{Alignment, BlockElem, Dir, Spacing};
|
||||||
|
|
||||||
/// Arranges content and spacing horizontally or vertically.
|
/// Arranges content and spacing horizontally or vertically.
|
||||||
///
|
///
|
||||||
@ -42,6 +44,11 @@ pub struct StackElem {
|
|||||||
/// Spacing to insert between items where no explicit spacing was provided.
|
/// Spacing to insert between items where no explicit spacing was provided.
|
||||||
pub spacing: Option<Spacing>,
|
pub spacing: Option<Spacing>,
|
||||||
|
|
||||||
|
/// How to align the items.
|
||||||
|
///
|
||||||
|
/// If set to `{auto}`, the outer alignment is used.
|
||||||
|
pub align: Smart<Alignment>,
|
||||||
|
|
||||||
/// The children to stack along the axis.
|
/// The children to stack along the axis.
|
||||||
#[variadic]
|
#[variadic]
|
||||||
pub children: Vec<StackChild>,
|
pub children: Vec<StackChild>,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user