# maximinus/pyui architecture

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

- Interactive diagram: https://gitdiagram.com/maximinus/pyui
- Repository: https://github.com/maximinus/pyui

## Overview

##### Main Components

A. Core Framework Layer:
- Base Components (/pyui/base.py, widget_base.py)
- Theme System (theme.py)
- Setup Configuration (setup.py)

B. Event System:
- Event Loop (events/loop.py)
- Event Queue (events/queue.py)
- Event Handlers (events/events.py)

C. Widget System:
- Basic Widgets (buttons, labels, images, etc.)
- Container Widgets (frames, spacers)
- Layout Management (containers.py)

D. Resource Management:
- Asset Handling (assets/ directory)
- Theme Resources (assets/themes/)
- Nine-Patch Resources (assets/nine_patch/)

E. SDL Integration Layer:
- Rendering Interface
- Platform-specific Implementation

**┌─────────────────────────────────────────┐**
- Application Layer          │
- ┘
- ↑
**┌─────────────────────────────────────────┐**
- Widget System               │
- ┬─────────────┬────────────┤
- Containers │   Controls  │  Layouts   │
- ┴─────────────┴────────────┘
- ↑
**┌─────────────────────────────────────────┐**
- Event System                │
- ┬─────────────┬────────────┤
- Event Loop │    Queue    │  Handlers  │
- ┴─────────────┴────────────┘
- ↑
**┌─────────────────────────────────────────┐**
- SDL Render Engine             │
- ┘

##### Important Relationships

A. Component Dependencies:
- Widgets depend on the base framework
- Event system integrates with widgets
- Theme system affects all visual components
- SDL renderer used by all visual components

B. Data Flow:
- Event propagation through the system
- Widget hierarchy and containment
- Resource loading and management
- Rendering pipeline

##### Specific Implementation Details

- Widget inheritance hierarchy
- Event propagation paths
- Demonstrate the theme system's influence
- Asset management flow

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and Classes
    classDef core fill:#3498db,stroke:#2980b9,color:white
    classDef widget fill:#2ecc71,stroke:#27ae60,color:white
    classDef event fill:#f1c40f,stroke:#f39c12,color:black
    classDef resource fill:#9b59b6,stroke:#8e44ad,color:white
    classDef sdl fill:#e74c3c,stroke:#c0392b,color:white
    classDef test fill:#95a5a6,stroke:#7f8c8d,color:white

    %% Core Framework Layer
    subgraph CoreFramework
        Base["Base Components"]:::core
        Theme["Theme System"]:::core
        Setup["Setup Configuration"]:::core
    end

    %% Widget System Layer
    subgraph WidgetSystem
        BasicWidgets["Basic Widgets"]:::widget
        ContainerWidgets["Container Widgets"]:::widget
        MenuSystem["Menu System"]:::widget

        subgraph BasicWidgetComponents
            Buttons["Buttons"]:::widget
            Labels["Text Labels"]:::widget
            Images["Images"]:::widget
            ColorRect["Color Rectangle"]:::widget
        end

        subgraph ContainerComponents
            Frames["Frames"]:::widget
            Containers["Containers"]:::widget
            Spacers["Spacers"]:::widget
        end
    end

    %% Event System Layer
    subgraph EventSystem
        EventLoop["Event Loop"]:::event
        EventQueue["Event Queue"]:::event
        EventHandlers["Event Handlers"]:::event
    end

    %% Resource Management Layer
    subgraph ResourceManagement
        ThemeRes["Theme Resources"]:::resource
        NinePatchRes["Nine-Patch Resources"]:::resource
        AssetDirs["Asset Directories"]:::resource
    end

    %% SDL Integration Layer
    subgraph SDLIntegration
        SDLRenderer["SDL Render Engine"]:::sdl
    end

    %% Testing Framework
    subgraph TestingFramework
        WidgetTests["Widget Tests"]:::test
        EventTests["Event Tests"]:::test
        SDLTests["SDL Integration Tests"]:::test
    end

    %% Relationships
    Base --> BasicWidgets
    Base --> ContainerWidgets
    Theme --> BasicWidgets
    Theme --> ContainerWidgets
    
    EventLoop --> EventQueue
    EventQueue --> EventHandlers
    EventHandlers --> BasicWidgets
    EventHandlers --> ContainerWidgets
    
    BasicWidgets --> SDLRenderer
    ContainerWidgets --> SDLRenderer
    
    ThemeRes --> Theme
    NinePatchRes --> BasicWidgets
    AssetDirs --> BasicWidgets

    %% Click Events
    click Base "https://github.com/maximinus/PyUI/blob/main//pyui/base.py"
    click Theme "https://github.com/maximinus/PyUI/blob/main//pyui/theme.py"
    click Setup "https://github.com/maximinus/PyUI/blob/main//pyui/setup.py"
    click EventLoop "https://github.com/maximinus/PyUI/blob/main//pyui/events/loop.py"
    click EventQueue "https://github.com/maximinus/PyUI/blob/main//pyui/events/queue.py"
    click EventHandlers "https://github.com/maximinus/PyUI/blob/main//pyui/events/events.py"
    click Buttons "https://github.com/maximinus/PyUI/blob/main//pyui/widgets/buttons.py"
    click Labels "https://github.com/maximinus/PyUI/blob/main//pyui/widgets/text_label.py"
    click Images "https://github.com/maximinus/PyUI/blob/main//pyui/widgets/image.py"
    click ColorRect "https://github.com/maximinus/PyUI/blob/main//pyui/widgets/color_rect.py"
    click Frames "https://github.com/maximinus/PyUI/blob/main//pyui/widgets/frames.py"
    click Containers "https://github.com/maximinus/PyUI/blob/main//pyui/widgets/containers.py"
    click Spacers "https://github.com/maximinus/PyUI/blob/main//pyui/widgets/spacer.py"
    click MenuSystem "https://github.com/maximinus/PyUI/blob/main//pyui/widgets/menu.py"
    click ThemeRes "https://github.com/maximinus/PyUI/blob/main//assets/themes/basic_theme.json"
    click NinePatchRes "https://github.com/maximinus/PyUI/tree/main//assets/nine_patch"
    click AssetDirs "https://github.com/maximinus/PyUI/tree/main//assets"
    click WidgetTests "https://github.com/maximinus/PyUI/tree/main//test/widgets"
    click EventTests "https://github.com/maximinus/PyUI/tree/main//test/events"
    click SDLTests "https://github.com/maximinus/PyUI/blob/main//test/sdl_test.py"
```
