Skip to content

Commit

Permalink
Add Spacing::menu_width (#3973)
Browse files Browse the repository at this point in the history
Let users pick default menu width
  • Loading branch information
emilk authored Feb 5, 2024
1 parent 7a6d80c commit a5f3881
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 1 addition & 2 deletions crates/egui/src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ pub(crate) fn menu_ui<'c, R>(
set_menu_style(ui.style_mut());

let frame = Frame::menu(ui.style()).show(ui, |ui| {
const DEFAULT_MENU_WIDTH: f32 = 150.0; // TODO(emilk): add to ui.spacing
ui.set_max_width(DEFAULT_MENU_WIDTH);
ui.set_max_width(ui.spacing().menu_width);
ui.set_menu_state(Some(menu_state_arc.clone()));
ui.with_layout(Layout::top_down_justified(Align::LEFT), add_contents)
.inner
Expand Down
10 changes: 10 additions & 0 deletions crates/egui/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ pub struct Spacing {
/// Width of a tooltip (`on_hover_ui`, `on_hover_text` etc).
pub tooltip_width: f32,

/// The default width of a menu.
pub menu_width: f32,

/// End indented regions with a horizontal line
pub indent_ends_with_horizontal_line: bool,

Expand Down Expand Up @@ -1111,6 +1114,7 @@ impl Default for Spacing {
icon_width_inner: 8.0,
icon_spacing: 4.0,
tooltip_width: 600.0,
menu_width: 150.0,
combo_height: 200.0,
scroll: Default::default(),
indent_ends_with_horizontal_line: false,
Expand Down Expand Up @@ -1458,6 +1462,7 @@ impl Spacing {
icon_width_inner,
icon_spacing,
tooltip_width,
menu_width,
indent_ends_with_horizontal_line,
combo_height,
scroll,
Expand Down Expand Up @@ -1516,6 +1521,11 @@ impl Spacing {
ui.label("Tooltip wrap width");
});

ui.horizontal(|ui| {
ui.add(DragValue::new(menu_width).clamp_range(0.0..=1000.0));
ui.label("Default width of a menu");
});

ui.checkbox(
indent_ends_with_horizontal_line,
"End indented regions with a horizontal separator",
Expand Down

0 comments on commit a5f3881

Please sign in to comment.