Screen

Trait Screen 

Source
pub trait Screen: Render + 'static {
    // Required method
    fn id(&self) -> &'static str;

    // Provided methods
    fn on_enter(&mut self, _cx: &mut Context<'_, Self>)
       where Self: Sized { ... }
    fn on_exit(&mut self, _cx: &mut Context<'_, Self>)
       where Self: Sized { ... }
}
Expand description

A screen that can be displayed in the navigation stack.

Screens must implement both Render and this trait to be used with the navigator.

§Example

use gpui::*;
use gpui_nav::Screen;

pub struct MyScreen {
    // your fields
}

impl Screen for MyScreen {
    fn id(&self) -> &'static str {
        "my_screen"
    }
}

impl Render for MyScreen {
    fn render(&mut self, _: &mut Window, _: &mut Context<Self>) -> impl IntoElement {
        div().child("My Screen")
    }
}

Required Methods§

Source

fn id(&self) -> &'static str

Returns a unique identifier for this screen.

This ID is used for history tracking and debugging.

Provided Methods§

Source

fn on_enter(&mut self, _cx: &mut Context<'_, Self>)
where Self: Sized,

Called when the screen is pushed onto the navigation stack.

Use this to initialize state or start timers/animations.

Source

fn on_exit(&mut self, _cx: &mut Context<'_, Self>)
where Self: Sized,

Called when the screen is popped from the navigation stack.

Use this to clean up resources or cancel ongoing operations.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§