Dampen
Declarative UI framework for Rust with Iced backend, hot reloading and advanced styling.
Dampen allows you to define your user interface in XML and render it via Iced.
⚠️ DEVELOPMENT STATUS
Dampen is currently under active development and is NOT ready for production use.
The framework is functional and can be tested for experimentation, learning, and contributing to its development. However, the API is unstable and subject to breaking changes. Features may be incomplete, and there may be bugs or performance issues.
Use Dampen for:
- ✅ Experimentation and learning
- ✅ Contributing to development
- ✅ Testing and providing feedback
- ✅ Prototype applications
Do NOT use Dampen for:
- ❌ Production applications
- ❌ Mission-critical systems
- ❌ Applications requiring API stability
We welcome your feedback and contributions! See CONTRIBUTING.md to get involved.
Features
- ✅ Declarative XML definitions
- ✅ Advanced styling system (themes, classes, state styles)
- ✅ Responsive design with breakpoints (mobile, tablet, desktop)
- ✅ Type-safe event handlers
- ✅ Expression evaluation in XML attributes
- ✅ Full Iced widget support (text, buttons, inputs, layouts, etc.)
- ✅ Radio button groups with single-selection behavior
- ✅ Data binding with
#[derive(UiModel)] - ✅ CLI validation tools for syntax checking
- ✅ Dual-mode architecture: Hot-reload for development, codegen for production
- ✅ Hot-reload support: See UI changes instantly without recompiling
Installation
Quick Start
Create a New Project
Use the CLI command to scaffold a new Dampen project:
# Create a new project
# Navigate to the project
# Run the application
Add New UI Windows
NEW! Quickly scaffold new UI windows with the dampen add command:
# Add a settings window
# Add a window in custom directory
This creates:
settings.rs- Model, handlers, and AppState setupsettings.dampen- Basic UI layout with data binding example
Then add to src/ui/mod.rs:
Benefits:
- ✅ Production-ready code in < 1 second
- ✅ Consistent structure across windows
- ✅ Prevents accidental overwrites
- ✅ Reduces manual boilerplate
See dampen add --help for more options.
Project Structure
The dampen new command creates a complete project structure:
my-app/
├── Cargo.toml # Project dependencies
├── README.md # Getting started guide
├── build.rs # Code generation (XML → Rust)
├── src/
│ ├── main.rs # Application entry point
│ └── ui/
│ ├── mod.rs # UI module exports
│ ├── window.rs # Model and handlers with #[dampen_ui]
│ └── window.dampen # Declarative UI definition (XML)
└── tests/
└── integration.rs # Integration tests
Key Files:
| File | Description |
|---|---|
src/ui/window.dampen |
XML UI definition with widgets, bindings, handlers |
src/ui/window.rs |
Model with #[derive(UiModel)], handler registry |
src/main.rs |
Application orchestration (view, update) |
build.rs |
Compiles .dampen files to Rust code |
Generated UI Example:
Project Validation
# Validate XML syntax and widget names
# Build the project
# Inspect generated IR
Advanced Features
Data Binding
Type-Safe Event Handlers
Advanced Theming System
Reusable Style Classes
Responsive Design with Breakpoints
Available Widgets
| Widget | Description | Main Attributes |
|---|---|---|
text |
Text display | value, size, weight, color |
button |
Interactive button | label, on_click, enabled, class |
text_input |
Text input field | value, on_input, placeholder |
checkbox |
Checkbox | checked, on_toggle |
toggler |
Toggle switch | active, on_toggle, label |
pick_list |
Dropdown list | options, selected, on_select |
radio |
Radio button | label, value, selected, on_select |
column |
Vertical layout | spacing, padding, align |
row |
Horizontal layout | spacing, padding, align |
scrollable |
Scrollable area | width, height |
container |
Container | padding, width, height |
for |
Dynamic loop | each, in |
grid |
Grid layout | columns, spacing |
progress_bar |
Progress bar | min, max, value |
svg |
SVG image | path, width, height |
tooltip |
Tooltip | message, position |
Dual-Mode Architecture
Dampen supports two compilation modes optimized for different use cases:
Interpreted Mode (Development)
Enabled by default in development builds
- ✅ Fast iteration: Hot-reload UI changes without recompiling
- ✅ Runtime parsing: XML loaded and parsed at application startup
- ✅ Instant feedback: See changes in <300ms
- ✅ Debugging friendly: Error overlays with detailed messages
# Development mode (automatic)
# Explicit interpreted mode
Hot-reload example:
use watch_files;
Codegen Mode (Production)
Enabled by default in release builds
- ✅ Zero runtime overhead: All XML parsed at compile time
- ✅ Optimal performance: Direct widget construction
- ✅ Smaller binaries: No runtime parser included
- ✅ Build-time validation: Catch errors before deployment
# Production build (automatic codegen)
# Debug build with codegen
How it works:
build.rsprocesses.dampenfiles at compile time- Generated Rust code embedded via macros
- No runtime XML parsing required
Mode Selection
Mode selection is automatic based on build profile:
| CLI Command | Mode | Use Case |
|---|---|---|
dampen new |
- | Create new project |
dampen add |
- | Scaffold new UI window |
dampen run |
Interpreted | Development with hot-reload |
dampen build |
Codegen | Debug builds with codegen |
dampen release |
Codegen | Production deployments (optimized) |
dampen test |
Interpreted | Fast test iteration |
dampen check |
- | Validate XML syntax |
Advanced usage:
# Enable additional features
# Run tests in release mode
# Verbose output
Migration Guide
Migrating existing projects to dual-mode architecture? See our Migration Guide for step-by-step instructions.
Architecture
Crate Structure
crates/
├── dampen-core/ # XML parser, IR, traits (no Iced dependency)
├── dampen-macros/ # Macros #[derive(UiModel)], #[dampen_ui]
├── dampen-iced/ # Iced backend implementation
├── dampen-dev/ # Development mode tooling for Dampen
└── dampen-cli/ # Developer CLI (build, check, inspect)
Core Principles
- Declarative-First: XML is the source of truth for UI structure
- Type Safety: No type erasure for messages/state
- Production Mode: Static code generation for deployments
- Backend-Agnostic: Core crate has no Iced dependency
- Test-First: TDD for all features
Examples
See the examples/ directory for progressive demonstrations:
| Example | Features |
|---|---|
| hello-world | Minimal static UI rendering |
| counter | Interactive event handlers |
| todo-app | Complete data binding with lists |
| styling | Themes, classes, state styles |
| responsive | Responsive design with breakpoints |
| settings | Multiple views and navigation |
| widget-showcase | Demonstration of all widgets |
CLI Commands
# Generate production code
# Validate UI files without running
# Inspect IR or generated code
Documentation
- API Documentation - Complete Rustdoc
- XML Schema Reference - Widgets and attributes
- Styling Guide - Themes, classes, state styles
- Examples - Progressive example projects
Contributing
We welcome contributions from the community! Whether you're fixing bugs, adding features, improving documentation, or reporting issues, your help is appreciated.
Before contributing, please read our Contributing Guide which covers:
- Code of conduct and community standards
- Setting up your development environment
- Coding standards and style guidelines
- Testing requirements (TDD is mandatory)
- Pull request process and commit message format
- How to report issues and request features
Quick start for contributors:
# Fork and clone the repository
# Build and test
# Try the examples
All contributions must:
- ✅ Pass all tests (
cargo test --workspace) - ✅ Pass clippy lints (
cargo clippy --workspace -- -D warnings) - ✅ Be properly formatted (
cargo fmt --all) - ✅ Include tests for new functionality
- ✅ Update documentation as needed
See docs/CONTRIBUTING.md for complete details.
License
This project is dual-licensed under Apache 2.0 or MIT, at your option.
Built with ❤️ using Rust and Iced