Add spacing.menu_margin
for customizing menu spacing (#2036)
- Fixes https://github.com/emilk/egui/discussions/287
This commit is contained in:
parent
bc6a823103
commit
311eb66cae
2 changed files with 36 additions and 2 deletions
|
@ -75,7 +75,7 @@ impl Frame {
|
|||
|
||||
pub fn menu(style: &Style) -> Self {
|
||||
Self {
|
||||
inner_margin: Margin::same(1.0),
|
||||
inner_margin: style.spacing.menu_margin,
|
||||
rounding: style.visuals.widgets.noninteractive.rounding,
|
||||
shadow: style.visuals.popup_shadow,
|
||||
fill: style.visuals.window_fill(),
|
||||
|
|
|
@ -252,6 +252,9 @@ pub struct Spacing {
|
|||
/// Button size is text size plus this on each side
|
||||
pub button_padding: Vec2,
|
||||
|
||||
/// Horizontal and vertical margins within a menu frame.
|
||||
pub menu_margin: Margin,
|
||||
|
||||
/// Indent collapsing regions etc by this much.
|
||||
pub indent: f32,
|
||||
|
||||
|
@ -642,6 +645,7 @@ impl Default for Spacing {
|
|||
Self {
|
||||
item_spacing: vec2(8.0, 3.0),
|
||||
window_margin: Margin::same(6.0),
|
||||
menu_margin: Margin::same(1.0),
|
||||
button_padding: vec2(4.0, 1.0),
|
||||
indent: 18.0, // match checkbox/radio-button with `button_padding.x + icon_width + icon_spacing`
|
||||
interact_size: vec2(40.0, 18.0),
|
||||
|
@ -923,6 +927,7 @@ impl Spacing {
|
|||
let Self {
|
||||
item_spacing,
|
||||
window_margin,
|
||||
menu_margin,
|
||||
button_padding,
|
||||
indent,
|
||||
interact_size,
|
||||
|
@ -963,12 +968,41 @@ impl Spacing {
|
|||
);
|
||||
ui.add(
|
||||
DragValue::new(&mut window_margin.bottom)
|
||||
.clamp_range(margin_range)
|
||||
.clamp_range(margin_range.clone())
|
||||
.prefix("bottom: "),
|
||||
);
|
||||
ui.label("Window margins y");
|
||||
});
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
ui.add(
|
||||
DragValue::new(&mut menu_margin.left)
|
||||
.clamp_range(margin_range.clone())
|
||||
.prefix("left: "),
|
||||
);
|
||||
ui.add(
|
||||
DragValue::new(&mut menu_margin.right)
|
||||
.clamp_range(margin_range.clone())
|
||||
.prefix("right: "),
|
||||
);
|
||||
|
||||
ui.label("Menu margins x");
|
||||
});
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
ui.add(
|
||||
DragValue::new(&mut menu_margin.top)
|
||||
.clamp_range(margin_range.clone())
|
||||
.prefix("top: "),
|
||||
);
|
||||
ui.add(
|
||||
DragValue::new(&mut menu_margin.bottom)
|
||||
.clamp_range(margin_range)
|
||||
.prefix("bottom: "),
|
||||
);
|
||||
ui.label("Menu margins y");
|
||||
});
|
||||
|
||||
ui.add(slider_vec2(button_padding, 0.0..=20.0, "Button padding"));
|
||||
ui.add(slider_vec2(interact_size, 4.0..=60.0, "Interact size"))
|
||||
.on_hover_text("Minimum size of an interactive widget");
|
||||
|
|
Loading…
Reference in a new issue