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
//! Text constructors.
//!
//! [`text`] is default body text. [`h1`] / [`h2`] / [`h3`] are heading
//! constructors used directly.
//!
//! Modifiers (`.muted`, `.bold`, `.semibold`, `.small`, `.color`, etc.)
//! are inherent methods on [`El`]; see [`crate::style`].
// Lock in full per-item documentation for this module (issue #73).
#![warn(missing_docs)]
use std::panic::Location;
use crate::style::StyleProfile;
use crate::tree::*;
/// Default body text leaf — single-line, hug-sized, [`TextRole::Body`].
#[track_caller]
pub fn text(s: impl Into<String>) -> El {
El::new(Kind::Text)
.at_loc(Location::caller())
.style_profile(StyleProfile::TextOnly)
.text(s)
.text_role(TextRole::Body)
.hug()
}
/// Body text that wraps — full-width with wrapping enabled, like an HTML `<p>`.
#[track_caller]
pub fn paragraph(s: impl Into<String>) -> El {
text(s)
.at_loc(Location::caller())
.wrap_text()
.fill_width()
.height(Size::Hug)
}
/// Top-level heading ([`TextRole::Display`]) — like an HTML `<h1>`.
#[track_caller]
pub fn h1(s: impl Into<String>) -> El {
El::new(Kind::Heading)
.at_loc(Location::caller())
.style_profile(StyleProfile::TextOnly)
.text(s)
.text_role(TextRole::Display)
.hug()
}
/// Section heading ([`TextRole::Heading`]) — like an HTML `<h2>`.
#[track_caller]
pub fn h2(s: impl Into<String>) -> El {
El::new(Kind::Heading)
.at_loc(Location::caller())
.style_profile(StyleProfile::TextOnly)
.text(s)
.text_role(TextRole::Heading)
.hug()
}
/// Subsection heading ([`TextRole::Title`]) — like an HTML `<h3>`.
#[track_caller]
pub fn h3(s: impl Into<String>) -> El {
El::new(Kind::Heading)
.at_loc(Location::caller())
.style_profile(StyleProfile::TextOnly)
.text(s)
.text_role(TextRole::Title)
.hug()
}
/// Inline monospace text — body text with the `.code()` modifier applied, like an HTML `<code>`.
#[track_caller]
pub fn mono(s: impl Into<String>) -> El {
text(s).code()
}