return response for hover events on grid
This commit is contained in:
parent
35c8e97b75
commit
5ccfa1117e
3 changed files with 23 additions and 16 deletions
|
@ -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<F>(self, grid: F)
|
||||
///
|
||||
/// Returns a `[egui::Response]` for hover events.
|
||||
pub fn horizontal<F>(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<F>(self, grid: F)
|
||||
///
|
||||
/// Returns a `[egui::Response]` for hover events.
|
||||
pub fn vertical<F>(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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<f32>,
|
||||
|
|
Loading…
Reference in a new issue