diff options
| author | Martin Haug <mhaug@live.de> | 2022-06-08 18:43:00 +0200 |
|---|---|---|
| committer | Martin Haug <mhaug@live.de> | 2022-06-08 19:26:20 +0200 |
| commit | 72d3f3fffabe6872eb7839585bea925b89aac6a4 (patch) | |
| tree | 2c55fc7bceb85d7ce94b09536ee02f5fedcd5fff /src/library | |
| parent | 9dca4c2f7833055edd3c1682e98dcc3f86b7e31b (diff) | |
CR: Whoever said orange is the new pink was seriously disturbed.
Diffstat (limited to 'src/library')
| -rw-r--r-- | src/library/graphics/shape.rs | 4 | ||||
| -rw-r--r-- | src/library/layout/grid.rs | 63 | ||||
| -rw-r--r-- | src/library/layout/page.rs | 14 | ||||
| -rw-r--r-- | src/library/structure/heading.rs | 5 | ||||
| -rw-r--r-- | src/library/structure/list.rs | 4 | ||||
| -rw-r--r-- | src/library/text/par.rs | 1 |
6 files changed, 26 insertions, 65 deletions
diff --git a/src/library/graphics/shape.rs b/src/library/graphics/shape.rs index e972a3d5..82eb2d9d 100644 --- a/src/library/graphics/shape.rs +++ b/src/library/graphics/shape.rs @@ -94,9 +94,7 @@ impl<const S: ShapeKind> Layout for ShapeNode<S> { frames = child.layout(ctx, &pod, styles)?; for frame in frames.iter_mut() { - if frame.role().map_or(true, Role::is_weak) { - Arc::make_mut(frame).apply_role(Role::GenericBlock); - } + Arc::make_mut(frame).apply_role(Role::GenericBlock); } // Relayout with full expansion into square region to make sure diff --git a/src/library/layout/grid.rs b/src/library/layout/grid.rs index 687091ff..2d6eb259 100644 --- a/src/library/layout/grid.rs +++ b/src/library/layout/grid.rs @@ -65,41 +65,6 @@ pub enum TrackSizing { Fractional(Fraction), } -/// Defines what kind of semantics a grid should represent. -#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] -enum GridSemantics { - /// The grid is transparent to the semantic tree. - None, - /// The grid is a list, its rows are list items. The bool indicates whether - /// the list is ordered. - List, - /// The grid is a table. - Table, -} - -impl GridSemantics { - /// The role of a row in a grid with these semantics. - fn row(self) -> Option<Role> { - match self { - Self::None => None, - Self::List => Some(Role::ListItem), - Self::Table => Some(Role::TableRow), - } - } - - /// Returns the semantic role of a grid row given the previous semantics and - /// the cell's role. - fn determine(other: Option<Self>, role: Option<Role>) -> Self { - match (other, role) { - (None, Some(Role::ListItem | Role::ListLabel)) => Self::List, - (Some(Self::List), Some(Role::ListItem | Role::ListLabel)) => Self::List, - (None, Some(Role::TableCell)) => Self::Table, - (Some(Self::Table), Some(Role::TableCell)) => Self::Table, - _ => Self::None, - } - } -} - castable! { Vec<TrackSizing>, Expected: "integer, auto, relative length, fraction, or array of the latter three)", @@ -487,7 +452,6 @@ impl<'a> GridLayouter<'a> { let mut output = Frame::new(Size::new(self.used.x, height)); let mut pos = Point::zero(); - let mut semantic = None; for (x, &rcol) in self.rcols.iter().enumerate() { if let Some(node) = self.cell(x, y) { @@ -501,7 +465,13 @@ impl<'a> GridLayouter<'a> { let pod = Regions::one(size, base, Spec::splat(true)); let frame = node.layout(self.ctx, &pod, self.styles)?.remove(0); - semantic = Some(GridSemantics::determine(semantic, frame.role())); + match frame.role() { + Some(Role::ListLabel | Role::ListItemBody) => { + output.apply_role(Role::ListItem) + } + Some(Role::TableCell) => output.apply_role(Role::TableRow), + _ => {} + } output.push_frame(pos, frame); } @@ -509,10 +479,6 @@ impl<'a> GridLayouter<'a> { pos.x += rcol; } - if let Some(role) = semantic.and_then(GridSemantics::row) { - output.apply_role(role); - } - Ok(output) } @@ -535,7 +501,6 @@ impl<'a> GridLayouter<'a> { // Layout the row. let mut pos = Point::zero(); - let mut semantic = None; for (x, &rcol) in self.rcols.iter().enumerate() { if let Some(node) = self.cell(x, y) { pod.first.x = rcol; @@ -549,7 +514,13 @@ impl<'a> GridLayouter<'a> { // Push the layouted frames into the individual output frames. let frames = node.layout(self.ctx, &pod, self.styles)?; for (output, frame) in outputs.iter_mut().zip(frames) { - semantic = Some(GridSemantics::determine(semantic, frame.role())); + match frame.role() { + Some(Role::ListLabel | Role::ListItemBody) => { + output.apply_role(Role::ListItem) + } + Some(Role::TableCell) => output.apply_role(Role::TableRow), + _ => {} + } output.push_frame(pos, frame); } } @@ -557,12 +528,6 @@ impl<'a> GridLayouter<'a> { pos.x += rcol; } - for output in outputs.iter_mut() { - if let Some(role) = semantic.and_then(GridSemantics::row) { - output.apply_role(role); - } - } - Ok(outputs) } diff --git a/src/library/layout/page.rs b/src/library/layout/page.rs index 8bd507c4..115a1923 100644 --- a/src/library/layout/page.rs +++ b/src/library/layout/page.rs @@ -110,30 +110,28 @@ impl PageNode { let pad = padding.resolve(styles).relative_to(size); let pw = size.x - pad.left - pad.right; let py = size.y - pad.bottom; - for (marginal, pos, area, role) in [ + for (role, marginal, pos, area) in [ ( + Role::Header, header, Point::with_x(pad.left), Size::new(pw, pad.top), - Role::Header, ), ( + Role::Footer, footer, Point::new(pad.left, py), Size::new(pw, pad.bottom), - Role::Footer, ), - (foreground, Point::zero(), size, Role::Background), - (background, Point::zero(), size, Role::Background), + (Role::Foreground, foreground, Point::zero(), size), + (Role::Background, background, Point::zero(), size), ] { if let Some(content) = marginal.resolve(ctx, page)? { let pod = Regions::one(area, area, Spec::splat(true)); - let role_map = StyleMap::with_role(role); - let styles = role_map.chain(&styles); let mut sub = content.layout(ctx, &pod, styles)?.remove(0); Arc::make_mut(&mut sub).apply_role(role); - if std::ptr::eq(marginal, background) { + if role == Role::Background { Arc::make_mut(frame).prepend_frame(pos, sub); } else { Arc::make_mut(frame).push_frame(pos, sub); diff --git a/src/library/structure/heading.rs b/src/library/structure/heading.rs index 242912a3..af2b3626 100644 --- a/src/library/structure/heading.rs +++ b/src/library/structure/heading.rs @@ -92,8 +92,7 @@ impl Show for HeadingNode { }; } - let mut map = StyleMap::with_role(Role::Heading(self.level.get())); - + let mut map = StyleMap::new(); map.set(TextNode::SIZE, resolve!(Self::SIZE)); if let Smart::Custom(family) = resolve!(Self::FAMILY) { @@ -116,7 +115,7 @@ impl Show for HeadingNode { realized = realized.underlined(); } - realized = realized.styled_with_map(map); + realized = realized.styled_with_map(map).role(Role::Heading(self.level.get())); realized = realized.spaced( resolve!(Self::ABOVE).resolve(styles), resolve!(Self::BELOW).resolve(styles), diff --git a/src/library/structure/list.rs b/src/library/structure/list.rs index 077536d4..015ef520 100644 --- a/src/library/structure/list.rs +++ b/src/library/structure/list.rs @@ -161,7 +161,9 @@ impl<const L: ListKind> Show for ListNode<L> { } } - Ok(realized.role(Role::List(L == ORDERED)).spaced(above, below)) + Ok(realized + .role(Role::List { ordered: L == ORDERED }) + .spaced(above, below)) } } diff --git a/src/library/text/par.rs b/src/library/text/par.rs index 0fec11ad..41246b00 100644 --- a/src/library/text/par.rs +++ b/src/library/text/par.rs @@ -557,7 +557,6 @@ fn prepare<'a>( if !shift.is_zero() || frame.role().map_or(true, Role::is_weak) { let frame = Arc::make_mut(&mut frame); - frame.translate(Point::with_y(shift)); frame.apply_role(Role::GenericInline); } |
