Add a screen for gpui tests

Allows me to test notifications
This commit is contained in:
Conrad Irwin 2023-10-02 09:53:30 -06:00
parent 92bb9a5fdc
commit 9dc292772a

View file

@ -103,6 +103,7 @@ pub struct Platform {
current_clipboard_item: Mutex<Option<ClipboardItem>>, current_clipboard_item: Mutex<Option<ClipboardItem>>,
cursor: Mutex<CursorStyle>, cursor: Mutex<CursorStyle>,
active_window: Arc<Mutex<Option<AnyWindowHandle>>>, active_window: Arc<Mutex<Option<AnyWindowHandle>>>,
active_screen: Screen,
} }
impl Platform { impl Platform {
@ -113,6 +114,7 @@ impl Platform {
current_clipboard_item: Default::default(), current_clipboard_item: Default::default(),
cursor: Mutex::new(CursorStyle::Arrow), cursor: Mutex::new(CursorStyle::Arrow),
active_window: Default::default(), active_window: Default::default(),
active_screen: Screen::new(),
} }
} }
} }
@ -136,12 +138,16 @@ impl super::Platform for Platform {
fn quit(&self) {} fn quit(&self) {}
fn screen_by_id(&self, _id: uuid::Uuid) -> Option<Rc<dyn crate::platform::Screen>> { fn screen_by_id(&self, uuid: uuid::Uuid) -> Option<Rc<dyn crate::platform::Screen>> {
None if self.active_screen.uuid == uuid {
Some(Rc::new(self.active_screen.clone()))
} else {
None
}
} }
fn screens(&self) -> Vec<Rc<dyn crate::platform::Screen>> { fn screens(&self) -> Vec<Rc<dyn crate::platform::Screen>> {
Default::default() vec![Rc::new(self.active_screen.clone())]
} }
fn open_window( fn open_window(
@ -158,6 +164,7 @@ impl super::Platform for Platform {
WindowBounds::Fixed(rect) => rect.size(), WindowBounds::Fixed(rect) => rect.size(),
}, },
self.active_window.clone(), self.active_window.clone(),
Rc::new(self.active_screen.clone()),
)) ))
} }
@ -170,6 +177,7 @@ impl super::Platform for Platform {
handle, handle,
vec2f(24., 24.), vec2f(24., 24.),
self.active_window.clone(), self.active_window.clone(),
Rc::new(self.active_screen.clone()),
)) ))
} }
@ -238,8 +246,18 @@ impl super::Platform for Platform {
fn restart(&self) {} fn restart(&self) {}
} }
#[derive(Debug)] #[derive(Debug, Clone)]
pub struct Screen; pub struct Screen {
uuid: uuid::Uuid,
}
impl Screen {
fn new() -> Self {
Self {
uuid: uuid::Uuid::new_v4(),
}
}
}
impl super::Screen for Screen { impl super::Screen for Screen {
fn as_any(&self) -> &dyn Any { fn as_any(&self) -> &dyn Any {
@ -255,7 +273,7 @@ impl super::Screen for Screen {
} }
fn display_uuid(&self) -> Option<uuid::Uuid> { fn display_uuid(&self) -> Option<uuid::Uuid> {
Some(uuid::Uuid::new_v4()) Some(self.uuid)
} }
} }
@ -275,6 +293,7 @@ pub struct Window {
pub(crate) edited: bool, pub(crate) edited: bool,
pub(crate) pending_prompts: RefCell<VecDeque<oneshot::Sender<usize>>>, pub(crate) pending_prompts: RefCell<VecDeque<oneshot::Sender<usize>>>,
active_window: Arc<Mutex<Option<AnyWindowHandle>>>, active_window: Arc<Mutex<Option<AnyWindowHandle>>>,
screen: Rc<Screen>,
} }
impl Window { impl Window {
@ -282,6 +301,7 @@ impl Window {
handle: AnyWindowHandle, handle: AnyWindowHandle,
size: Vector2F, size: Vector2F,
active_window: Arc<Mutex<Option<AnyWindowHandle>>>, active_window: Arc<Mutex<Option<AnyWindowHandle>>>,
screen: Rc<Screen>,
) -> Self { ) -> Self {
Self { Self {
handle, handle,
@ -299,6 +319,7 @@ impl Window {
edited: false, edited: false,
pending_prompts: Default::default(), pending_prompts: Default::default(),
active_window, active_window,
screen,
} }
} }
@ -329,7 +350,7 @@ impl super::Window for Window {
} }
fn screen(&self) -> Rc<dyn crate::platform::Screen> { fn screen(&self) -> Rc<dyn crate::platform::Screen> {
Rc::new(Screen) self.screen.clone()
} }
fn mouse_position(&self) -> Vector2F { fn mouse_position(&self) -> Vector2F {