diff --git a/egui_extras/src/grid.rs b/egui_extras/src/grid.rs index 1765e631..3e9092dd 100644 --- a/egui_extras/src/grid.rs +++ b/egui_extras/src/grid.rs @@ -3,7 +3,7 @@ use crate::{ sizing::Sizing, Size, }; -use egui::Ui; +use egui::{Response, Ui}; /// The direction in which cells are positioned in the grid. /// @@ -44,7 +44,9 @@ impl<'a> GridBuilder<'a> { /// Build horizontal grid: Cells are positions from left to right. /// Takes the available horizontal width, so there can't be anything right of the grid or the container will grow slowly! - pub fn horizontal(self, grid: F) + /// + /// Returns a `[egui::Response]` for hover events. + pub fn horizontal(self, grid: F) -> Response where F: for<'b> FnOnce(Grid<'a, 'b>), { @@ -58,11 +60,14 @@ impl<'a> GridBuilder<'a> { direction: GridDirection::Horizontal, sizes: widths, }); + layout.set_rect() } /// Build vertical grid: Cells are positions from top to bottom. /// Takes the full available vertical height, so there can't be anything below of the grid or the container will grow slowly! - pub fn vertical(self, grid: F) + /// + /// Returns a `[egui::Response]` for hover events. + pub fn vertical(self, grid: F) -> Response where F: for<'b> FnOnce(Grid<'a, 'b>), { @@ -76,6 +81,7 @@ impl<'a> GridBuilder<'a> { direction: GridDirection::Vertical, sizes: heights, }); + layout.set_rect() } } diff --git a/egui_extras/src/layout.rs b/egui_extras/src/layout.rs index fc8d211a..0a9a4052 100644 --- a/egui_extras/src/layout.rs +++ b/egui_extras/src/layout.rs @@ -141,15 +141,6 @@ impl<'l> Layout<'l> { } } - /// Set the rect so that the scrollview knows about our size - fn set_rect(&mut self) { - let mut rect = self.rect; - rect.set_right(self.max.x); - rect.set_bottom(self.max.y); - - self.ui.allocate_rect(rect, Sense::hover()); - } - fn cell(&mut self, rect: Rect, clip: bool, add_contents: impl FnOnce(&mut Ui)) { let mut child_ui = self.ui.child_ui(rect, *self.ui.layout()); @@ -162,10 +153,13 @@ impl<'l> Layout<'l> { add_contents(&mut child_ui); } -} -impl<'a> Drop for Layout<'a> { - fn drop(&mut self) { - self.set_rect(); + /// Set the rect so that the scrollview knows about our size + pub fn set_rect(&mut self) -> Response { + let mut rect = self.rect; + rect.set_right(self.max.x); + rect.set_bottom(self.max.y); + + self.ui.allocate_rect(rect, Sense::hover()) } } diff --git a/egui_extras/src/table.rs b/egui_extras/src/table.rs index 244d91f1..85c9c4b2 100644 --- a/egui_extras/src/table.rs +++ b/egui_extras/src/table.rs @@ -81,6 +81,7 @@ impl<'a> TableBuilder<'a> { }; header(row); } + layout.set_rect(); } Table { @@ -221,6 +222,12 @@ impl<'a> TableBody<'a> { } } +impl<'a> Drop for TableBody<'a> { + fn drop(&mut self) { + self.layout.set_rect(); + } +} + pub struct TableRow<'a, 'b> { layout: &'b mut Layout<'a>, widths: Vec,