Expand description
Add command for scaffolding new UI windows.
This module provides the dampen add --ui <window_name> command that generates
UI window files (.rs and .dampen) based on templates.
§Overview
The add command scaffolds new UI windows for Dampen applications by:
- Generating a Rust module with model, handlers, and AppState
- Creating a corresponding
.dampenXML file with basic UI layout - Validating window names and output paths
- Preventing accidental file overwrites
§Usage
§Basic Usage
Create a new window in the default location (src/ui/):
dampen add --ui settingsThis generates:
src/ui/settings.rs- Rust module with Model and handlerssrc/ui/settings.dampen- XML UI definition
§Custom Output Directory
Specify a custom output directory with --path:
dampen add --ui order_form --path "src/ui/orders"This generates files in src/ui/orders/:
src/ui/orders/order_form.rssrc/ui/orders/order_form.dampen
§Window Name Conventions
Window names are automatically converted to proper case:
- Input:
UserProfile→ Files:user_profile.rs,user_profile.dampen - Input:
settings→ Files:settings.rs,settings.dampen
§Generated Code Structure
The generated Rust module includes:
Modelstruct with#[derive(UiModel)]for data bindingcreate_app_state()function that returns configuredAppState<Model>create_handler_registry()with sample event handlers- Auto-loading via
#[dampen_ui]macro
The generated XML includes:
- Basic column layout with text and button widgets
- Data binding example (
{message}) - Event handler hookup (
on_click="on_action")
§After Generation
-
Add the module to
src/ui/mod.rs:ⓘpub mod settings; -
Validate the XML:
dampen check -
Use in your application:
ⓘuse ui::settings; let state = settings::create_app_state();
§Error Handling
The command validates:
- Project context (must be a Dampen project with
dampen-coredependency) - Window name (must be valid Rust identifier, not a reserved keyword)
- Output path (must be relative, within project bounds)
- File conflicts (prevents overwriting existing files)
§Examples
# Create a settings window
dampen add --ui settings
# Create an admin dashboard in a subdirectory
dampen add --ui dashboard --path "src/ui/admin"
# Create an order form
dampen add --ui OrderForm
# → Generates: order_form.rs, order_form.dampenRe-exports§
pub use errors::GenerationError;pub use errors::PathError;pub use errors::ProjectError;pub use errors::ValidationError;pub use templates::TemplateKind;pub use templates::WindowNameVariants;pub use templates::WindowTemplate;pub use validation::ProjectInfo;pub use validation::TargetPath;pub use validation::WindowName;pub use generation::GeneratedFiles;pub use generation::generate_window_files;
Modules§
- errors
- Error types for the add command.
- generation
- File generation logic for creating window files from templates.
- integration
- Module d’intégration automatique pour les nouvelles fenêtres UI.
- templates
- Template loading and rendering logic.
- validation
- Validation logic for window names, paths, and project detection.
- view_
switching - View switching activation logic for enabling multi-view in main.rs
Structs§
- AddArgs
- Arguments for the
dampen addcommand.
Functions§
- execute
- Execute the add command.