Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions crates/egui/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2397,6 +2397,12 @@ impl Context {
crate::gui_zoom::zoom_with_keyboard(self);
}

for shortcut in self.options(|o| o.quit_shortcuts.clone()) {
if self.input_mut(|i| i.consume_shortcut(&shortcut)) {
self.send_viewport_cmd(ViewportCommand::Close);
}
}

#[cfg(debug_assertions)]
self.debug_painting();

Expand Down
15 changes: 15 additions & 0 deletions crates/egui/src/memory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,16 @@ pub struct Options {
#[cfg_attr(feature = "serde", serde(skip))]
pub zoom_with_keyboard: bool,

/// Keyboard shortcuts to close the application.
///
/// Pressing any of these will send [`crate::ViewportCommand::Close`]
/// to the root viewport.
///
/// Defaults to `Cmd-Q` (which is Ctrl-Q on Linux/Windows, Cmd-Q on Mac).
/// Set to empty to disable.
#[cfg_attr(feature = "serde", serde(skip))]
pub quit_shortcuts: Vec<crate::KeyboardShortcut>,

/// Controls the tessellator.
pub tessellation_options: epaint::TessellationOptions,

Expand Down Expand Up @@ -304,6 +314,10 @@ impl Default for Options {
system_theme: None,
zoom_factor: 1.0,
zoom_with_keyboard: true,
quit_shortcuts: vec![crate::KeyboardShortcut::new(
crate::Modifiers::COMMAND,
crate::Key::Q,
)],
tessellation_options: Default::default(),
repaint_on_widget_change: false,

Expand Down Expand Up @@ -363,6 +377,7 @@ impl Options {
system_theme: _,
zoom_factor,
zoom_with_keyboard,
quit_shortcuts: _, // not shown in ui
tessellation_options,
repaint_on_widget_change,
max_passes,
Expand Down
Loading