# toikron/imdesignmanager architecture

> Architecture diagram of the GitHub repository toikron/imdesignmanager, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/toikron/imdesignmanager
- Repository: https://github.com/toikron/imdesignmanager

## Overview

##### Project type and purpose
- This is a single-header C++ library that augments Dear ImGui with an in-app visual UI design workflow.

##### File structure
- There is only one source file: design_manager.h
- No separate “frontend” or “backend” directories—everything lives in that header.
- README and build/dependency instructions point to Dear ImGui, GLFW/OpenGL (or SDL) as prerequisites.

a. Host Application
- The main C++ application that creates an ImGui context (via GLFW, SDL, etc.)
- Calls into ImGui_Impl* for platform and renderer bindings
b. Dear ImGui Core
- UI framework that renders immediate-mode widgets
c. DesignManager Module (design_manager.h)
- Initialization (Init) – registers window dimensions and pointer to native window
- Data structures
– g_windowsMap: maps window names → Window objects
– Window: contains Layers → ShapeItem lists
- Visual Editor UI
– ShowChainAnimationGUI(): editor for animation sequences
- Runtime update & render
– UpdateChainAnimations(): step animations
– RenderAllRegisteredWindows()/RenderTemporaryWindows(): manage auxiliary windows
- Code Generation / Builder API
– ShapeBuilder, AnimationBuilder, etc. for programmatic UI creation
– GeneratedCode(): user‐provided function with builder calls
d. External Services & Dependencies
- Backend libraries (GLFW/OpenGL/SDL)
- Dear ImGui submodule under external/imgui

##### Relationships and data flow
- At startup: Host App → ImGui_Impl init → DesignManager::Init()
- Design load: Host App → DesignManager::GeneratedCode() (invokes builder to populate g_windowsMap)
- Each frame:
- Host App polls events → ImGui new frame
- Calls DesignManager updates in sequence (responsiveness, animations)
- Optionally calls ShowUI/ShowChainAnimationGUI to display editor overlays
- Ends ImGui frame → ImGui render → platform swap buffers
- User interactions in the editor update data structures in DesignManager, triggering code-gen updates.

##### Architectural patterns and principles
- Immediate-mode UI pattern (via ImGui)
- Builder Pattern for programmatic code generation of UI
- MVC‐like separation:
- Model: ShapeItem, Layer, Window data structures
- View: ImGui rendering calls in DrawAll
- Modular design: single header to plug into any linear ImGui setup
- Extensibility point: experimental HTML/CSS/React parser module

##### Essential elements
- Component labels (Host App, ImGui Core, DesignManager editor/runtime, backends)
- Annotations for key data structures (g_windowsMap, ShapeItem, Layer)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Host Application
    subgraph "Host Application"
        HA["Host Application"]:::app
        IMPL["ImGui_Impl* Bindings"]:::core
    end

    %% Core Frameworks
    subgraph "Dear ImGui Core"
        IC["Dear ImGui Core"]:::core
    end

    %% DesignManager Module
    subgraph "DesignManager Module"
        DM_Init["Init()"]:::dm
        DM_DataModel["Data Model\n(g_windowsMap, ShapeItem, Layer, Window)"]:::dm
        DM_Editor["Visual Editor UI\nShowUI(), ShowChainAnimationGUI()"]:::dm
        DM_Runtime["Runtime & Render\nUpdateShapeTransforms(), UpdateChainAnimations(), DrawAll(), RenderAllRegisteredWindows()"]:::dm
        DM_CodeGen["Code Generation API\nGeneratedCode(), ShapeBuilder, AnimationBuilder"]:::dm
    end

    %% External Backends and Submodules
    subgraph "External Dependencies"
        EB1["GLFW/OpenGL/SDL"]:::ext
        EB2["external/imgui submodule"]:::ext
    end

    %% Project Files
    subgraph "Project Files"
        README["README.md"]:::app
        LICENSE["LICENSE"]:::app
        GITIGNORE[".gitignore"]:::app
        EXCODE["Screenshot's Generated code.txt"]:::app
    end

    %% Relationships
    HA -->|"ImGui_Impl init"| IMPL
    IMPL --> IC
    EB1 --> HA
    EB2 --> IC

    IC -->|"DesignManager::Init()"| DM_Init
    HA -->|"DesignManager::GeneratedCode()"| DM_CodeGen

    HA -->|"PollEvents"| IC
    IC -->|"NewFrame()"| DM_Runtime
    DM_Runtime -->|"DrawAll()"| IC
    IC -->|"Render()"| HA

    DM_Editor <-->|"edit shapes/layers"| DM_DataModel

    %% Click Events
    click DM_Init "https://github.com/toikron/imdesignmanager/blob/main/design_manager.h"
    click DM_DataModel "https://github.com/toikron/imdesignmanager/blob/main/design_manager.h"
    click DM_Editor "https://github.com/toikron/imdesignmanager/blob/main/design_manager.h"
    click DM_Runtime "https://github.com/toikron/imdesignmanager/blob/main/design_manager.h"
    click DM_CodeGen "https://github.com/toikron/imdesignmanager/blob/main/design_manager.h"
    click README "https://github.com/toikron/imdesignmanager/blob/main/README.md"
    click LICENSE "https://github.com/toikron/imdesignmanager/tree/main/LICENSE"
    click GITIGNORE "https://github.com/toikron/imdesignmanager/blob/main/.gitignore"
    click EXCODE "https://github.com/toikron/imdesignmanager/blob/main/Screenshot's Generated code.txt"

    %% Styles
    classDef app fill:#e0e0e0,stroke:#888,stroke-width:1px;
    classDef core fill:#bbdefb,stroke:#1976d2,stroke-width:1px;
    classDef dm fill:#c8e6c9,stroke:#2e7d32,stroke-width:1px;
    classDef ext fill:#eeeeee,stroke:#666,stroke-width:1px;
```
