gpui_nav/
screen.rs

1use gpui::{Context, Render};
2
3/// A screen that can be displayed in the navigation stack.
4///
5/// Screens must implement both `Render` and this trait to be used with the navigator.
6///
7/// # Example
8///
9/// ```rust,ignore
10/// use gpui::*;
11/// use gpui_nav::Screen;
12///
13/// pub struct MyScreen {
14///     // your fields
15/// }
16///
17/// impl Screen for MyScreen {
18///     fn id(&self) -> &'static str {
19///         "my_screen"
20///     }
21/// }
22///
23/// impl Render for MyScreen {
24///     fn render(&mut self, _: &mut Window, _: &mut Context<Self>) -> impl IntoElement {
25///         div().child("My Screen")
26///     }
27/// }
28/// ```
29pub trait Screen: Render + 'static {
30    /// Returns a unique identifier for this screen.
31    ///
32    /// This ID is used for history tracking and debugging.
33    fn id(&self) -> &'static str;
34
35    /// Called when the screen is pushed onto the navigation stack.
36    ///
37    /// Use this to initialize state or start timers/animations.
38    fn on_enter(&mut self, _cx: &mut Context<Self>)
39    where
40        Self: Sized,
41    {
42    }
43
44    /// Called when the screen is popped from the navigation stack.
45    ///
46    /// Use this to clean up resources or cancel ongoing operations.
47    fn on_exit(&mut self, _cx: &mut Context<Self>)
48    where
49        Self: Sized,
50    {
51    }
52}