1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-02 06:40:06 -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

@@ -251,14 +251,7 @@ impl<'a, State> Harness<'a, State> {
self._step(false);
}
for event in events {
match event {
EventType::Event(event) => {
self.input.events.push(event);
}
EventType::Modifiers(modifiers) => {
self.input.modifiers = modifiers;
}
}
self.input.events.push(event);
self._step(false);
}
}
@@ -471,7 +464,7 @@ impl<'a, State> Harness<'a, State> {
/// Queue an event to be processed in the next frame.
pub fn event(&self, event: egui::Event) {
self.queued_events.lock().push(EventType::Event(event));
self.queued_events.lock().push(event);
}
/// Queue an event with modifiers.
@@ -479,15 +472,15 @@ impl<'a, State> Harness<'a, State> {
/// Queues the modifiers to be pressed, then the event, then the modifiers to be released.
pub fn event_modifiers(&self, event: egui::Event, modifiers: Modifiers) {
let mut queue = self.queued_events.lock();
queue.push(EventType::Modifiers(modifiers));
queue.push(EventType::Event(event));
queue.push(EventType::Modifiers(Modifiers::default()));
queue.push(egui::Event::ModifiersChanged(modifiers));
queue.push(event);
queue.push(egui::Event::ModifiersChanged(Modifiers::default()));
}
fn modifiers(&self, modifiers: Modifiers) {
self.queued_events
.lock()
.push(EventType::Modifiers(modifiers));
.push(egui::Event::ModifiersChanged(modifiers));
}
pub fn key_down(&self, key: egui::Key) {
@@ -735,10 +728,11 @@ impl<'a, State> Harness<'a, State> {
/// The root node of the test harness.
pub fn root(&self) -> Node<'_> {
Node {
accesskit_node: self.kittest.root(),
queue: &self.queued_events,
}
Node::new(
self.kittest.root(),
&self.queued_events,
self.ctx.pixels_per_point(),
)
}
/// Spawn a real native eframe window running this harness's app, reusing its [`egui::Context`].

View File

@@ -4,17 +4,13 @@ use egui::{Modifiers, PointerButton, Pos2, accesskit};
use kittest::{AccessKitNode, NodeT, debug_fmt_node};
use std::fmt::{Debug, Formatter};
pub(crate) enum EventType {
Event(egui::Event),
Modifiers(Modifiers),
}
pub(crate) type EventQueue = Mutex<Vec<EventType>>;
pub type EventQueue = Mutex<Vec<egui::Event>>;
#[derive(Clone, Copy)]
pub struct Node<'tree> {
pub(crate) accesskit_node: AccessKitNode<'tree>,
pub(crate) queue: &'tree EventQueue,
pub(crate) pixels_per_point: f32,
}
impl Debug for Node<'_> {
@@ -29,20 +25,32 @@ impl<'tree> NodeT<'tree> for Node<'tree> {
}
fn new_related(&self, child_node: AccessKitNode<'tree>) -> Self {
Self {
queue: self.queue,
accesskit_node: child_node,
}
Self::new(child_node, self.queue, self.pixels_per_point)
}
}
impl Node<'_> {
impl<'tree> Node<'tree> {
/// Construct a new accesskit node
pub fn new(
accesskit_node: AccessKitNode<'tree>,
queue: &'tree EventQueue,
pixels_per_point: f32,
) -> Self {
Self {
accesskit_node,
queue,
pixels_per_point,
}
}
fn event(&self, event: egui::Event) {
self.queue.lock().push(EventType::Event(event));
self.queue.lock().push(event);
}
fn modifiers(&self, modifiers: Modifiers) {
self.queue.lock().push(EventType::Modifiers(modifiers));
self.queue
.lock()
.push(egui::Event::ModifiersChanged(modifiers));
}
pub fn hover(&self) {
@@ -104,14 +112,17 @@ impl Node<'_> {
));
}
/// This returns the rect in logical ui coordinates while the underlying [`accesskit::Node`] has it
/// in physical screen coordinates.
pub fn rect(&self) -> egui::Rect {
let rect = self
.accesskit_node
.bounding_box()
.expect("Every egui node should have a rect");
let ppp = self.pixels_per_point;
egui::Rect {
min: Pos2::new(rect.x0 as f32, rect.y0 as f32),
max: Pos2::new(rect.x1 as f32, rect.y1 as f32),
min: Pos2::new(rect.x0 as f32 / ppp, rect.y0 as f32 / ppp),
max: Pos2::new(rect.x1 as f32 / ppp, rect.y1 as f32 / ppp),
}
}