gpui-nav
A lightweight screen navigation library for GPUI applications.
Quick Start
Add this to your Cargo.toml:
[]
= "0.2.1"
= "0.1.0"
Basic Usage
use *;
use ;
// Define your app state
// Define a screen
Navigation Operations
Push a new screen
let settings_screen = new;
app.navigator.push;
Pop the current screen
app.navigator.pop;
Replace the current screen
let login_screen = new;
app.navigator.replace;
Clear stack and push new screen
let home_screen = new;
app.navigator.clear_and_push;
Examples
Basic Navigation Example
A complete example demonstrating navigation between multiple screens with state management:
Features demonstrated:
- Multiple screens (Home, Profile, Settings)
- All navigation operations (push, pop, replace, clear_and_push)
- Shared state management
- Login/logout flow
- Clean modular architecture
Core Concepts
Screen Trait
Every screen must implement the Screen trait:
ScreenContext
ScreenContext provides convenient navigation methods:
Navigator
The Navigator manages your navigation stack:
Architecture
Your App State
├── Navigator (manages screen stack)
├── Shared Data (accessible to all screens)
└── Business Logic
Screen A ←→ ScreenContext ←→ Navigator ←→ Screen B
↓ ↓ ↓
UI Logic Navigation API UI Logic
Best Practices
- Single Navigator: Keep one navigator instance in your app state
- Screen IDs: Use descriptive, unique screen identifiers
- State Management: Store shared data in your app state, not in screens
- Memory: Screens are automatically cleaned up when popped
Compatibility
- GPUI: 0.2+
- Rust: 1.70+
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.