Skip to content

Commit 4a23eec

Browse files
authored
Merge branch 'emilk:master' into patch5
2 parents 8a0075b + 08c5a64 commit 4a23eec

File tree

4 files changed

+35
-22
lines changed

4 files changed

+35
-22
lines changed

crates/egui_kittest/Cargo.toml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@ include = ["../LICENSE-APACHE", "../LICENSE-MIT", "**/*.rs", "Cargo.toml"]
1818

1919
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
2020

21+
[package.metadata.docs.rs]
22+
all-features = true
23+
rustdoc-args = ["--generate-link-to-definition"]
24+
2125
[features]
22-
# Adds a wgpu-based test renderer.
26+
## Adds a wgpu-based test renderer.
2327
wgpu = [
2428
"dep:egui-wgpu",
2529
"dep:pollster",
@@ -28,12 +32,15 @@ wgpu = [
2832
"eframe?/wgpu",
2933
]
3034

31-
# Adds a dify-based image snapshot utility.
35+
## Adds a dify-based image snapshot utility.
3236
snapshot = ["dep:dify", "dep:image", "image/png"]
3337

34-
# Allows testing eframe::App
38+
## Allows testing eframe::App
3539
eframe = ["dep:eframe", "eframe/accesskit"]
3640

41+
# This is just so it compiles with `--all-features` on Linux
42+
x11 = ["eframe?/x11"]
43+
3744

3845
[dependencies]
3946
kittest.workspace = true
@@ -50,7 +57,7 @@ wgpu = { workspace = true, features = ["metal", "dx12"], optional = true }
5057
# snapshot dependencies
5158
dify = { workspace = true, optional = true }
5259

53-
## Enable this when generating docs.
60+
# Enable this when generating docs.
5461
document-features = { workspace = true, optional = true }
5562

5663
[dev-dependencies]

crates/egui_kittest/src/event.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@ pub(crate) struct EventState {
88
}
99

1010
impl EventState {
11-
/// Map the kittest events to egui events, add them to the input and update the modifiers.
11+
/// Map the kittest event to an egui event, add it to the input and update the modifiers.
1212
/// This function accesses `egui::RawInput::modifiers`. Make sure it is not reset after each
1313
/// frame (Since we use [`egui::RawInput::take`], this should be fine).
14-
pub fn update(&mut self, events: Vec<kittest::Event>, input: &mut egui::RawInput) {
15-
for event in events {
16-
if let Some(event) = self.kittest_event_to_egui(&mut input.modifiers, event) {
17-
input.events.push(event);
18-
}
14+
pub fn update(&mut self, event: kittest::Event, input: &mut egui::RawInput) {
15+
if let Some(event) = self.kittest_event_to_egui(&mut input.modifiers, event) {
16+
input.events.push(event);
1917
}
2018
}
2119

crates/egui_kittest/src/lib.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,17 +219,22 @@ impl<'a, State> Harness<'a, State> {
219219
self
220220
}
221221

222-
/// Run a frame.
223-
/// This will call the app closure with the queued events and current context and
222+
/// Run a frame for each queued event (or a single frame if there are no events).
223+
/// This will call the app closure with each queued event and
224224
/// update the Harness.
225225
pub fn step(&mut self) {
226-
self._step(false);
226+
let events = self.kittest.take_events();
227+
if events.is_empty() {
228+
self._step(false);
229+
}
230+
for event in events {
231+
self.event_state.update(event, &mut self.input);
232+
self._step(false);
233+
}
227234
}
228235

236+
/// Run a single step. This will not process any events.
229237
fn _step(&mut self, sizing_pass: bool) {
230-
self.event_state
231-
.update(self.kittest.take_events(), &mut self.input);
232-
233238
self.input.predicted_dt = self.step_dt;
234239

235240
let mut output = self.ctx.run(self.input.take(), |ctx| {

crates/egui_kittest/tests/tests.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ fn test_modifiers() {
2222
struct State {
2323
cmd_clicked: bool,
2424
cmd_z_pressed: bool,
25+
cmd_y_pressed: bool,
2526
}
2627
let mut harness = Harness::new_ui_state(
2728
|ui, state| {
@@ -31,6 +32,9 @@ fn test_modifiers() {
3132
if ui.input(|i| i.modifiers.command && i.key_pressed(egui::Key::Z)) {
3233
state.cmd_z_pressed = true;
3334
}
35+
if ui.input(|i| i.modifiers.command && i.key_pressed(egui::Key::Y)) {
36+
state.cmd_y_pressed = true;
37+
}
3438
},
3539
State::default(),
3640
);
@@ -39,18 +43,17 @@ fn test_modifiers() {
3943
// This run isn't necessary, but allows us to test whether modifiers are remembered between frames
4044
harness.run();
4145
harness.get_by_label("Click me").click();
42-
// TODO(lucasmerlin): Right now the key_up needs to happen on a separate frame or it won't register.
43-
// This should be more intuitive
44-
harness.run();
4546
harness.get_by_label("Click me").key_up(Key::Command);
46-
4747
harness.run();
4848

4949
harness.press_key_modifiers(Modifiers::COMMAND, egui::Key::Z);
50-
// TODO(lucasmerlin): This should also work (Same problem as above)
51-
// harness.node().key_combination(&[Key::Command, Key::Z]);
50+
harness.run();
51+
52+
harness.node().key_combination(&[Key::Command, Key::Y]);
53+
harness.run();
5254

5355
let state = harness.state();
5456
assert!(state.cmd_clicked, "The button wasn't command-clicked");
5557
assert!(state.cmd_z_pressed, "Cmd+Z wasn't pressed");
58+
assert!(state.cmd_y_pressed, "Cmd+Y wasn't pressed");
5659
}

0 commit comments

Comments
 (0)