mirror of
https://github.com/emilk/egui.git
synced 2026-08-29 12:50:04 -04:00
eframe: Added App::raw_input_hook allows for the manipulation or filtering of raw input events (#4008)
# What's New * eframe: Added `App::raw_input_hook` allows for the manipulation or filtering of raw input events A filter applied to raw input before [`Self::update`] This allows for the manipulation or filtering of input events before they are processed by egui. This can be used to exclude specific keyboard shortcuts, mouse events, etc. Additionally, it can be used to add custom keyboard or mouse events generated by a virtual keyboard. * examples: Added an example to demonstrates how to implement a custom virtual keyboard. [eframe-custom-keypad.webm](https://github.com/emilk/egui/assets/1274171/a9dc8e34-2c35-4172-b7ef-41010b794fb8)
This commit is contained in:
@@ -196,6 +196,24 @@ pub trait App {
|
||||
fn persist_egui_memory(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
/// A hook for manipulating or filtering raw input before it is processed by [`Self::update`].
|
||||
///
|
||||
/// This function provides a way to modify or filter input events before they are processed by egui.
|
||||
///
|
||||
/// It can be used to prevent specific keyboard shortcuts or mouse events from being processed by egui.
|
||||
///
|
||||
/// Additionally, it can be used to inject custom keyboard or mouse events into the input stream, which can be useful for implementing features like a virtual keyboard.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `_ctx` - The context of the egui, which provides access to the current state of the egui.
|
||||
/// * `_raw_input` - The raw input events that are about to be processed. This can be modified to change the input that egui processes.
|
||||
///
|
||||
/// # Note
|
||||
///
|
||||
/// This function does not return a value. Any changes to the input should be made directly to `_raw_input`.
|
||||
fn raw_input_hook(&mut self, _ctx: &egui::Context, _raw_input: &mut egui::RawInput) {}
|
||||
}
|
||||
|
||||
/// Selects the level of hardware graphics acceleration.
|
||||
|
||||
@@ -274,6 +274,8 @@ impl EpiIntegration {
|
||||
|
||||
let close_requested = raw_input.viewport().close_requested();
|
||||
|
||||
app.raw_input_hook(&self.egui_ctx, &mut raw_input);
|
||||
|
||||
let full_output = self.egui_ctx.run(raw_input, |egui_ctx| {
|
||||
if let Some(viewport_ui_cb) = viewport_ui_cb {
|
||||
// Child viewport
|
||||
|
||||
Reference in New Issue
Block a user