Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide shortcut text on zoom buttons if zoom_with_keyboard is false #4262

Merged
merged 1 commit into from
Mar 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading