mirror of
https://github.com/emilk/egui.git
synced 2026-09-03 07:10:04 -04:00
Properly respect the text valign, by individually aligning glyphs
This commit is contained in:
@@ -585,40 +585,29 @@ fn galley_from_rows(
|
|||||||
let mut min_x: f32 = 0.0;
|
let mut min_x: f32 = 0.0;
|
||||||
let mut max_x: f32 = 0.0;
|
let mut max_x: f32 = 0.0;
|
||||||
for row in &mut rows {
|
for row in &mut rows {
|
||||||
let mut line_height = first_row_min_height.max(row.rect.height());
|
let mut row_height = first_row_min_height.max(row.rect.height());
|
||||||
let mut row_ascent = 0.0f32;
|
|
||||||
first_row_min_height = 0.0;
|
first_row_min_height = 0.0;
|
||||||
|
for glyph in &row.glyphs {
|
||||||
// take metrics from the highest font in this row
|
row_height = row_height.max(glyph.size.y);
|
||||||
if let Some(glyph) = row
|
|
||||||
.glyphs
|
|
||||||
.iter()
|
|
||||||
.max_by(|a, b| a.size.y.partial_cmp(&b.size.y).unwrap())
|
|
||||||
{
|
|
||||||
line_height = glyph.size.y;
|
|
||||||
row_ascent = glyph.ascent;
|
|
||||||
}
|
}
|
||||||
line_height = point_scale.round_to_pixel(line_height);
|
row_height = point_scale.round_to_pixel(row_height);
|
||||||
|
|
||||||
// Now positions each glyph:
|
// Now positions each glyph:
|
||||||
for glyph in &mut row.glyphs {
|
for glyph in &mut row.glyphs {
|
||||||
let format = &job.sections[glyph.section_index as usize].format;
|
let format = &job.sections[glyph.section_index as usize].format;
|
||||||
|
|
||||||
let align_offset = match format.valign {
|
glyph.pos.y =
|
||||||
Align::Center | Align::Max => row_ascent,
|
cursor_y + glyph.ascent + format.valign.to_factor() * (row_height - glyph.size.y);
|
||||||
|
|
||||||
// raised text.
|
glyph.pos.y = point_scale.round_to_pixel(glyph.pos.y);
|
||||||
Align::Min => glyph.ascent,
|
|
||||||
};
|
|
||||||
glyph.pos.y = cursor_y + align_offset;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
row.rect.min.y = cursor_y;
|
row.rect.min.y = cursor_y;
|
||||||
row.rect.max.y = cursor_y + line_height;
|
row.rect.max.y = cursor_y + row_height;
|
||||||
|
|
||||||
min_x = min_x.min(row.rect.min.x);
|
min_x = min_x.min(row.rect.min.x);
|
||||||
max_x = max_x.max(row.rect.max.x);
|
max_x = max_x.max(row.rect.max.x);
|
||||||
cursor_y += line_height;
|
cursor_y += row_height;
|
||||||
cursor_y = point_scale.round_to_pixel(cursor_y);
|
cursor_y = point_scale.round_to_pixel(cursor_y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user