mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 22:30:03 -04:00
Fix modifiers not working in kittest (#5693)
* Closes <https://github.com/emilk/egui/issues/5690>
* [x] I have followed the instructions in the PR template
It still isn't ideal, since you have to remember to call key_up on a
separate frame.
---------
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
(cherry picked from commit 1c6e7b1bd0)
This commit is contained in:
committed by
Lucas Meurer
parent
5c372a7b36
commit
45df656d0e
@@ -1,4 +1,6 @@
|
||||
use egui_kittest::{Harness, SnapshotResults};
|
||||
use egui::Modifiers;
|
||||
use egui_kittest::Harness;
|
||||
use kittest::{Key, Queryable};
|
||||
|
||||
#[test]
|
||||
fn test_shrink() {
|
||||
@@ -10,8 +12,45 @@ fn test_shrink() {
|
||||
|
||||
harness.fit_contents();
|
||||
|
||||
let mut results = SnapshotResults::new();
|
||||
|
||||
#[cfg(all(feature = "snapshot", feature = "wgpu"))]
|
||||
results.add(harness.try_snapshot("test_shrink"));
|
||||
harness.snapshot("test_shrink");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_modifiers() {
|
||||
#[derive(Default)]
|
||||
struct State {
|
||||
cmd_clicked: bool,
|
||||
cmd_z_pressed: bool,
|
||||
}
|
||||
let mut harness = Harness::new_ui_state(
|
||||
|ui, state| {
|
||||
if ui.button("Click me").clicked() && ui.input(|i| i.modifiers.command) {
|
||||
state.cmd_clicked = true;
|
||||
}
|
||||
if ui.input(|i| i.modifiers.command && i.key_pressed(egui::Key::Z)) {
|
||||
state.cmd_z_pressed = true;
|
||||
}
|
||||
},
|
||||
State::default(),
|
||||
);
|
||||
|
||||
harness.get_by_label("Click me").key_down(Key::Command);
|
||||
// This run isn't necessary, but allows us to test whether modifiers are remembered between frames
|
||||
harness.run();
|
||||
harness.get_by_label("Click me").click();
|
||||
// TODO(lucasmerlin): Right now the key_up needs to happen on a separate frame or it won't register.
|
||||
// This should be more intuitive
|
||||
harness.run();
|
||||
harness.get_by_label("Click me").key_up(Key::Command);
|
||||
|
||||
harness.run();
|
||||
|
||||
harness.press_key_modifiers(Modifiers::COMMAND, egui::Key::Z);
|
||||
// TODO(lucasmerlin): This should also work (Same problem as above)
|
||||
// harness.node().key_combination(&[Key::Command, Key::Z]);
|
||||
|
||||
let state = harness.state();
|
||||
assert!(state.cmd_clicked, "The button wasn't command-clicked");
|
||||
assert!(state.cmd_z_pressed, "Cmd+Z wasn't pressed");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user