1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-01 06:10:06 -04:00

egui_extras: add cell_layout option to set the layout of all cells

This commit is contained in:
Emil Ernerfeldt
2022-04-11 10:29:34 +02:00
parent 0e0eedfdda
commit 426b933d2f
4 changed files with 60 additions and 30 deletions

View File

@@ -45,14 +45,17 @@ pub struct StripBuilder<'a> {
ui: &'a mut Ui,
sizing: Sizing,
clip: bool,
cell_layout: egui::Layout,
}
impl<'a> StripBuilder<'a> {
/// Create new strip builder.
pub fn new(ui: &'a mut Ui) -> Self {
let cell_layout = *ui.layout();
Self {
ui,
sizing: Default::default(),
cell_layout,
clip: true,
}
}
@@ -63,6 +66,12 @@ impl<'a> StripBuilder<'a> {
self
}
/// What layout should we use for the individual cells?
pub fn cell_layout(mut self, cell_layout: egui::Layout) -> Self {
self.cell_layout = cell_layout;
self
}
/// Allocate space for for one column/row.
pub fn size(mut self, size: Size) -> Self {
self.sizing.add(size);
@@ -89,7 +98,12 @@ impl<'a> StripBuilder<'a> {
self.ui.available_rect_before_wrap().width(),
self.ui.spacing().item_spacing.x,
);
let mut layout = StripLayout::new(self.ui, CellDirection::Horizontal, self.clip);
let mut layout = StripLayout::new(
self.ui,
CellDirection::Horizontal,
self.clip,
self.cell_layout,
);
strip(Strip {
layout: &mut layout,
direction: CellDirection::Horizontal,
@@ -110,7 +124,12 @@ impl<'a> StripBuilder<'a> {
self.ui.available_rect_before_wrap().height(),
self.ui.spacing().item_spacing.y,
);
let mut layout = StripLayout::new(self.ui, CellDirection::Vertical, self.clip);
let mut layout = StripLayout::new(
self.ui,
CellDirection::Vertical,
self.clip,
self.cell_layout,
);
strip(Strip {
layout: &mut layout,
direction: CellDirection::Vertical,