1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-29 04:40:03 -04:00

Fix text layout bugs in wrapped texts (#8137)

Fixes some bugs that happen randomly when resizing horizontal_wrapped
texts:


https://github.com/user-attachments/assets/141392d2-0239-465a-ba7b-c864f7823319

Adds regression tests (I enjoy using claude to fix these bugs, first
have it create a minimal repro test case, then fix the bug by iterating
until it figures out a fix).
This commit is contained in:
Lucas Meurer
2026-05-04 13:45:50 +02:00
committed by GitHub
parent fe8b1edfc6
commit e9b8c0d918
3 changed files with 105 additions and 7 deletions

View File

@@ -726,18 +726,19 @@ fn line_break(
if job.wrap.max_rows <= out_rows.len() {
*elided = true; // can't fit another row
} else {
let paragraph_min_x = paragraph.glyphs[row_start_idx].pos.x - row_start_x;
let paragraph_max_x = paragraph.glyphs.last().unwrap().max_x() - row_start_x;
let glyphs: Vec<Glyph> = paragraph.glyphs[row_start_idx..]
.iter()
.copied()
.map(|mut glyph| {
glyph.pos.x -= row_start_x;
glyph.pos.x -= row_start_x + paragraph_min_x;
glyph
})
.collect();
let section_index_at_start = glyphs[0].section_index;
let paragraph_min_x = glyphs[0].pos.x;
let paragraph_max_x = glyphs.last().unwrap().max_x();
out_rows.push(PlacedRow {
pos: pos2(paragraph_min_x, 0.0),

View File

@@ -707,9 +707,12 @@ impl PlacedRow {
/// Same as [`Self::rect`] but excluding the `LayoutSection::leading_space`.
pub fn rect_without_leading_space(&self) -> Rect {
let x = self.glyphs.first().map_or(self.pos.x, |g| g.pos.x);
let size_x = self.size.x - x;
Rect::from_min_size(Pos2::new(x, self.pos.y), Vec2::new(size_x, self.size.y))
let x = self.pos.x + self.glyphs.first().map_or(0.0, |g| g.pos.x);
let right = self.pos.x + self.size.x;
Rect::from_min_max(
Pos2::new(x, self.pos.y),
Pos2::new(right, self.pos.y + self.size.y),
)
}
}