mirror of
https://github.com/emilk/egui.git
synced 2026-08-29 21:00:03 -04:00
Use Font::ascent for the logical rect, but FontImpl::ascent for centering
This commit is contained in:
@@ -172,7 +172,8 @@ fn layout_section(
|
||||
chr,
|
||||
pos: pos2(paragraph.cursor_x, f32::NAN),
|
||||
size: vec2(glyph_info.advance_width, line_height),
|
||||
ascent: font.ascent(),
|
||||
font_impl_ascent: font_impl.map_or(0.0, |f| f.ascent()),
|
||||
font_ascent: font.ascent(),
|
||||
uv_rect: glyph_info.uv_rect,
|
||||
section_index,
|
||||
});
|
||||
@@ -392,7 +393,8 @@ fn replace_last_glyph_with_overflow_character(
|
||||
chr: overflow_character,
|
||||
pos: pos2(x, f32::NAN),
|
||||
size: vec2(replacement_glyph_info.advance_width, line_height),
|
||||
ascent: font.ascent(),
|
||||
font_impl_ascent: font_impl.map_or(0.0, |f| f.ascent()),
|
||||
font_ascent: font.ascent(),
|
||||
uv_rect: replacement_glyph_info.uv_rect,
|
||||
section_index,
|
||||
});
|
||||
@@ -404,13 +406,14 @@ fn replace_last_glyph_with_overflow_character(
|
||||
|
||||
let x = 0.0; // TODO(emilk): heed paragraph leading_space 😬
|
||||
|
||||
let (_, replacement_glyph_info) = font.font_impl_and_glyph_info(overflow_character);
|
||||
let (font_impl, replacement_glyph_info) = font.font_impl_and_glyph_info(overflow_character);
|
||||
|
||||
row.glyphs.push(Glyph {
|
||||
chr: overflow_character,
|
||||
pos: pos2(x, f32::NAN),
|
||||
size: vec2(replacement_glyph_info.advance_width, line_height),
|
||||
ascent: font.ascent(),
|
||||
font_impl_ascent: font_impl.map_or(0.0, |f| f.ascent()),
|
||||
font_ascent: font.ascent(),
|
||||
uv_rect: replacement_glyph_info.uv_rect,
|
||||
section_index,
|
||||
});
|
||||
@@ -596,8 +599,9 @@ fn galley_from_rows(
|
||||
for glyph in &mut row.glyphs {
|
||||
let format = &job.sections[glyph.section_index as usize].format;
|
||||
|
||||
glyph.pos.y =
|
||||
cursor_y + glyph.ascent + format.valign.to_factor() * (row_height - glyph.size.y);
|
||||
glyph.pos.y = cursor_y
|
||||
+ glyph.font_impl_ascent
|
||||
+ format.valign.to_factor() * (row_height - glyph.size.y);
|
||||
|
||||
glyph.pos.y = point_scale.round_to_pixel(glyph.pos.y);
|
||||
}
|
||||
|
||||
@@ -608,8 +608,11 @@ pub struct Glyph {
|
||||
/// Logical position: pos.y is the same for all chars of the same [`TextFormat`].
|
||||
pub pos: Pos2,
|
||||
|
||||
/// `ascent` value from the font
|
||||
pub ascent: f32,
|
||||
/// `ascent` value from the `Font`
|
||||
pub font_ascent: f32,
|
||||
|
||||
/// `ascent` value from the `FontImpl`
|
||||
pub font_impl_ascent: f32,
|
||||
|
||||
/// Advance width and line height.
|
||||
///
|
||||
@@ -631,7 +634,7 @@ impl Glyph {
|
||||
/// Same y range for all characters with the same [`TextFormat`].
|
||||
#[inline]
|
||||
pub fn logical_rect(&self) -> Rect {
|
||||
Rect::from_min_size(self.pos - vec2(0.0, self.ascent), self.size)
|
||||
Rect::from_min_size(self.pos - vec2(0.0, self.font_ascent), self.size)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user