Redraw the window at the end of flush_effects in tests

Co-Authored-By: Max Brunsfeld <max@zed.dev>
This commit is contained in:
Antonio Scandurra 2023-12-11 20:10:27 +01:00
parent f1ebad22db
commit 9b94f1483a
4 changed files with 24 additions and 9 deletions

View file

@ -595,6 +595,14 @@ impl AppContext {
break; break;
} }
} }
for (_, window) in &self.windows {
if let Some(window) = window.as_ref() {
if window.dirty {
window.platform_window.invalidate();
}
}
}
} }
/// Repeatedly called during `flush_effects` to release any entities whose /// Repeatedly called during `flush_effects` to release any entities whose
@ -713,7 +721,7 @@ impl AppContext {
fn apply_refresh_effect(&mut self) { fn apply_refresh_effect(&mut self) {
for window in self.windows.values_mut() { for window in self.windows.values_mut() {
if let Some(window) = window.as_mut() { if let Some(window) = window.as_mut() {
window.platform_window.invalidate(); window.dirty = true;
} }
} }
} }

View file

@ -136,11 +136,12 @@ impl Platform for TestPlatform {
&self, &self,
handle: AnyWindowHandle, handle: AnyWindowHandle,
options: WindowOptions, options: WindowOptions,
_draw: Box<dyn FnMut() -> Result<Scene>>, draw: Box<dyn FnMut() -> Result<Scene>>,
) -> Box<dyn crate::PlatformWindow> { ) -> Box<dyn crate::PlatformWindow> {
*self.active_window.lock() = Some(handle); *self.active_window.lock() = Some(handle);
Box::new(TestWindow::new( Box::new(TestWindow::new(
options, options,
draw,
self.weak.clone(), self.weak.clone(),
self.active_display.clone(), self.active_display.clone(),
)) ))

View file

@ -1,7 +1,7 @@
use crate::{ use crate::{
px, AtlasKey, AtlasTextureId, AtlasTile, Pixels, PlatformAtlas, PlatformDisplay, px, AtlasKey, AtlasTextureId, AtlasTile, DrawWindow, Pixels, PlatformAtlas, PlatformDisplay,
PlatformInputHandler, PlatformWindow, Point, Scene, Size, TestPlatform, TileId, PlatformInputHandler, PlatformWindow, Point, Size, TestPlatform, TileId, WindowAppearance,
WindowAppearance, WindowBounds, WindowOptions, WindowBounds, WindowOptions,
}; };
use collections::HashMap; use collections::HashMap;
use parking_lot::Mutex; use parking_lot::Mutex;
@ -20,7 +20,7 @@ pub(crate) struct TestWindowHandlers {
pub struct TestWindow { pub struct TestWindow {
pub(crate) bounds: WindowBounds, pub(crate) bounds: WindowBounds,
current_scene: Mutex<Option<Scene>>, draw: Mutex<DrawWindow>,
display: Rc<dyn PlatformDisplay>, display: Rc<dyn PlatformDisplay>,
pub(crate) window_title: Option<String>, pub(crate) window_title: Option<String>,
pub(crate) input_handler: Option<Arc<Mutex<Box<dyn PlatformInputHandler>>>>, pub(crate) input_handler: Option<Arc<Mutex<Box<dyn PlatformInputHandler>>>>,
@ -32,12 +32,13 @@ pub struct TestWindow {
impl TestWindow { impl TestWindow {
pub fn new( pub fn new(
options: WindowOptions, options: WindowOptions,
draw: DrawWindow,
platform: Weak<TestPlatform>, platform: Weak<TestPlatform>,
display: Rc<dyn PlatformDisplay>, display: Rc<dyn PlatformDisplay>,
) -> Self { ) -> Self {
Self { Self {
bounds: options.bounds, bounds: options.bounds,
current_scene: Default::default(), draw: Mutex::new(draw),
display, display,
platform, platform,
input_handler: None, input_handler: None,
@ -166,7 +167,9 @@ impl PlatformWindow for TestWindow {
unimplemented!() unimplemented!()
} }
fn invalidate(&self) {} fn invalidate(&self) {
(self.draw.lock())().unwrap();
}
fn sprite_atlas(&self) -> sync::Arc<dyn crate::PlatformAtlas> { fn sprite_atlas(&self) -> sync::Arc<dyn crate::PlatformAtlas> {
self.sprite_atlas.clone() self.sprite_atlas.clone()

View file

@ -223,6 +223,7 @@ pub struct Window {
bounds: WindowBounds, bounds: WindowBounds,
bounds_observers: SubscriberSet<(), AnyObserver>, bounds_observers: SubscriberSet<(), AnyObserver>,
active: bool, active: bool,
pub(crate) dirty: 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>,
@ -355,6 +356,7 @@ impl Window {
bounds, bounds,
bounds_observers: SubscriberSet::new(), bounds_observers: SubscriberSet::new(),
active: false, active: false,
dirty: false,
activation_observers: SubscriberSet::new(), activation_observers: SubscriberSet::new(),
last_blur: None, last_blur: None,
focus: None, focus: None,
@ -406,7 +408,7 @@ 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) {
self.window.platform_window.invalidate(); self.window.dirty = true;
} }
/// Close this window. /// Close this window.
@ -1237,6 +1239,7 @@ impl<'a> WindowContext<'a> {
.take() .take()
.unwrap_or(CursorStyle::Arrow); .unwrap_or(CursorStyle::Arrow);
self.platform.set_cursor_style(cursor_style); self.platform.set_cursor_style(cursor_style);
self.window.dirty = false;
scene scene
} }