mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-07-07 07:12:34 +00:00
fix(core/rust): fix glyph positioning in TextOverlay
This commit is contained in:
parent
c55d599565
commit
d8838a9135
@ -250,12 +250,21 @@ pub struct TextOverlay<T> {
|
|||||||
area: Rect,
|
area: Rect,
|
||||||
text: T,
|
text: T,
|
||||||
font: Font,
|
font: Font,
|
||||||
|
max_height: i16,
|
||||||
|
baseline: i16,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: AsRef<str>> TextOverlay<T> {
|
impl<T: AsRef<str>> TextOverlay<T> {
|
||||||
pub fn new(text: T, font: Font) -> Self {
|
pub fn new(text: T, font: Font) -> Self {
|
||||||
let area = Rect::zero();
|
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) {
|
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);
|
let p_rel = Point::new(p.x - self.area.x0, p.y - self.area.y0);
|
||||||
|
|
||||||
for g in self
|
for g in self.text.as_ref().bytes().filter_map(|c| self.font.get_glyph(c)) {
|
||||||
.text
|
let top = self.max_height - self.baseline - g.bearing_y;
|
||||||
.as_ref()
|
|
||||||
.bytes()
|
|
||||||
.filter_map(|c| self.font.get_glyph(c))
|
|
||||||
{
|
|
||||||
let char_area = Rect::new(
|
let char_area = Rect::new(
|
||||||
Point::new(tot_adv + g.bearing_x, g.height - g.bearing_y),
|
Point::new(tot_adv + g.bearing_x, top),
|
||||||
Point::new(tot_adv + g.bearing_x + g.width, g.bearing_y),
|
Point::new(tot_adv + g.bearing_x + g.width, top + g.height),
|
||||||
);
|
);
|
||||||
|
|
||||||
tot_adv += g.adv;
|
tot_adv += g.adv;
|
||||||
|
Loading…
Reference in New Issue
Block a user