mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 14:50:03 -04:00
Quit on Ctrl-Q (#7985)
This adds `Ctrl-Q` as the default shortcut for closing the current egui `Viewport`, which also means closing the entire application if you are in the root viewport. Can be configured by `egui::Options::quit_shortcuts` On Mac, `cmd-Q` already triggers a quit, but not on all Linux:es.
This commit is contained in:
@@ -2397,6 +2397,12 @@ impl Context {
|
|||||||
crate::gui_zoom::zoom_with_keyboard(self);
|
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)]
|
#[cfg(debug_assertions)]
|
||||||
self.debug_painting();
|
self.debug_painting();
|
||||||
|
|
||||||
|
|||||||
@@ -234,6 +234,16 @@ pub struct Options {
|
|||||||
#[cfg_attr(feature = "serde", serde(skip))]
|
#[cfg_attr(feature = "serde", serde(skip))]
|
||||||
pub zoom_with_keyboard: bool,
|
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.
|
/// Controls the tessellator.
|
||||||
pub tessellation_options: epaint::TessellationOptions,
|
pub tessellation_options: epaint::TessellationOptions,
|
||||||
|
|
||||||
@@ -304,6 +314,10 @@ impl Default for Options {
|
|||||||
system_theme: None,
|
system_theme: None,
|
||||||
zoom_factor: 1.0,
|
zoom_factor: 1.0,
|
||||||
zoom_with_keyboard: true,
|
zoom_with_keyboard: true,
|
||||||
|
quit_shortcuts: vec![crate::KeyboardShortcut::new(
|
||||||
|
crate::Modifiers::COMMAND,
|
||||||
|
crate::Key::Q,
|
||||||
|
)],
|
||||||
tessellation_options: Default::default(),
|
tessellation_options: Default::default(),
|
||||||
repaint_on_widget_change: false,
|
repaint_on_widget_change: false,
|
||||||
|
|
||||||
@@ -363,6 +377,7 @@ impl Options {
|
|||||||
system_theme: _,
|
system_theme: _,
|
||||||
zoom_factor,
|
zoom_factor,
|
||||||
zoom_with_keyboard,
|
zoom_with_keyboard,
|
||||||
|
quit_shortcuts: _, // not shown in ui
|
||||||
tessellation_options,
|
tessellation_options,
|
||||||
repaint_on_widget_change,
|
repaint_on_widget_change,
|
||||||
max_passes,
|
max_passes,
|
||||||
|
|||||||
Reference in New Issue
Block a user