1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-02-23 13:02:03 +00:00

fix(core/rust): fix glyph positioning in TextOverlay

This commit is contained in:
tychovrahe 2022-10-20 12:55:23 +02:00
parent c55d599565
commit d8838a9135

View File

@ -250,12 +250,21 @@ pub struct TextOverlay<T> {
area: Rect,
text: T,
font: Font,
max_height: i16,
baseline: i16,
}
impl<T: AsRef<str>> TextOverlay<T> {
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<T: AsRef<str>> TextOverlay<T> {
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;