Don't notify when drawing

This commit is contained in:
Nathan Sobo 2023-12-13 16:01:49 -07:00
parent 26a31b41b9
commit 1e4a7e6ef1

View file

@ -237,6 +237,7 @@ pub struct Window {
bounds_observers: SubscriberSet<(), AnyObserver>, bounds_observers: SubscriberSet<(), AnyObserver>,
active: bool, active: bool,
pub(crate) dirty: bool, pub(crate) dirty: bool,
pub(crate) drawing: bool,
activation_observers: SubscriberSet<(), AnyObserver>, activation_observers: SubscriberSet<(), AnyObserver>,
pub(crate) last_blur: Option<Option<FocusId>>, pub(crate) last_blur: Option<Option<FocusId>>,
pub(crate) focus: Option<FocusId>, pub(crate) focus: Option<FocusId>,
@ -371,6 +372,7 @@ impl Window {
bounds_observers: SubscriberSet::new(), bounds_observers: SubscriberSet::new(),
active: false, active: false,
dirty: false, dirty: false,
drawing: false,
activation_observers: SubscriberSet::new(), activation_observers: SubscriberSet::new(),
last_blur: None, last_blur: None,
focus: None, focus: None,
@ -422,8 +424,10 @@ impl<'a> WindowContext<'a> {
/// Mark the window as dirty, scheduling it to be redrawn on the next frame. /// Mark the window as dirty, scheduling it to be redrawn on the next frame.
pub fn notify(&mut self) { pub fn notify(&mut self) {
if !self.window.drawing {
self.window.dirty = true; self.window.dirty = true;
} }
}
/// Close this window. /// Close this window.
pub fn remove_window(&mut self) { pub fn remove_window(&mut self) {
@ -1237,6 +1241,8 @@ impl<'a> WindowContext<'a> {
/// Draw pixels to the display for this window based on the contents of its scene. /// Draw pixels to the display for this window based on the contents of its scene.
pub(crate) fn draw(&mut self) -> Scene { pub(crate) fn draw(&mut self) -> Scene {
let t0 = std::time::Instant::now(); let t0 = std::time::Instant::now();
self.window.dirty = false;
self.window.drawing = true;
let window_was_focused = self let window_was_focused = self
.window .window
@ -1327,7 +1333,7 @@ impl<'a> WindowContext<'a> {
self.platform.set_cursor_style(cursor_style); self.platform.set_cursor_style(cursor_style);
} }
self.window.dirty = false; self.window.drawing = false;
eprintln!("frame: {:?}", t0.elapsed()); eprintln!("frame: {:?}", t0.elapsed());
scene scene
@ -2346,11 +2352,13 @@ impl<'a, V: 'static> ViewContext<'a, V> {
} }
pub fn notify(&mut self) { pub fn notify(&mut self) {
if !self.window.drawing {
self.window_cx.notify(); self.window_cx.notify();
self.window_cx.app.push_effect(Effect::Notify { self.window_cx.app.push_effect(Effect::Notify {
emitter: self.view.model.entity_id, emitter: self.view.model.entity_id,
}); });
} }
}
pub fn observe_window_bounds( pub fn observe_window_bounds(
&mut self, &mut self,