summaryrefslogtreecommitdiff
path: root/src/style.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2019-12-30 22:28:56 +0100
committerLaurenz <laurmaedje@gmail.com>2019-12-30 22:28:56 +0100
commit269f069a4d721a986807293ef71be1348bfae3d4 (patch)
tree31b737c4ff2aead3eb5e2673828595bb26622032 /src/style.rs
parentb8620121a692df6313eeb5ccf7baf89c1e364116 (diff)
Simple line layouter 🧾
Diffstat (limited to 'src/style.rs')
-rw-r--r--src/style.rs27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/style.rs b/src/style.rs
index eb0de5da..df5e13d1 100644
--- a/src/style.rs
+++ b/src/style.rs
@@ -26,11 +26,11 @@ pub struct TextStyle {
/// The font scale to apply on the base font size.
pub font_scale: f32,
/// The word spacing (as a multiple of the font size).
- pub word_spacing: f32,
+ pub word_spacing_scale: f32,
/// The line spacing (as a multiple of the font size).
- pub line_spacing: f32,
+ pub line_spacing_scale: f32,
/// The paragraphs spacing (as a multiple of the font size).
- pub paragraph_spacing: f32,
+ pub paragraph_spacing_scale: f32,
}
impl TextStyle {
@@ -39,6 +39,21 @@ impl TextStyle {
self.base_font_size * self.font_scale
}
+ /// The absolute word spacing.
+ pub fn word_spacing(&self) -> Size {
+ self.word_spacing_scale * self.font_size()
+ }
+
+ /// The absolute line spacing.
+ pub fn line_spacing(&self) -> Size {
+ (self.line_spacing_scale - 1.0) * self.font_size()
+ }
+
+ /// The absolute paragraph spacing.
+ pub fn paragraph_spacing(&self) -> Size {
+ (self.paragraph_spacing_scale - 1.0) * self.font_size()
+ }
+
/// Toggle a class.
///
/// If the class was one of _italic_ or _bold_, then:
@@ -82,9 +97,9 @@ impl Default for TextStyle {
fallback: vec![Serif],
base_font_size: Size::pt(11.0),
font_scale: 1.0,
- word_spacing: 0.25,
- line_spacing: 1.2,
- paragraph_spacing: 1.5,
+ word_spacing_scale: 0.25,
+ line_spacing_scale: 1.2,
+ paragraph_spacing_scale: 1.5,
}
}
}