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/layout | |
| parent | 9dca4c2f7833055edd3c1682e98dcc3f86b7e31b (diff) | |
CR: Whoever said orange is the new pink was seriously disturbed.
Diffstat (limited to 'src/library/layout')
| -rw-r--r-- | src/library/layout/grid.rs | 63 | ||||
| -rw-r--r-- | src/library/layout/page.rs | 14 |
2 files changed, 20 insertions, 57 deletions
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); |
