Skip to content

Conversation

@kolkov
Copy link
Contributor

@kolkov kolkov commented Dec 30, 2025

Summary

Phase 0 Foundation implementation for gogpu/ui - core packages required before Phase 1 MVP.

Packages Added

Package LOC Coverage Description
geometry/ ~800 100% Point, Size, Rect, Constraints, Insets
event/ ~600 100% Event types, MouseEvent, KeyEvent, Modifiers
widget/ ~2,956 100% Widget interface, WidgetBase, Context, Canvas, Color
internal/render/ ~1,740 96.5% Canvas implementation using gogpu/gg
internal/layout/ ~4,165 89.9% Layout engine, Flex, Stack, Grid

Total: ~10,261 lines of code

Key Features

  • geometry: Foundation types for UI layout (float32 for GPU compatibility)
  • event: Type-safe event system with bitmask modifiers
  • widget: Core Widget interface with thread-safe WidgetBase
  • internal/render: Canvas implementation wrapping gogpu/gg
  • internal/layout: CSS Flexbox-style layout + VStack/HStack/ZStack + Grid

Design Decisions

  1. float32 everywhere - GPU-compatible, matches WebGPU conventions
  2. Bitmask modifiers - Efficient keyboard modifier handling
  3. Thread-safe WidgetBase - Safe for concurrent UI updates
  4. Constraint-based layout - Flutter-inspired layout system
  5. gogpu/gg as render backend - Pure Go 2D graphics

Test Plan

  • All packages build successfully
  • All tests pass (100% for public, >80% for internal)
  • golangci-lint passes with 0 issues
  • pre-release-check.sh passes

Dependencies Added

  • github.com/gogpu/gg v0.15.7 - 2D graphics backend

Phase 0 Stage 1 of UI foundation implementation:
- Point: 2D coordinates with math operations (Add, Sub, Scale, Distance, Lerp, etc.)
- Size: dimensions with Contains, FitIn, FillIn, aspect ratio support
- Rect: rectangle with Contains, Intersects, Union, Inset operations
- Constraints: Flutter-style BoxConstraints for layout (Tight, Loose, Expand)
- Insets: edge padding/margin support (Uniform, Symmetric, LTRB)

All types use float32 for GPU compatibility.
Test coverage: 98.8%
Add complete event package for UI framework:
- Event interface and Base type with modifiers, timestamp, handled flag
- MouseEvent with press, release, move, enter, leave, drag, double-click
- KeyEvent with 100+ key codes (A-Z, 0-9, F1-F24, navigation, numpad)
- FocusEvent for focus gained/lost
- WheelEvent for mouse wheel scrolling
- Modifiers bitmask (Shift, Ctrl, Alt, Super, CapsLock, NumLock)

Test coverage: 100%
golangci-lint: 0 issues
- Widget interface with Layout, Draw, Event, Children methods
- WidgetBase struct with thread-safe state management
- Context interface for UI state (focus, time, invalidation, cursor)
- Canvas interface for drawing operations
- Color type with float32 RGBA and helpers (Hex, Lerp, WithAlpha)
- CursorType enum with 12 cursor types
- Comprehensive tests with 100% coverage
- ~2,956 lines of code
- Canvas implements widget.Canvas interface using gogpu/gg backend
- Drawing ops: Clear, DrawRect, StrokeRect, DrawRoundRect, DrawCircle, DrawLine
- Clip stack with intersection-based clipping and visibility culling
- Transform stack with cumulative offsets
- Color conversion utilities (widget.Color <-> gg.RGBA)
- Renderer for render cycle orchestration (BeginFrame/EndFrame)
- RenderTarget interface with SoftwareTarget implementation
- 96.5% test coverage
- Add gogpu/gg v0.15.7 dependency
- Layout engine with caching and dirty tracking
- Layoutable interface for layout abstractions
- FlexContainer: full CSS Flexbox (direction, justify, align, grow/shrink)
- VStack, HStack, ZStack for simple layouts
- GridContainer with auto/fixed/fractional tracks and cell spanning
- Integrates with geometry.Constraints API
- 89.9% test coverage
- Run gofmt on flex.go, canvas.go, canvas_test.go
- Remove 'replace github.com/gogpu/gg => ../gg' for CI compatibility
- CHANGELOG.md: Add detailed Phase 0 section with all packages
- README.md: Update status badges, add implemented packages table
- ROADMAP.md: Mark Phase 0 complete, update task statuses

Statistics: ~10,261 LOC, 95%+ test coverage, 0 linter issues
@kolkov kolkov merged commit c26fc8a into main Dec 30, 2025
16 checks passed
@kolkov kolkov deleted the feat/phase0-foundation branch December 30, 2025 00:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants