From d8838a9135bcae786e2e4268727a36bec10e3be2 Mon Sep 17 00:00:00 2001 From: tychovrahe Date: Thu, 20 Oct 2022 12:55:23 +0200 Subject: [PATCH] fix(core/rust): fix glyph positioning in TextOverlay --- core/embed/rust/src/ui/display/mod.rs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/core/embed/rust/src/ui/display/mod.rs b/core/embed/rust/src/ui/display/mod.rs index 14383971b2..9e8a95a48b 100644 --- a/core/embed/rust/src/ui/display/mod.rs +++ b/core/embed/rust/src/ui/display/mod.rs @@ -250,12 +250,21 @@ pub struct TextOverlay { area: Rect, text: T, font: Font, + max_height: i16, + baseline: i16, } impl> TextOverlay { pub fn new(text: T, font: Font) -> Self { let area = Rect::zero(); - Self { area, text, font } + + Self { + area, + text, + font, + max_height: font.max_height(), + baseline: font.baseline(), + } } pub fn set_text(&mut self, text: T) { @@ -287,15 +296,11 @@ impl> TextOverlay { let p_rel = Point::new(p.x - self.area.x0, p.y - self.area.y0); - for g in self - .text - .as_ref() - .bytes() - .filter_map(|c| self.font.get_glyph(c)) - { + for g in self.text.as_ref().bytes().filter_map(|c| self.font.get_glyph(c)) { + let top = self.max_height - self.baseline - g.bearing_y; let char_area = Rect::new( - Point::new(tot_adv + g.bearing_x, g.height - g.bearing_y), - Point::new(tot_adv + g.bearing_x + g.width, g.bearing_y), + Point::new(tot_adv + g.bearing_x, top), + Point::new(tot_adv + g.bearing_x + g.width, top + g.height), ); tot_adv += g.adv;