mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 13:20:05 -04:00
improve fallback fonts alignment (#2724)
* use font metrics in layout * properly center scaled fonts * adjust docs * fix raised text * fix easymark viewer small text alignment caused by variable row heights
This commit is contained in:
@@ -123,7 +123,8 @@ fn layout_section(
|
||||
paragraph.glyphs.push(Glyph {
|
||||
chr,
|
||||
pos: pos2(paragraph.cursor_x, f32::NAN),
|
||||
size: vec2(glyph_info.advance_width, font_height),
|
||||
size: vec2(glyph_info.advance_width, glyph_info.row_height),
|
||||
ascent: glyph_info.ascent,
|
||||
uv_rect: glyph_info.uv_rect,
|
||||
section_index,
|
||||
});
|
||||
@@ -434,17 +435,31 @@ fn galley_from_rows(point_scale: PointScale, job: Arc<LayoutJob>, mut rows: Vec<
|
||||
let mut max_x: f32 = 0.0;
|
||||
for row in &mut rows {
|
||||
let mut row_height = first_row_min_height.max(row.rect.height());
|
||||
let mut row_ascent = 0.0f32;
|
||||
first_row_min_height = 0.0;
|
||||
for glyph in &row.glyphs {
|
||||
row_height = row_height.max(glyph.size.y);
|
||||
|
||||
// take metrics from the highest font in this row
|
||||
if let Some(glyph) = row
|
||||
.glyphs
|
||||
.iter()
|
||||
.max_by(|a, b| a.size.y.partial_cmp(&b.size.y).unwrap())
|
||||
{
|
||||
row_height = glyph.size.y;
|
||||
row_ascent = glyph.ascent;
|
||||
}
|
||||
row_height = point_scale.round_to_pixel(row_height);
|
||||
|
||||
// Now positions each glyph:
|
||||
for glyph in &mut row.glyphs {
|
||||
let format = &job.sections[glyph.section_index as usize].format;
|
||||
glyph.pos.y = cursor_y + format.valign.to_factor() * (row_height - glyph.size.y);
|
||||
glyph.pos.y = point_scale.round_to_pixel(glyph.pos.y);
|
||||
|
||||
let align_offset = match format.valign {
|
||||
Align::Center | Align::Max => row_ascent,
|
||||
|
||||
// raised text.
|
||||
Align::Min => glyph.ascent,
|
||||
};
|
||||
glyph.pos.y = cursor_y + align_offset;
|
||||
}
|
||||
|
||||
row.rect.min.y = cursor_y;
|
||||
|
||||
Reference in New Issue
Block a user