[grid] Allow putting a separator in a grid
This commit is contained in:
parent
a5ce1ba711
commit
07f1b074ca
5 changed files with 27 additions and 12 deletions
|
@ -82,15 +82,25 @@ impl GridLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn available_rect(&self, region: &Region) -> Rect {
|
pub(crate) fn available_rect(&self, region: &Region) -> Rect {
|
||||||
let mut rect = Rect::from_min_max(region.cursor, region.max_rect.max);
|
// let mut rect = Rect::from_min_max(region.cursor, region.max_rect.max);
|
||||||
rect.set_height(rect.height().at_least(self.min_row_height));
|
// rect.set_height(rect.height().at_least(self.min_row_height));
|
||||||
rect
|
// rect
|
||||||
|
self.available_rect_finite(region)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn available_rect_finite(&self, region: &Region) -> Rect {
|
pub(crate) fn available_rect_finite(&self, region: &Region) -> Rect {
|
||||||
let mut rect = Rect::from_min_max(region.cursor, region.max_rect_finite().max);
|
// If we want to allow width-filling widgets like `Separator` in one of the first cells
|
||||||
rect.set_height(rect.height().at_least(self.min_row_height));
|
// then we need to make sure they don't spill out of the first cell:
|
||||||
rect
|
let width = self
|
||||||
|
.prev_state
|
||||||
|
.col_width(self.col)
|
||||||
|
.or_else(|| self.curr_state.col_width(self.col))
|
||||||
|
.unwrap_or_default();
|
||||||
|
let height = region
|
||||||
|
.max_rect_finite()
|
||||||
|
.height()
|
||||||
|
.at_least(self.min_row_height);
|
||||||
|
Rect::from_min_size(region.cursor, vec2(width, height))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn next_cell(&self, cursor: Pos2, child_size: Vec2) -> Rect {
|
pub(crate) fn next_cell(&self, cursor: Pos2, child_size: Vec2) -> Rect {
|
||||||
|
|
|
@ -27,6 +27,10 @@ impl Placer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn is_grid(&self) -> bool {
|
||||||
|
self.grid.is_some()
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn layout(&self) -> &Layout {
|
pub(crate) fn layout(&self) -> &Layout {
|
||||||
&self.layout
|
&self.layout
|
||||||
}
|
}
|
||||||
|
|
|
@ -1118,6 +1118,10 @@ impl Ui {
|
||||||
self.placer.save_grid();
|
self.placer.save_grid();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn is_grid(&self) -> bool {
|
||||||
|
self.placer.is_grid()
|
||||||
|
}
|
||||||
|
|
||||||
/// Move to the next row in a grid layout or wrapping layout.
|
/// Move to the next row in a grid layout or wrapping layout.
|
||||||
/// Otherwise does nothing.
|
/// Otherwise does nothing.
|
||||||
pub fn end_row(&mut self) {
|
pub fn end_row(&mut self) {
|
||||||
|
|
|
@ -45,8 +45,8 @@ impl Widget for Separator {
|
||||||
is_horizontal_line,
|
is_horizontal_line,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
let is_horizontal_line =
|
let is_horizontal_line = is_horizontal_line
|
||||||
is_horizontal_line.unwrap_or_else(|| !ui.layout().main_dir().is_horizontal());
|
.unwrap_or_else(|| ui.is_grid() || !ui.layout().main_dir().is_horizontal());
|
||||||
|
|
||||||
let available_space = ui.available_size_before_wrap_finite();
|
let available_space = ui.available_size_before_wrap_finite();
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,6 @@ impl super::Demo for WidgetGallery {
|
||||||
fn show(&mut self, ctx: &egui::CtxRef, open: &mut bool) {
|
fn show(&mut self, ctx: &egui::CtxRef, open: &mut bool) {
|
||||||
egui::Window::new(self.name())
|
egui::Window::new(self.name())
|
||||||
.open(open)
|
.open(open)
|
||||||
.default_width(200.0)
|
|
||||||
.resizable(false)
|
.resizable(false)
|
||||||
.show(ctx, |ui| {
|
.show(ctx, |ui| {
|
||||||
use super::View;
|
use super::View;
|
||||||
|
@ -131,9 +130,7 @@ impl super::View for WidgetGallery {
|
||||||
ui.end_row();
|
ui.end_row();
|
||||||
|
|
||||||
ui.label("Separator:");
|
ui.label("Separator:");
|
||||||
// Putting a separator in a grid is kind of meaningless since there is no well-defined direction.
|
ui.separator();
|
||||||
// Normally you'd just do ui.separator(), but here we need to explicitly pick a dimension:
|
|
||||||
ui.add(egui::Separator::new().horizontal());
|
|
||||||
ui.end_row();
|
ui.end_row();
|
||||||
|
|
||||||
ui.label("CollapsingHeader:");
|
ui.label("CollapsingHeader:");
|
||||||
|
|
Loading…
Reference in a new issue