Skip to content

Commit 36d6213

Browse files
emilkhacknus
authored andcommitted
Hide shortcut text on zoom buttons if zoom_with_keyboard is false (emilk#4262)
1 parent d1eb0b7 commit 36d6213

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

crates/egui/src/gui_zoom.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,20 @@ pub fn zoom_out(ctx: &Context) {
7070
///
7171
/// This is meant to be called from within a menu (See [`Ui::menu_button`]).
7272
pub fn zoom_menu_buttons(ui: &mut Ui) {
73+
fn button(ctx: &Context, text: &str, shortcut: &KeyboardShortcut) -> Button<'static> {
74+
let btn = Button::new(text);
75+
let zoom_with_keyboard = ctx.options(|o| o.zoom_with_keyboard);
76+
if zoom_with_keyboard {
77+
btn.shortcut_text(ctx.format_shortcut(shortcut))
78+
} else {
79+
btn
80+
}
81+
}
82+
7383
if ui
7484
.add_enabled(
7585
ui.ctx().zoom_factor() < MAX_ZOOM_FACTOR,
76-
Button::new("Zoom In").shortcut_text(ui.ctx().format_shortcut(&kb_shortcuts::ZOOM_IN)),
86+
button(ui.ctx(), "Zoom In", &kb_shortcuts::ZOOM_IN),
7787
)
7888
.clicked()
7989
{
@@ -84,8 +94,7 @@ pub fn zoom_menu_buttons(ui: &mut Ui) {
8494
if ui
8595
.add_enabled(
8696
ui.ctx().zoom_factor() > MIN_ZOOM_FACTOR,
87-
Button::new("Zoom Out")
88-
.shortcut_text(ui.ctx().format_shortcut(&kb_shortcuts::ZOOM_OUT)),
97+
button(ui.ctx(), "Zoom Out", &kb_shortcuts::ZOOM_OUT),
8998
)
9099
.clicked()
91100
{
@@ -96,8 +105,7 @@ pub fn zoom_menu_buttons(ui: &mut Ui) {
96105
if ui
97106
.add_enabled(
98107
ui.ctx().zoom_factor() != 1.0,
99-
Button::new("Reset Zoom")
100-
.shortcut_text(ui.ctx().format_shortcut(&kb_shortcuts::ZOOM_RESET)),
108+
button(ui.ctx(), "Reset Zoom", &kb_shortcuts::ZOOM_RESET),
101109
)
102110
.clicked()
103111
{

0 commit comments

Comments
 (0)