Skip to content

Commit

Permalink
eframe: Fix clicks in web (#3640)
Browse files Browse the repository at this point in the history
Closes #3633

Bug introduced in #3623 (after 0.24.0 was cut)
  • Loading branch information
emilk committed Nov 27, 2023
1 parent fbccd3a commit 43e7b16
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
16 changes: 2 additions & 14 deletions crates/eframe/src/web/app_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,20 +173,8 @@ impl AppRunner {
self.painter.destroy();
}

/// Runs the user code and paints the UI.
///
/// If there is already an outstanding frame of output,
/// that is painted instead.
pub fn run_and_paint(&mut self) {
if self.clipped_primitives.is_none() {
// Run user code, and paint the results:
self.logic();
self.paint();
} else {
// We have already run the logic, e.g. in an on-click event,
// so let's only present the results:
self.paint();
}
pub fn has_outstanding_paint_data(&self) -> bool {
self.clipped_primitives.is_some()
}

/// Runs the logic, but doesn't paint the result.
Expand Down
21 changes: 19 additions & 2 deletions crates/eframe/src/web/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,25 @@ fn paint_and_schedule(runner_ref: &WebRunner) -> Result<(), JsValue> {

fn paint_if_needed(runner: &mut AppRunner) {
if runner.needs_repaint.needs_repaint() {
runner.needs_repaint.clear();
runner.run_and_paint();
if runner.has_outstanding_paint_data() {
// We have already run the logic, e.g. in an on-click event,
// so let's only present the results:
runner.paint();

// We schedule another repaint asap, so that we can run the actual logic
// again, which may schedule a new repaint (if there's animations):
runner.needs_repaint.repaint_asap();
} else {
// Clear the `needs_repaint` flags _before_
// running the logic, as the logic could cause it to be set again.
runner.needs_repaint.clear();

// Run user code…
runner.logic();

// …and paint the result.
runner.paint();
}
}
runner.auto_save_if_needed();
}
Expand Down

0 comments on commit 43e7b16

Please sign in to comment.