Skip to main content

Module add

Module add 

Source
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 .dampen XML 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 settings

This generates:

  • src/ui/settings.rs - Rust module with Model and handlers
  • src/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.rs
  • src/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:

  • Model struct with #[derive(UiModel)] for data binding
  • create_app_state() function that returns configured AppState<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

  1. Add the module to src/ui/mod.rs:

    pub mod settings;
  2. Validate the XML:

    dampen check
  3. 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-core dependency)
  • 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.dampen

Re-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 add command.

Functions§

execute
Execute the add command.