Fix interaction with widgets inside selectable rows of `Table` (#4077)

* Closes https://github.com/emilk/egui/issues/4047
This commit is contained in:
Emil Ernerfeldt 2024-02-20 14:50:13 +01:00 committed by GitHub
parent 9096abdeec
commit 4fc0c49a6b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 4 deletions

View File

@ -146,7 +146,9 @@ impl<'l> StripLayout<'l> {
);
}
let used_rect = self.cell(flags, max_rect, child_ui_id_source, add_cell_contents);
let child_ui = self.cell(flags, max_rect, child_ui_id_source, add_cell_contents);
let used_rect = child_ui.min_rect();
self.set_pos(max_rect);
@ -156,7 +158,9 @@ impl<'l> StripLayout<'l> {
max_rect.union(used_rect)
};
let response = self.ui.allocate_rect(allocation_rect, self.sense);
self.ui.advance_cursor_after_rect(allocation_rect);
let response = child_ui.interact(max_rect, child_ui.id(), self.sense);
(used_rect, response)
}
@ -183,13 +187,14 @@ impl<'l> StripLayout<'l> {
self.ui.allocate_rect(rect, Sense::hover());
}
/// Return the Ui to which the contents where added
fn cell(
&mut self,
flags: StripLayoutFlags,
rect: Rect,
child_ui_id_source: egui::Id,
add_cell_contents: impl FnOnce(&mut Ui),
) -> Rect {
) -> Ui {
let mut child_ui =
self.ui
.child_ui_with_id_source(rect, self.cell_layout, child_ui_id_source);
@ -208,7 +213,7 @@ impl<'l> StripLayout<'l> {
add_cell_contents(&mut child_ui);
child_ui.min_rect()
child_ui
}
/// Allocate the rect in [`Self::ui`] so that the scrollview knows about our size