1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-26 14:49:06 -04:00

Fixes the overly aggressive overflow elision in truncate() and similar for os scaling other than 100% (#7867)

* Closes #7818
* [x] I have followed the instructions in the PR template

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
RndUsr123
2026-03-03 07:46:45 +00:00
committed by GitHub
parent 1b8a9fe95e
commit 124bde4883

View File

@@ -495,7 +495,9 @@ fn replace_last_glyph_with_overflow_character(
let replacement_glyph_width = font_face
.as_mut()
.and_then(|f| f.glyph_info(overflow_character))
.map(|i| i.advance_width_unscaled.0 * font_face_metrics.px_scale_factor)
.map(|i| {
i.advance_width_unscaled.0 * font_face_metrics.px_scale_factor / pixels_per_point
})
.unwrap_or_default();
// Check if we're within width budget:
@@ -1166,6 +1168,42 @@ mod tests {
assert_eq!(row.rect().max.x, row.glyphs.last().unwrap().max_x());
}
#[test]
fn test_truncate_with_pixels_per_point() {
let mut fonts = FontsImpl::new(TextOptions::default(), FontDefinitions::default());
for pixels_per_point in [
0.33, 0.5, 0.67, 1.0, 1.25, 1.33, 1.5, 1.75, 2.0, 3.0, 4.0, 5.0,
] {
for ch in ['W', 'A', 'n', 't', 'i'] {
let target_width = 50.0;
let text = (0..20).map(|_| ch).collect::<String>();
let mut job = LayoutJob::single_section(text, TextFormat::default());
job.wrap.max_width = target_width;
job.wrap.max_rows = 1;
let elided_galley = layout(&mut fonts, pixels_per_point, job.into());
assert!(elided_galley.elided);
let test_galley = layout(
&mut fonts,
pixels_per_point,
Arc::new(LayoutJob::single_section(
(0..elided_galley.rows[0].char_count_excluding_newline())
.map(|_| ch)
.chain(std::iter::once('…'))
.collect::<String>(),
TextFormat::default(),
)),
);
assert!(elided_galley.size().x >= 0.0);
assert!(elided_galley.size().x <= target_width);
assert!(test_galley.size().x > target_width);
}
}
}
#[test]
fn test_empty_row() {
let pixels_per_point = 1.0;