Simple GPUI
Overview
Simple GPUI is a Rust library that provides a simplified component-based framework for building GPUI applications. It offers a declarative approach to creating UI components using procedural macros, making GPUI development more intuitive and ergonomic.
Features
- Component Macro: Simplify component creation with the
#[component]attribute macro - Reactive Properties: Define component properties with automatic getter/setter generation
- Event Subscriptions: Easy event handling with the
subscribe!macro - Context Management: Simplified context access with
init_with_context! - Type-Safe: Full Rust type safety with compile-time guarantees
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
= "0.2.2"
= "0.3.1"
Quick Start
Here's a simple "Hello World" example:
use *;
use component;
Core Concepts
Component Properties
Define component properties using the component_property! macro:
Event Subscriptions
Subscribe to events from entities using the subscribe! macro:
Context Access
Use init_with_context!() when you need to access the window or context during property initialization:
Examples
The repository includes several examples:
- hello_world.rs - Basic component with properties
- gpui_component_input.rs - Input handling with event subscriptions
- temperature_caculator.rs - Temperature converter with tabs and input validation
Run examples with:
Project Structure
simple-gpui/
├── src/ # Main library exports
├── simple_gpui_core/ # Core procedural macros
│ ├── src/
│ │ ├── lib.rs # Component macro implementation
│ │ ├── extractors.rs # Macro parsing logic
│ │ └── methods.rs # Code generation for methods
├── examples/ # Example applications
└── Cargo.toml
How It Works
The #[component] macro transforms your function into a struct with:
- Generated struct with fields for each
component_property! - new() method for initialization
- Setter methods for each property
- Render trait implementation using your function body
- Subscription management for event handlers
Requirements
- Rust 2024 edition or later
- GPUI 0.2.2+
- gpui-component 0.3.1+
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.