Skip to content

GPU Layout Phase 0: Architecture Improvements #111

@Pluglug

Description

@Pluglug

Overview

Before proceeding with UI Scaling (#106), improve the architectural foundation of the GPU Layout system based on professional feedback.

Problems Identified

  1. Phase mixing: draw() calls layout() internally (layout.py:624)

    • Unpredictable behavior
    • Performance issues
    • Prevents Dirty Flag optimization
  2. State scattering: hovered/pressed states exist in multiple places

    • ButtonItem._hovered, _pressed (items.py)
    • InteractionState.hovered, pressed (interactive.py)
    • GPULayout._close_button_hovered (layout.py)
  3. Event propagation incomplete: Only bubble phase, no stopPropagation()

Sub-tasks

  • Phase 0-A: Separate draw() and layout() phases ✅ d3feb58
  • Phase 0-B: Centralize state management with UIStated3feb58
  • Phase 0-C: Improve event propagation with UIEvent.consume() (deferred)

Design Document

See _docs/design/gpu_phase0_architecture.md

Success Criteria

  • TEST_OT_gpu_layout works correctly
  • TEST_OT_gpu_interactive works correctly (drag, close button, hover, press)
  • Clean separation between layout and drawing phases
  • Single source of truth for UI state

Implementation Notes

Phase 0-A: Layout/Draw Separation

  • draw() no longer calls layout() internally
  • Added update_and_draw() convenience method
  • Introduced Dirty Flag pattern for optimization

Phase 0-B: Centralized State

  • UIState class: ID-based state management
  • ItemRenderState: passed to draw() methods
  • Removed _hovered/_pressed from items
  • State flows: HitTestManager → UIState → ItemRenderState → draw()

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions