1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
//! Extension traits.
use crate::layout::{AlignNode, MoveNode, PadNode};
use crate::prelude::*;
use crate::text::{EmphNode, FontFamily, FontList, StrongNode, TextNode, UnderlineNode};
/// Additional methods on content.
pub trait ContentExt {
/// Make this content strong.
fn strong(self) -> Self;
/// Make this content emphasized.
fn emph(self) -> Self;
/// Underline this content.
fn underlined(self) -> Self;
/// Link the content somewhere.
fn linked(self, link: Link) -> Self;
/// Set alignments for this content.
fn aligned(self, aligns: Axes<Option<GenAlign>>) -> Self;
/// Pad this content at the sides.
fn padded(self, padding: Sides<Rel<Length>>) -> Self;
/// Transform this content's contents without affecting layout.
fn moved(self, delta: Axes<Rel<Length>>) -> Self;
}
impl ContentExt for Content {
fn strong(self) -> Self {
StrongNode::new(self).pack()
}
fn emph(self) -> Self {
EmphNode::new(self).pack()
}
fn underlined(self) -> Self {
UnderlineNode::new(self).pack()
}
fn linked(self, link: Link) -> Self {
self.styled(MetaNode::set_data(vec![Meta::Link(link)]))
}
fn aligned(self, aligns: Axes<Option<GenAlign>>) -> Self {
self.styled(AlignNode::set_alignment(aligns))
}
fn padded(self, padding: Sides<Rel<Length>>) -> Self {
PadNode::new(self)
.with_left(padding.left)
.with_top(padding.top)
.with_right(padding.right)
.with_bottom(padding.bottom)
.pack()
}
fn moved(self, delta: Axes<Rel<Length>>) -> Self {
MoveNode::new(self).with_dx(delta.x).with_dy(delta.y).pack()
}
}
/// Additional methods for style maps.
pub trait StyleMapExt {
/// 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 {
fn set_family(&mut self, preferred: FontFamily, existing: StyleChain) {
self.set(TextNode::set_font(FontList(
std::iter::once(preferred)
.chain(TextNode::font_in(existing))
.collect(),
)));
}
}
|