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,
|
sizing::Sizing,
|
||||||
Size,
|
Size,
|
||||||
};
|
};
|
||||||
use egui::Ui;
|
use egui::{Response, Ui};
|
||||||
|
|
||||||
/// The direction in which cells are positioned in the grid.
|
/// 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.
|
/// 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!
|
/// 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
|
where
|
||||||
F: for<'b> FnOnce(Grid<'a, 'b>),
|
F: for<'b> FnOnce(Grid<'a, 'b>),
|
||||||
{
|
{
|
||||||
|
@ -58,11 +60,14 @@ impl<'a> GridBuilder<'a> {
|
||||||
direction: GridDirection::Horizontal,
|
direction: GridDirection::Horizontal,
|
||||||
sizes: widths,
|
sizes: widths,
|
||||||
});
|
});
|
||||||
|
layout.set_rect()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Build vertical grid: Cells are positions from top to bottom.
|
/// 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!
|
/// 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
|
where
|
||||||
F: for<'b> FnOnce(Grid<'a, 'b>),
|
F: for<'b> FnOnce(Grid<'a, 'b>),
|
||||||
{
|
{
|
||||||
|
@ -76,6 +81,7 @@ impl<'a> GridBuilder<'a> {
|
||||||
direction: GridDirection::Vertical,
|
direction: GridDirection::Vertical,
|
||||||
sizes: heights,
|
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)) {
|
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());
|
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);
|
add_contents(&mut child_ui);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Drop for Layout<'a> {
|
/// Set the rect so that the scrollview knows about our size
|
||||||
fn drop(&mut self) {
|
pub fn set_rect(&mut self) -> Response {
|
||||||
self.set_rect();
|
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);
|
header(row);
|
||||||
}
|
}
|
||||||
|
layout.set_rect();
|
||||||
}
|
}
|
||||||
|
|
||||||
Table {
|
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> {
|
pub struct TableRow<'a, 'b> {
|
||||||
layout: &'b mut Layout<'a>,
|
layout: &'b mut Layout<'a>,
|
||||||
widths: Vec<f32>,
|
widths: Vec<f32>,
|
||||||
|
|
Loading…
Reference in a new issue