mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 06:40:06 -04:00
Add Context::request_repaint_after (#1694)
This commit is contained in:
@@ -16,7 +16,7 @@ fn main() {
|
||||
let mut redraw = || {
|
||||
let mut quit = false;
|
||||
|
||||
let needs_repaint = egui_glow.run(gl_window.window(), |egui_ctx| {
|
||||
let repaint_after = egui_glow.run(gl_window.window(), |egui_ctx| {
|
||||
egui::SidePanel::left("my_side_panel").show(egui_ctx, |ui| {
|
||||
ui.heading("Hello World!");
|
||||
if ui.button("Quit").clicked() {
|
||||
@@ -28,9 +28,13 @@ fn main() {
|
||||
|
||||
*control_flow = if quit {
|
||||
glutin::event_loop::ControlFlow::Exit
|
||||
} else if needs_repaint {
|
||||
} else if repaint_after.is_zero() {
|
||||
gl_window.window().request_redraw();
|
||||
glutin::event_loop::ControlFlow::Poll
|
||||
} else if let Some(repaint_after_instant) =
|
||||
std::time::Instant::now().checked_add(repaint_after)
|
||||
{
|
||||
glutin::event_loop::ControlFlow::WaitUntil(repaint_after_instant)
|
||||
} else {
|
||||
glutin::event_loop::ControlFlow::Wait
|
||||
};
|
||||
@@ -82,6 +86,11 @@ fn main() {
|
||||
glutin::event::Event::LoopDestroyed => {
|
||||
egui_glow.destroy();
|
||||
}
|
||||
glutin::event::Event::NewEvents(glutin::event::StartCause::ResumeTimeReached {
|
||||
..
|
||||
}) => {
|
||||
gl_window.window().request_redraw();
|
||||
}
|
||||
|
||||
_ => (),
|
||||
}
|
||||
|
||||
@@ -41,18 +41,18 @@ impl EguiGlow {
|
||||
self.egui_winit.on_event(&self.egui_ctx, event)
|
||||
}
|
||||
|
||||
/// Returns `true` if egui requests a repaint.
|
||||
/// Returns the `Duration` of the timeout after which egui should be repainted even if there's no new events.
|
||||
///
|
||||
/// Call [`Self::paint`] later to paint.
|
||||
pub fn run(
|
||||
&mut self,
|
||||
window: &winit::window::Window,
|
||||
run_ui: impl FnMut(&egui::Context),
|
||||
) -> bool {
|
||||
) -> std::time::Duration {
|
||||
let raw_input = self.egui_winit.take_egui_input(window);
|
||||
let egui::FullOutput {
|
||||
platform_output,
|
||||
needs_repaint,
|
||||
repaint_after,
|
||||
textures_delta,
|
||||
shapes,
|
||||
} = self.egui_ctx.run(raw_input, run_ui);
|
||||
@@ -62,7 +62,7 @@ impl EguiGlow {
|
||||
|
||||
self.shapes = shapes;
|
||||
self.textures_delta.append(textures_delta);
|
||||
needs_repaint
|
||||
repaint_after
|
||||
}
|
||||
|
||||
/// Paint the results of the last call to [`Self::run`].
|
||||
|
||||
Reference in New Issue
Block a user