summaryrefslogtreecommitdiff
path: root/src/layout/text.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2019-11-16 10:37:30 +0100
committerLaurenz <laurmaedje@gmail.com>2019-11-16 10:37:30 +0100
commit261ef9e33a8548d4b7aa53e69e71866648982ae8 (patch)
tree8c98eeb4a4bb2123b45baf1dd4de706a21d619e9 /src/layout/text.rs
parent0917d89bb899380ba897382b4945c8426f25c66d (diff)
Generalize tree layouter 🌲
Diffstat (limited to 'src/layout/text.rs')
-rw-r--r--src/layout/text.rs19
1 files changed, 5 insertions, 14 deletions
diff --git a/src/layout/text.rs b/src/layout/text.rs
index 79ace040..88d83ab7 100644
--- a/src/layout/text.rs
+++ b/src/layout/text.rs
@@ -13,16 +13,6 @@ pub struct TextContext<'a, 'p> {
pub style: &'a TextStyle,
}
-impl<'a, 'p> TextContext<'a, 'p> {
- /// Create a text context from a generic layout context.
- pub fn from_layout_ctx(ctx: LayoutContext<'a, 'p>) -> TextContext<'a, 'p> {
- TextContext {
- loader: ctx.loader,
- style: ctx.style,
- }
- }
-}
-
/// Layouts text into a box.
///
/// There is no complex layout involved. The text is simply laid out left-
@@ -81,7 +71,7 @@ impl<'a, 'p> TextLayouter<'a, 'p> {
}
Ok(Layout {
- dimensions: Size2D::new(self.width, Size::pt(self.ctx.style.font_size)),
+ dimensions: Size2D::new(self.width, self.ctx.style.font_size),
actions: self.actions.into_vec(),
debug_render: false,
})
@@ -107,15 +97,16 @@ impl<'a, 'p> TextLayouter<'a, 'p> {
let glyph = font
.read_table::<CharMap>()?
.get(c)
- .expect("layout text: font should have char");
+ .expect("select_font: font should have char");
let glyph_width = font
.read_table::<HorizontalMetrics>()?
.get(glyph)
- .expect("layout text: font should have glyph")
+ .expect("select_font: font should have glyph")
.advance_width as f32;
- let char_width = font_unit_to_size(glyph_width) * self.ctx.style.font_size;
+ let char_width = font_unit_to_size(glyph_width)
+ * self.ctx.style.font_size.to_pt();
return Ok((index, char_width));
}