diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-06-13 23:16:40 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-06-14 13:53:02 +0200 |
| commit | c81e2a5f56eb262663f292578c683fba7f18251f (patch) | |
| tree | 6c045a8dcbec5e75e01a15f970ef8cee6ff042d0 /src/model | |
| parent | 891af17260a6750a74a102388a05e59cf1ffc3c1 (diff) | |
Many fixes
Diffstat (limited to 'src/model')
| -rw-r--r-- | src/model/content.rs | 4 | ||||
| -rw-r--r-- | src/model/layout.rs | 6 | ||||
| -rw-r--r-- | src/model/locate.rs | 12 | ||||
| -rw-r--r-- | src/model/property.rs | 6 | ||||
| -rw-r--r-- | src/model/styles.rs | 22 |
5 files changed, 27 insertions, 23 deletions
diff --git a/src/model/content.rs b/src/model/content.rs index d2af4595..264785ec 100644 --- a/src/model/content.rs +++ b/src/model/content.rs @@ -154,7 +154,7 @@ impl Content { Self::Show(node.pack(), None) } - /// Create a new sequence nodes from multiples nodes. + /// Create a new sequence node from multiples nodes. pub fn sequence(seq: Vec<Self>) -> Self { match seq.as_slice() { [] => Self::Empty, @@ -204,7 +204,7 @@ impl Content { Self::Styled(Arc::new((self, styles))) } - /// Assign a role to this content by adding a style map. + /// Assign a semantic role to this content. pub fn role(self, role: Role) -> Self { self.styled_with_entry(StyleEntry::Role(role)) } diff --git a/src/model/layout.rs b/src/model/layout.rs index 4fa3fe20..ffe41725 100644 --- a/src/model/layout.rs +++ b/src/model/layout.rs @@ -19,7 +19,7 @@ use crate::Context; /// A node that can be layouted into a sequence of regions. /// -/// Layouting return one frame per used region. +/// Layouting returns one frame per used region. pub trait Layout: 'static { /// Layout this node into the given regions, producing frames. fn layout( @@ -377,7 +377,7 @@ impl Layout for SizedNode { struct FillNode { /// How to fill the frames resulting from the `child`. fill: Paint, - /// The node to fill. + /// The node whose frames should be filled. child: LayoutNode, } @@ -402,7 +402,7 @@ impl Layout for FillNode { struct StrokeNode { /// How to stroke the frames resulting from the `child`. stroke: Stroke, - /// The node to stroke. + /// The node whose frames should be stroked. child: LayoutNode, } diff --git a/src/model/locate.rs b/src/model/locate.rs index f6432d43..d5c71423 100644 --- a/src/model/locate.rs +++ b/src/model/locate.rs @@ -1,6 +1,7 @@ use std::cell::Cell; use std::fmt::{self, Debug, Formatter}; use std::hash::{Hash, Hasher}; +use std::num::NonZeroUsize; use std::sync::Arc; use super::Content; @@ -55,7 +56,7 @@ impl LocateNode { Self(Arc::new(Repr::Entry(EntryNode { group, recipe, value }))) } - /// Create a new node with access to a group's members. + /// Create a new node with access to all of a group's members. pub fn all(group: Group, recipe: Spanned<Func>) -> Self { Self(Arc::new(Repr::All(AllNode { group, recipe }))) } @@ -278,7 +279,7 @@ impl PinBoard { locate_in_frame( &mut self.list, &mut flow, - 1 + i, + NonZeroUsize::new(1 + i).unwrap(), frame, Transform::identity(), ); @@ -295,7 +296,7 @@ impl PinBoard { fn locate_in_frame( pins: &mut [Pin], flow: &mut usize, - page: usize, + page: NonZeroUsize, frame: &Frame, ts: Transform, ) { @@ -384,7 +385,10 @@ impl Pin { impl Default for Pin { fn default() -> Self { Self { - loc: Location { page: 0, pos: Point::zero() }, + loc: Location { + page: NonZeroUsize::new(1).unwrap(), + pos: Point::zero(), + }, flow: 0, group: None, value: None, diff --git a/src/model/property.rs b/src/model/property.rs index a0a71ddc..0e171939 100644 --- a/src/model/property.rs +++ b/src/model/property.rs @@ -18,7 +18,7 @@ pub struct Property { pub key: KeyId, /// The id of the node the property belongs to. pub node: NodeId, - /// Whether the property should only affects the first node down the + /// Whether the property should only affect the first node down the /// hierarchy. Used by constructors. pub scoped: bool, /// The property's value. @@ -143,10 +143,10 @@ pub trait Key<'a>: Copy + 'static { /// The name of the property, used for debug printing. const NAME: &'static str; - /// The ids of the key and of the node the key belongs to. + /// The id of the node the key belongs to. fn node() -> NodeId; - /// Compute an output value from a sequence of values belong to this key, + /// Compute an output value from a sequence of values belonging to this key, /// folding if necessary. fn get( chain: StyleChain<'a>, diff --git a/src/model/styles.rs b/src/model/styles.rs index 7d16f4ba..03cdcaac 100644 --- a/src/model/styles.rs +++ b/src/model/styles.rs @@ -216,7 +216,7 @@ impl StyleEntry { } } - /// The highest-level kind of of structure the entry interrupts. + /// The highest-level kind of structure the entry interrupts. pub fn interruption(&self) -> Option<Interruption> { match self { Self::Property(property) => property.interruption(), @@ -328,7 +328,7 @@ impl<'a> StyleChain<'a> { Ok(realized) } - /// Retrieve the current role + /// Retrieve the current role. pub fn role(self) -> Option<Role> { let mut depth = 0; @@ -522,6 +522,15 @@ impl<T> StyleVec<T> { } } + /// Iterate over references to the contained items and associated style maps. + pub fn iter(&self) -> impl Iterator<Item = (&T, &StyleMap)> + '_ { + self.items().zip( + self.maps + .iter() + .flat_map(|(map, count)| iter::repeat(map).take(*count)), + ) + } + /// Iterate over the contained items. pub fn items(&self) -> std::slice::Iter<'_, T> { self.items.iter() @@ -535,15 +544,6 @@ impl<T> StyleVec<T> { pub fn styles(&self) -> impl Iterator<Item = &StyleMap> { self.maps.iter().map(|(map, _)| map) } - - /// Iterate over references to the contained items and associated style maps. - pub fn iter(&self) -> impl Iterator<Item = (&T, &StyleMap)> + '_ { - self.items().zip( - self.maps - .iter() - .flat_map(|(map, count)| iter::repeat(map).take(*count)), - ) - } } impl<T> Default for StyleVec<T> { |
