From 521b087269acb6032d5040fa8bad33e84dbadede Mon Sep 17 00:00:00 2001 From: Bu5hm4nn Date: Sun, 11 Feb 2024 12:21:30 -0600 Subject: [PATCH] Fix https://github.com/mikedilger/gossip/issues/336 and https://github.com/mikedilger/gossip/issues/347 by ensuring ui.placer.region.cursor is set to the correct line height. --- crates/egui/src/widgets/label.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/crates/egui/src/widgets/label.rs b/crates/egui/src/widgets/label.rs index d2085d4fb49..16217e8511d 100644 --- a/crates/egui/src/widgets/label.rs +++ b/crates/egui/src/widgets/label.rs @@ -181,6 +181,16 @@ impl Label { let pos = pos2(ui.max_rect().left(), ui.cursor().top()); assert!(!galley.rows.is_empty(), "Galleys are never empty"); + + // set the row height to ensure the cursor advancement is correct. when creating a child ui such as with + // ui.horizontal_wrapped, the initial cursor will be set to the height of the child ui. this can lead + // to the cursor not advancing to the second row but rather expanding the height of the cursor. + // + // note that we do not set the row height earlier in this function as we do want to allow populating + // `first_row_min_height` above. however it is crucial the placer knows the actual row height by + // setting the cursor height before ui.allocate_rect() gets called. + ui.set_row_height(galley.rows[0].height()); + // collect a response from many rows: let rect = galley.rows[0].rect.translate(vec2(pos.x, pos.y)); let mut response = ui.allocate_rect(rect, sense);