Skip to content

Commit

Permalink
Add spacing.menu_margin for customizing menu spacing (#2036)
Browse files Browse the repository at this point in the history
- Fixes #287
  • Loading branch information
chamons authored Sep 17, 2022
1 parent bc6a823 commit 311eb66
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion crates/egui/src/containers/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
36 changes: 35 additions & 1 deletion crates/egui/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -923,6 +927,7 @@ impl Spacing {
let Self {
item_spacing,
window_margin,
menu_margin,
button_padding,
indent,
interact_size,
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 311eb66

Please sign in to comment.