Skip to content

Commit

Permalink
Hide shortcut text on zoom buttons if zoom_with_keyboard is false (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk authored Mar 29, 2024
1 parent 7cc98bd commit 946bc88
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions crates/egui/src/gui_zoom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,20 @@ pub fn zoom_out(ctx: &Context) {
///
/// This is meant to be called from within a menu (See [`Ui::menu_button`]).
pub fn zoom_menu_buttons(ui: &mut Ui) {
fn button(ctx: &Context, text: &str, shortcut: &KeyboardShortcut) -> Button<'static> {
let btn = Button::new(text);
let zoom_with_keyboard = ctx.options(|o| o.zoom_with_keyboard);
if zoom_with_keyboard {
btn.shortcut_text(ctx.format_shortcut(shortcut))
} else {
btn
}
}

if ui
.add_enabled(
ui.ctx().zoom_factor() < MAX_ZOOM_FACTOR,
Button::new("Zoom In").shortcut_text(ui.ctx().format_shortcut(&kb_shortcuts::ZOOM_IN)),
button(ui.ctx(), "Zoom In", &kb_shortcuts::ZOOM_IN),
)
.clicked()
{
Expand All @@ -84,8 +94,7 @@ pub fn zoom_menu_buttons(ui: &mut Ui) {
if ui
.add_enabled(
ui.ctx().zoom_factor() > MIN_ZOOM_FACTOR,
Button::new("Zoom Out")
.shortcut_text(ui.ctx().format_shortcut(&kb_shortcuts::ZOOM_OUT)),
button(ui.ctx(), "Zoom Out", &kb_shortcuts::ZOOM_OUT),
)
.clicked()
{
Expand All @@ -96,8 +105,7 @@ pub fn zoom_menu_buttons(ui: &mut Ui) {
if ui
.add_enabled(
ui.ctx().zoom_factor() != 1.0,
Button::new("Reset Zoom")
.shortcut_text(ui.ctx().format_shortcut(&kb_shortcuts::ZOOM_RESET)),
button(ui.ctx(), "Reset Zoom", &kb_shortcuts::ZOOM_RESET),
)
.clicked()
{
Expand Down

0 comments on commit 946bc88

Please sign in to comment.