1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-01 22:30:03 -04:00

Remove Modifiers from RawInput and make it a egui::Event (#8336)

- needs #8335 

Previously it was impossible to correctly set modifiers via egui
inspection, since that only passes egui::Event and egui::Event had no
way to generally express modifiers.
Now modifiers are passed to egui as a Event and not as a field of
`RawInput`.

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
Lucas Meurer
2026-07-27 16:17:22 +02:00
committed by GitHub
parent e6eb00a31c
commit 2cb071f7f6
8 changed files with 106 additions and 69 deletions

View File

@@ -69,6 +69,9 @@ pub enum Event {
modifiers: Modifiers,
},
/// The set of held modifier keys changed.
ModifiersChanged(Modifiers),
/// The mouse or touch moved to a new place.
PointerMoved(Pos2),

View File

@@ -1,6 +1,6 @@
use crate::{OrderedViewportIdMap, Theme, ViewportId, ViewportIdMap, emath::Rect};
use super::{DroppedFile, Event, HoveredFile, Modifiers, SafeAreaInsets, ViewportInfo};
use super::{DroppedFile, Event, HoveredFile, SafeAreaInsets, ViewportInfo};
/// What the integrations provides to egui at the start of each frame.
///
@@ -53,9 +53,6 @@ pub struct RawInput {
/// Can safely be left at its default value.
pub predicted_dt: f32,
/// Which modifier keys are down at the start of the frame?
pub modifiers: Modifiers,
/// In-order events received this frame.
///
/// There is currently no way to know if egui handles a particular event,
@@ -92,7 +89,6 @@ impl Default for RawInput {
max_texture_side: None,
time: None,
predicted_dt: 1.0 / 60.0,
modifiers: Modifiers::default(),
events: vec![],
hovered_files: Default::default(),
dropped_files: Default::default(),
@@ -127,7 +123,6 @@ impl RawInput {
max_texture_side: self.max_texture_side.take(),
time: self.time,
predicted_dt: self.predicted_dt,
modifiers: self.modifiers,
events: std::mem::take(&mut self.events),
hovered_files: self.hovered_files.clone(),
dropped_files: std::mem::take(&mut self.dropped_files),
@@ -145,7 +140,6 @@ impl RawInput {
max_texture_side,
time,
predicted_dt,
modifiers,
mut events,
mut hovered_files,
mut dropped_files,
@@ -160,7 +154,6 @@ impl RawInput {
self.max_texture_side = max_texture_side.or(self.max_texture_side);
self.time = time; // use latest time
self.predicted_dt = predicted_dt; // use latest dt
self.modifiers = modifiers; // use latest
self.events.append(&mut events);
self.hovered_files.append(&mut hovered_files);
self.dropped_files.append(&mut dropped_files);
@@ -179,7 +172,6 @@ impl RawInput {
max_texture_side,
time,
predicted_dt,
modifiers,
events,
hovered_files,
dropped_files,
@@ -210,7 +202,6 @@ impl RawInput {
ui.label("time: None");
}
ui.label(format!("predicted_dt: {:.1} ms", 1e3 * predicted_dt));
ui.label(format!("modifiers: {modifiers:#?}"));
ui.label(format!("hovered_files: {}", hovered_files.len()));
ui.label(format!("dropped_files: {}", dropped_files.len()));
ui.label(format!("focused: {focused}"));

View File

@@ -393,6 +393,7 @@ impl InputState {
let pointer = self.pointer.begin_pass(time, &new, options);
let mut keys_down = self.keys_down;
let mut modifiers = self.modifiers;
let mut zoom_factor_delta = 1.0; // TODO(emilk): smoothing for zoom factor
let mut rotation_radians = 0.0;
@@ -429,6 +430,9 @@ impl InputState {
*modifiers,
);
}
Event::ModifiersChanged(new_modifiers) => {
modifiers = *new_modifiers;
}
Event::Zoom(factor) => {
zoom_factor_delta *= *factor;
}
@@ -442,6 +446,7 @@ impl InputState {
// So we take the safe route and just clear all the keys and modifiers when
// the app loses focus.
keys_down.clear();
modifiers = Modifiers::default();
}
_ => {}
}
@@ -482,7 +487,7 @@ impl InputState {
predicted_dt: new.predicted_dt,
stable_dt,
focused: new.focused,
modifiers: new.modifiers,
modifiers,
keys_down,
events: new.events.clone(), // TODO(emilk): remove clone() and use raw.events
raw: new,