Skip to content

Commit 43e7b16

Browse files
authored
eframe: Fix clicks in web (#3640)
Closes #3633 Bug introduced in #3623 (after 0.24.0 was cut)
1 parent fbccd3a commit 43e7b16

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

crates/eframe/src/web/app_runner.rs

+2-14
Original file line numberDiff line numberDiff line change
@@ -173,20 +173,8 @@ impl AppRunner {
173173
self.painter.destroy();
174174
}
175175

176-
/// Runs the user code and paints the UI.
177-
///
178-
/// If there is already an outstanding frame of output,
179-
/// that is painted instead.
180-
pub fn run_and_paint(&mut self) {
181-
if self.clipped_primitives.is_none() {
182-
// Run user code, and paint the results:
183-
self.logic();
184-
self.paint();
185-
} else {
186-
// We have already run the logic, e.g. in an on-click event,
187-
// so let's only present the results:
188-
self.paint();
189-
}
176+
pub fn has_outstanding_paint_data(&self) -> bool {
177+
self.clipped_primitives.is_some()
190178
}
191179

192180
/// Runs the logic, but doesn't paint the result.

crates/eframe/src/web/events.rs

+19-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,25 @@ fn paint_and_schedule(runner_ref: &WebRunner) -> Result<(), JsValue> {
1717

1818
fn paint_if_needed(runner: &mut AppRunner) {
1919
if runner.needs_repaint.needs_repaint() {
20-
runner.needs_repaint.clear();
21-
runner.run_and_paint();
20+
if runner.has_outstanding_paint_data() {
21+
// We have already run the logic, e.g. in an on-click event,
22+
// so let's only present the results:
23+
runner.paint();
24+
25+
// We schedule another repaint asap, so that we can run the actual logic
26+
// again, which may schedule a new repaint (if there's animations):
27+
runner.needs_repaint.repaint_asap();
28+
} else {
29+
// Clear the `needs_repaint` flags _before_
30+
// running the logic, as the logic could cause it to be set again.
31+
runner.needs_repaint.clear();
32+
33+
// Run user code…
34+
runner.logic();
35+
36+
// …and paint the result.
37+
runner.paint();
38+
}
2239
}
2340
runner.auto_save_if_needed();
2441
}

0 commit comments

Comments
 (0)