From 502931075ad67e08fd990dde0dfa55c0346db7a0 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Mon, 5 Feb 2024 11:32:37 +0100 Subject: [PATCH] Add Spacing::menu_width --- crates/egui/src/menu.rs | 3 +-- crates/egui/src/style.rs | 10 ++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/crates/egui/src/menu.rs b/crates/egui/src/menu.rs index f79942cd367..846b5738305 100644 --- a/crates/egui/src/menu.rs +++ b/crates/egui/src/menu.rs @@ -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 diff --git a/crates/egui/src/style.rs b/crates/egui/src/style.rs index 0cf9c5f6243..70e65261df6 100644 --- a/crates/egui/src/style.rs +++ b/crates/egui/src/style.rs @@ -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, @@ -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, @@ -1458,6 +1462,7 @@ impl Spacing { icon_width_inner, icon_spacing, tooltip_width, + menu_width, indent_ends_with_horizontal_line, combo_height, scroll, @@ -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",