mirror of
https://github.com/emilk/egui.git
synced 2026-08-29 21:00:03 -04:00
Add Context::request_repaint_after (#1694)
This commit is contained in:
@@ -251,10 +251,10 @@ impl AppRunner {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Returns `true` if egui requests a repaint.
|
||||
/// Returns how long to wait until the next repaint.
|
||||
///
|
||||
/// Call [`Self::paint`] later to paint
|
||||
pub fn logic(&mut self) -> Result<(bool, Vec<egui::ClippedPrimitive>), JsValue> {
|
||||
pub fn logic(&mut self) -> Result<(std::time::Duration, Vec<egui::ClippedPrimitive>), JsValue> {
|
||||
let frame_start = now_sec();
|
||||
|
||||
resize_canvas_to_screen_size(self.canvas_id(), self.app.max_size_points());
|
||||
@@ -266,7 +266,7 @@ impl AppRunner {
|
||||
});
|
||||
let egui::FullOutput {
|
||||
platform_output,
|
||||
needs_repaint,
|
||||
repaint_after,
|
||||
textures_delta,
|
||||
shapes,
|
||||
} = full_output;
|
||||
@@ -288,7 +288,7 @@ impl AppRunner {
|
||||
}
|
||||
|
||||
self.frame.info.cpu_usage = Some((now_sec() - frame_start) as f32);
|
||||
Ok((needs_repaint, clipped_primitives))
|
||||
Ok((repaint_after, clipped_primitives))
|
||||
}
|
||||
|
||||
pub fn clear_color_buffer(&self) {
|
||||
|
||||
@@ -9,11 +9,12 @@ pub fn paint_and_schedule(
|
||||
let mut runner_lock = runner_ref.lock();
|
||||
if runner_lock.needs_repaint.fetch_and_clear() {
|
||||
runner_lock.clear_color_buffer();
|
||||
let (needs_repaint, clipped_primitives) = runner_lock.logic()?;
|
||||
let (repaint_after, clipped_primitives) = runner_lock.logic()?;
|
||||
runner_lock.paint(&clipped_primitives)?;
|
||||
if needs_repaint {
|
||||
if repaint_after.is_zero() {
|
||||
runner_lock.needs_repaint.set_true();
|
||||
}
|
||||
// TODO: schedule a repaint after `repaint_after` when it is not zero
|
||||
runner_lock.auto_save();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user