summaryrefslogtreecommitdiff
path: root/library/src/shared
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-03-19 22:28:49 +0100
committerLaurenz <laurmaedje@gmail.com>2023-03-19 22:39:19 +0100
commitab43bd802eafe33977a91893907e67553e099569 (patch)
treeaf4dead92b143348f52e2e8f869df3f7dfd7322a /library/src/shared
parentd6aaae0cea1e79eecd85dc94ab85b9ad8eff48e8 (diff)
Renaming and refactoring
Diffstat (limited to 'library/src/shared')
-rw-r--r--library/src/shared/behave.rs33
-rw-r--r--library/src/shared/ext.rs32
2 files changed, 33 insertions, 32 deletions
diff --git a/library/src/shared/behave.rs b/library/src/shared/behave.rs
index eff41c0b..6a1aa127 100644
--- a/library/src/shared/behave.rs
+++ b/library/src/shared/behave.rs
@@ -1,14 +1,15 @@
-//! Node interaction.
+//! Element interaction.
use typst::model::{Behave, Behaviour, Content, StyleChain, StyleVec, StyleVecBuilder};
-/// A wrapper around a [`StyleVecBuilder`] that allows items to interact.
+/// A wrapper around a [`StyleVecBuilder`] that allows elements to interact.
#[derive(Debug)]
pub struct BehavedBuilder<'a> {
/// The internal builder.
builder: StyleVecBuilder<'a, Content>,
- /// Staged weak and ignorant items that we can't yet commit to the builder.
- /// The option is `Some(_)` for weak items and `None` for ignorant items.
+ /// Staged weak and ignorant elements that we can't yet commit to the
+ /// builder. The option is `Some(_)` for weak elements and `None` for
+ /// ignorant elements.
staged: Vec<(Content, Behaviour, StyleChain<'a>)>,
/// What the last non-ignorant item was.
last: Behaviour,
@@ -29,7 +30,7 @@ impl<'a> BehavedBuilder<'a> {
self.builder.is_empty() && self.staged.is_empty()
}
- /// Whether the builder is empty except for some weak items that will
+ /// Whether the builder is empty except for some weak elements that will
/// probably collapse.
pub fn is_basically_empty(&self) -> bool {
self.builder.is_empty()
@@ -40,15 +41,15 @@ impl<'a> BehavedBuilder<'a> {
}
/// Push an item into the sequence.
- pub fn push(&mut self, item: Content, styles: StyleChain<'a>) {
- let interaction = item
+ pub fn push(&mut self, elem: Content, styles: StyleChain<'a>) {
+ let interaction = elem
.with::<dyn Behave>()
.map_or(Behaviour::Supportive, Behave::behaviour);
match interaction {
Behaviour::Weak(level) => {
if matches!(self.last, Behaviour::Weak(_)) {
- let item = item.with::<dyn Behave>().unwrap();
+ let item = elem.with::<dyn Behave>().unwrap();
let i = self.staged.iter().position(|prev| {
let Behaviour::Weak(prev_level) = prev.1 else { return false };
level < prev_level
@@ -59,29 +60,29 @@ impl<'a> BehavedBuilder<'a> {
}
if self.last != Behaviour::Destructive {
- self.staged.push((item, interaction, styles));
+ self.staged.push((elem, interaction, styles));
self.last = interaction;
}
}
Behaviour::Supportive => {
self.flush(true);
- self.builder.push(item, styles);
+ self.builder.push(elem, styles);
self.last = interaction;
}
Behaviour::Destructive => {
self.flush(false);
- self.builder.push(item, styles);
+ self.builder.push(elem, styles);
self.last = interaction;
}
Behaviour::Ignorant => {
- self.staged.push((item, interaction, styles));
+ self.staged.push((elem, interaction, styles));
}
}
}
- /// Iterate over the contained items.
- pub fn items(&self) -> impl DoubleEndedIterator<Item = &Content> {
- self.builder.items().chain(self.staged.iter().map(|(item, ..)| item))
+ /// Iterate over the contained elements.
+ pub fn elems(&self) -> impl DoubleEndedIterator<Item = &Content> {
+ self.builder.elems().chain(self.staged.iter().map(|(item, ..)| item))
}
/// Return the finish style vec and the common prefix chain.
@@ -90,7 +91,7 @@ impl<'a> BehavedBuilder<'a> {
self.builder.finish()
}
- /// Push the staged items, filtering out weak items if `supportive` is
+ /// Push the staged elements, filtering out weak elements if `supportive` is
/// false.
fn flush(&mut self, supportive: bool) {
for (item, interaction, styles) in self.staged.drain(..) {
diff --git a/library/src/shared/ext.rs b/library/src/shared/ext.rs
index 14674c9d..72a82749 100644
--- a/library/src/shared/ext.rs
+++ b/library/src/shared/ext.rs
@@ -1,8 +1,8 @@
//! Extension traits.
-use crate::layout::{AlignNode, MoveNode, PadNode};
+use crate::layout::{AlignElem, MoveElem, PadElem};
use crate::prelude::*;
-use crate::text::{EmphNode, FontFamily, FontList, StrongNode, TextNode, UnderlineNode};
+use crate::text::{EmphElem, FontFamily, FontList, StrongElem, TextElem, UnderlineElem};
/// Additional methods on content.
pub trait ContentExt {
@@ -16,7 +16,7 @@ pub trait ContentExt {
fn underlined(self) -> Self;
/// Link the content somewhere.
- fn linked(self, link: Link) -> Self;
+ fn linked(self, dest: Destination) -> Self;
/// Set alignments for this content.
fn aligned(self, aligns: Axes<Option<GenAlign>>) -> Self;
@@ -30,27 +30,27 @@ pub trait ContentExt {
impl ContentExt for Content {
fn strong(self) -> Self {
- StrongNode::new(self).pack()
+ StrongElem::new(self).pack()
}
fn emph(self) -> Self {
- EmphNode::new(self).pack()
+ EmphElem::new(self).pack()
}
fn underlined(self) -> Self {
- UnderlineNode::new(self).pack()
+ UnderlineElem::new(self).pack()
}
- fn linked(self, link: Link) -> Self {
- self.styled(MetaNode::set_data(vec![Meta::Link(link)]))
+ fn linked(self, dest: Destination) -> Self {
+ self.styled(MetaElem::set_data(vec![Meta::Link(dest)]))
}
fn aligned(self, aligns: Axes<Option<GenAlign>>) -> Self {
- self.styled(AlignNode::set_alignment(aligns))
+ self.styled(AlignElem::set_alignment(aligns))
}
fn padded(self, padding: Sides<Rel<Length>>) -> Self {
- PadNode::new(self)
+ PadElem::new(self)
.with_left(padding.left)
.with_top(padding.top)
.with_right(padding.right)
@@ -59,22 +59,22 @@ impl ContentExt for Content {
}
fn moved(self, delta: Axes<Rel<Length>>) -> Self {
- MoveNode::new(self).with_dx(delta.x).with_dy(delta.y).pack()
+ MoveElem::new(self).with_dx(delta.x).with_dy(delta.y).pack()
}
}
-/// Additional methods for style maps.
-pub trait StyleMapExt {
+/// Additional methods for style lists.
+pub trait StylesExt {
/// Set a font family composed of a preferred family and existing families
/// from a style chain.
fn set_family(&mut self, preferred: FontFamily, existing: StyleChain);
}
-impl StyleMapExt for StyleMap {
+impl StylesExt for Styles {
fn set_family(&mut self, preferred: FontFamily, existing: StyleChain) {
- self.set(TextNode::set_font(FontList(
+ self.set(TextElem::set_font(FontList(
std::iter::once(preferred)
- .chain(TextNode::font_in(existing))
+ .chain(TextElem::font_in(existing))
.collect(),
)));
}