# hashiiiii/rectpop architecture

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

- Interactive diagram: https://gitdiagram.com/hashiiiii/rectpop
- Repository: https://github.com/hashiiiii/rectpop

## Overview

##### Main Components
- UI Request Component: Represents the Unity UI element (or code component) that triggers the floating UI. In the examples, these are represented by scripts like Example01 and Example02Request.
- PopHandler: Acts as the core coordinator. It receives a PopRequest (built from a RectTransform and Canvas) and delegates the processing.
- IPopProvider (and its default implementation, PopProvider): Responsible for calculating the correct settings for the floating UI. This includes determining positions and handling any offset or mode (Inside, OutsideVertical, OutsideHorizontal) adjustments.
- PopHelper: A utility that takes the computed results from PopHandler/IPopProvider and applies them to the UI’s RectTransform, ensuring the floating UI is positioned correctly.
- PopDispatcher: Implements an event-driven system to broadcast the result of a pop request (via PopDispatchedEvent) so that the floating UI can update appropriately. It also supports integration with event libraries.
- Integration Modules: Optional integrations with external event-driven frameworks, such as R3 and UniRx, which are demonstrated by separate example projects.

##### Out the Relationships and Interactions
- When a UI element (such as a button) is interacted with, its associated script creates a PopRequest (using its RectTransform and Canvas).
- This request is then sent to a PopHandler instance.
- The PopHandler calls the appropriate IPopProvider (or the default PopProvider) to calculate the correct floating UI settings based on the request.
- The computed result is either directly applied using PopHelper (as in the minimal usage example) or dispatched via PopDispatcher (as shown in the recommended usage example) to be handled asynchronously.
- The attached listener for the dispatched event then receives the PopDispatchedEvent and uses PopHelper to apply the settings to the floating UI’s RectTransform.

##### Important Architectural Patterns
- The package embraces a request/response design (through PopRequest and PopDispatchedEvent) that loosely couples the UI trigger from the display logic.
- There is a clear separation of concerns: PopHandler coordinates, IPopProvider calculates positioning, and PopHelper applies the UI changes.
- The use of events (via PopDispatcher) to decouple the population of results supports scalability and integration with reactive programming models (e.g., R3 and UniRx).

##### Relevant Technologies and Frameworks
- Unity’s UI system (using RectTransform, Canvas, Unity’s event system, etc.).
- The internal scripting architecture of RectPop (PopHandler, PopProvider, PopHelper, PopDispatcher).
- Optional libraries: R3 and UniRx for event-driven programming.
- Git-based package installation via Unity Package Manager.

##### Instructing the Principal Software Engineer to Include the Following
- Nodes for:
- UI Request (e.g., the Unity Button or any script initiating a PopRequest)
- PopHandler (the central orchestrator)
- IPopProvider / PopProvider (calculates floating UI parameters)
- PopDispatcher (event bus mechanism for broadcast, if used)
- PopHelper (utility for applying the computed settings)
- External Libraries (R3 / UniRx integrations) – you might indicate these with a separated or differently styled node.
- Start from UI Request → PopHandler → IPopProvider → (result dispatch via PopDispatcher) → PopHelper → Final UI update.
- A third for the UI client code and examples that trigger the logic.
- Optionally, if space permits, add sub-notes that detail key methods (like PopHandler.Request and PopHelper.Apply) or mention that the IPopProvider offers customizable behavior (via method overrides such as for GetPopAnchorWorldPoint and GetPopPivotPosition).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Request Components
    subgraph "UI Request Components"
        UI1("Example01 UI Request"):::client
        UI2("Example02Request UI Request"):::client
    end

    %% Core RectPop Components
    subgraph "Core RectPop"
        PH("PopHandler<br/>(Handles Request)"):::core
        PP("PopProvider<br/>(Default, implements IPopProvider)"):::core
        PD("PopDispatcher<br/>(Dispatches Event)"):::integration
        PHLP("PopHelper<br/>(Applies UI Settings)"):::core
    end

    %% Integration Modules
    subgraph "Integration Modules"
        subgraph "R3 Integration"
            R3UI("Example02RequestForR3 UI Request"):::client
            R3PD("PopDispatcherForR3"):::integration
        end
        subgraph "UniRx Integration"
            UniRxUI("Example02RequestForUniRx UI Request"):::client
            UniRxPD("PopDispatcherForUniRx"):::integration
        end
    end

    %% Main Flow for Standard UI Requests
    UI1 -->|"triggers"| PH
    UI2 -->|"triggers"| PH
    PH -->|"calls"| PP
    PP -->|"returns result"| PHLP
    PH -->|"dispatches (alt. flow)"| PD
    PD -->|"sends event"| PHLP

    %% Flow for Integration Modules (Event-Driven)
    R3UI -->|"triggers"| R3PD
    UniRxUI -->|"triggers"| UniRxPD
    R3PD -->|"sends event"| PHLP
    UniRxPD -->|"sends event"| PHLP

    %% Click Events for UI Request Components
    click UI1 "https://github.com/hashiiiii/rectpop/blob/main/Assets/RectPop/Examples/Sources/Example01.cs"
    click UI2 "https://github.com/hashiiiii/rectpop/blob/main/Assets/RectPop/Examples/Sources/Example02Request.cs"

    %% Click Events for Core RectPop Components
    click PH "https://github.com/hashiiiii/rectpop/blob/main/Assets/RectPop/Sources/Runtime/PopHandler.cs"
    click PP "https://github.com/hashiiiii/rectpop/blob/main/Assets/RectPop/Sources/Runtime/PopProvider.cs"
    click PHLP "https://github.com/hashiiiii/rectpop/blob/main/Assets/RectPop/Sources/Runtime/PopHelper.cs"
    click PD "https://github.com/hashiiiii/rectpop/blob/main/Assets/RectPop/Sources/Runtime/PopDispatcher.cs"

    %% Click Events for Integration Modules - R3
    click R3UI "https://github.com/hashiiiii/rectpop/blob/main/Assets/RectPop/Examples/Sources/Example02RequestForR3.cs"
    click R3PD "https://github.com/hashiiiii/rectpop/blob/main/Assets/RectPop/Examples/Sources/PopDispatcherForR3.cs"

    %% Click Events for Integration Modules - UniRx
    click UniRxUI "https://github.com/hashiiiii/rectpop/blob/main/Assets/RectPop/Examples/Sources/Example02RequestForUniRx.cs"
    click UniRxPD "https://github.com/hashiiiii/rectpop/blob/main/Assets/RectPop/Examples/Sources/PopDispatcherForUniRx.cs"

    %% Styles
    classDef core fill:#a2d2ff,stroke:#083d77,stroke-width:2px;
    classDef integration fill:#caffbf,stroke:#40916c,stroke-width:2px;
    classDef client fill:#ffadad,stroke:#d90429,stroke-width:2px;
```
