gpui_nav/lib.rs
1//! # gpui-nav
2//!
3//! A lightweight screen navigation library for GPUI applications.
4//!
5//! ## Quick Start
6//!
7//! ```rust,no_run
8//! use gpui::*;
9//! use gpui_nav::{Navigator, Screen, ScreenContext};
10//!
11//! // Define your app state
12//! pub struct AppState {
13//! navigator: Navigator,
14//! }
15//!
16//! // Define a screen
17//! pub struct HomeScreen {
18//! ctx: ScreenContext<AppState>,
19//! }
20//!
21//! impl Screen for HomeScreen {
22//! fn id(&self) -> &'static str {
23//! "home"
24//! }
25//! }
26//!
27//! impl Render for HomeScreen {
28//! fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
29//! div().child("Home Screen")
30//! }
31//! }
32//! ```
33//!
34//! ## Navigation Operations
35//!
36//! ### Push a new screen
37//! ```rust,ignore
38//! let settings_screen = SettingsScreen::new(ctx.weak_entity());
39//! app.navigator.push(settings_screen, cx);
40//! ```
41//!
42//! ### Pop the current screen
43//! ```rust,ignore
44//! app.navigator.pop(cx);
45//! ```
46//!
47//! ### Replace the current screen
48//! ```rust,ignore
49//! let login_screen = LoginScreen::new(ctx.weak_entity());
50//! app.navigator.replace(login_screen, cx);
51//! ```
52//!
53//! ### Clear stack and push new screen
54//! ```rust,ignore
55//! let home_screen = HomeScreen::new(ctx.weak_entity());
56//! app.navigator.clear_and_push(home_screen, cx);
57//! ```
58//!
59//! ## Examples
60//!
61//! See the [basic navigation example](https://github.com/benodiwal/gpui-nav/tree/main/examples/basic_navigation)
62//! for a complete working demonstration.
63
64pub mod context;
65mod navigator;
66mod screen;
67
68#[cfg(test)]
69mod tests;
70
71pub use context::ScreenContext;
72pub use navigator::Navigator;
73pub use screen::Screen;
74
75/// Prelude module for convenient imports
76///
77/// Import everything you need to get started with gpui-nav:
78///
79/// ```rust
80/// use gpui_nav::prelude::*;
81///
82/// // Now you have access to Navigator, Screen, and ScreenContext
83/// ```
84pub mod prelude {
85 /// Convenient re-exports of commonly used gpui-nav types
86 pub use crate::{Navigator, Screen, ScreenContext};
87}