[grid] Option to set spacing
This commit is contained in:
parent
480c6db37f
commit
b1157ee642
2 changed files with 16 additions and 2 deletions
|
@ -174,6 +174,7 @@ pub struct Grid {
|
||||||
id_source: Id,
|
id_source: Id,
|
||||||
striped: bool,
|
striped: bool,
|
||||||
min_row_height: Option<f32>,
|
min_row_height: Option<f32>,
|
||||||
|
spacing: Option<Vec2>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Grid {
|
impl Grid {
|
||||||
|
@ -182,6 +183,7 @@ impl Grid {
|
||||||
id_source: Id::new(id_source),
|
id_source: Id::new(id_source),
|
||||||
striped: false,
|
striped: false,
|
||||||
min_row_height: None,
|
min_row_height: None,
|
||||||
|
spacing: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,6 +201,13 @@ impl Grid {
|
||||||
self.min_row_height = Some(min_row_height);
|
self.min_row_height = Some(min_row_height);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set spacing between columns/rows.
|
||||||
|
/// Default: [`Spacing::item_spacing`].
|
||||||
|
pub fn spacing(mut self, spacing: impl Into<Vec2>) -> Self {
|
||||||
|
self.spacing = Some(spacing.into());
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Grid {
|
impl Grid {
|
||||||
|
@ -207,8 +216,10 @@ impl Grid {
|
||||||
id_source,
|
id_source,
|
||||||
striped,
|
striped,
|
||||||
min_row_height,
|
min_row_height,
|
||||||
|
spacing,
|
||||||
} = self;
|
} = self;
|
||||||
let min_row_height = min_row_height.unwrap_or_else(|| ui.style().spacing.interact_size.y);
|
let min_row_height = min_row_height.unwrap_or_else(|| ui.style().spacing.interact_size.y);
|
||||||
|
let spacing = spacing.unwrap_or_else(|| ui.style().spacing.item_spacing);
|
||||||
|
|
||||||
// Each grid cell is aligned LEFT_CENTER.
|
// Each grid cell is aligned LEFT_CENTER.
|
||||||
// If somebody wants to wrap more things inside a cell,
|
// If somebody wants to wrap more things inside a cell,
|
||||||
|
@ -219,6 +230,7 @@ impl Grid {
|
||||||
let grid = GridLayout {
|
let grid = GridLayout {
|
||||||
striped,
|
striped,
|
||||||
min_row_height,
|
min_row_height,
|
||||||
|
spacing,
|
||||||
..GridLayout::new(ui, id)
|
..GridLayout::new(ui, id)
|
||||||
};
|
};
|
||||||
ui.set_grid(grid);
|
ui.set_grid(grid);
|
||||||
|
|
|
@ -54,7 +54,9 @@ impl super::View for WidgetGallery {
|
||||||
color,
|
color,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
let grid = egui::Grid::new("my_grid").striped(true);
|
let grid = egui::Grid::new("my_grid")
|
||||||
|
.striped(true)
|
||||||
|
.spacing([40.0, 4.0]);
|
||||||
grid.show(ui, |ui| {
|
grid.show(ui, |ui| {
|
||||||
ui.label("Label:");
|
ui.label("Label:");
|
||||||
ui.label("Welcome to the widget gallery!");
|
ui.label("Welcome to the widget gallery!");
|
||||||
|
@ -138,7 +140,7 @@ impl super::View for WidgetGallery {
|
||||||
ui.collapsing("Click to see what is hidden!", |ui| {
|
ui.collapsing("Click to see what is hidden!", |ui| {
|
||||||
ui.horizontal_wrapped_for_text(egui::TextStyle::Body, |ui| {
|
ui.horizontal_wrapped_for_text(egui::TextStyle::Body, |ui| {
|
||||||
ui.label(
|
ui.label(
|
||||||
"Not much, as it turns out, but here is a gold star for you for checking:",
|
"Not much, as it turns out - but here is a gold star for you for checking:",
|
||||||
);
|
);
|
||||||
ui.colored_label(egui::Color32::GOLD, "☆");
|
ui.colored_label(egui::Color32::GOLD, "☆");
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue