Fix bug in size calculation of truncated text (#5076)
The width of the elision character (`…`) was never included in the size calculation
This commit is contained in:
parent
7cb61f8031
commit
b2dcb7d8db
|
|
@ -98,6 +98,9 @@ pub fn layout(fonts: &mut FontsImpl, job: Arc<LayoutJob>) -> Galley {
|
|||
if elided {
|
||||
if let Some(last_row) = rows.last_mut() {
|
||||
replace_last_glyph_with_overflow_character(fonts, &job, last_row);
|
||||
if let Some(last) = last_row.glyphs.last() {
|
||||
last_row.rect.max.x = last.max_x();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1115,4 +1118,21 @@ mod tests {
|
|||
vec!["日本語とEnglish", "の混在した文章"]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_truncate_width() {
|
||||
let mut fonts = FontsImpl::new(1.0, 1024, FontDefinitions::default());
|
||||
let mut layout_job =
|
||||
LayoutJob::single_section("# DNA\nMore text".into(), TextFormat::default());
|
||||
layout_job.wrap.max_width = f32::INFINITY;
|
||||
layout_job.wrap.max_rows = 1;
|
||||
let galley = layout(&mut fonts, layout_job.into());
|
||||
assert!(galley.elided);
|
||||
assert_eq!(
|
||||
galley.rows.iter().map(|row| row.text()).collect::<Vec<_>>(),
|
||||
vec!["# DNA…"]
|
||||
);
|
||||
let row = &galley.rows[0];
|
||||
assert_eq!(row.rect.max.x, row.glyphs.last().unwrap().max_x());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue