Native rendering backend for macOS using Core Graphics and Cocoa.
This backend implements the GoFlow Canvas interface using:
- Core Graphics (Quartz 2D) - 2D rendering API
- Core Text - Text layout and rendering
- Cocoa (AppKit) - Window management and event handling
✅ Implemented:
- Rectangle drawing (filled and stroked)
- Circle drawing (filled and stroked)
- Line drawing
- Text rendering with font support
- Canvas transformations (translate, scale, rotate)
- Canvas state save/restore
- Clipping rectangles
- Window creation and management
- Basic event loop
⏳ TODO:
- Mouse event handling
- Keyboard event handling
- More drawing primitives (paths, images)
- Advanced text layout
┌─────────────────────────────────────┐
│ window_macos.go (Go API) │
├─────────────────────────────────────┤
│ canvas_macos.go (Canvas impl) │
├─────────────────────────────────────┤
│ CGo Bridge (C/Go boundary) │
├─────────────────────────────────────┤
│ window_bridge.m (Objective-C) │
│ cgo_bridge.m (Objective-C) │
├─────────────────────────────────────┤
│ Core Graphics / Core Text │
│ Cocoa (AppKit) │
└─────────────────────────────────────┘
package main
import (
"github.com/base-go/GoFlow/backends/macos"
"github.com/base-go/GoFlow/pkg/core/framework"
)
func main() {
// Initialize app
macos.InitApp()
// Create window
window := macos.NewWindow(800, 600, "My GoFlow App")
defer window.Destroy()
// Set draw callback
window.SetDrawFunc(func(canvas *macos.CoreGraphicsCanvas) {
// Clear background
canvas.Clear(goflow.ColorWhite)
// Draw a rectangle
paint := goflow.NewPaint()
paint.Color = goflow.ColorBlue
rect := goflow.NewRect(goflow.NewOffset(100, 100), goflow.NewSize(200, 150))
canvas.DrawRect(rect, paint)
// Draw text
style := goflow.NewTextStyle()
style.FontSize = 24
style.Color = goflow.ColorBlack
canvas.DrawText("Hello, GoFlow!", goflow.NewOffset(100, 50), style)
})
// Show window
window.Show()
// Event loop
for !window.ShouldClose() {
window.PollEvents()
window.SetNeedsDisplay()
}
}This backend requires macOS and uses CGo to interface with Objective-C:
go build -o myapp
./myappcanvas_macos.go- Canvas implementationwindow_macos.go- Window managementcgo_bridge.h/m- Core Graphics bridgingwindow_bridge.h/m- Cocoa window bridging
- macOS 10.12+ (Sierra or later recommended)
- Xcode Command Line Tools (for compilation)
The Core Graphics backend is hardware-accelerated and provides excellent performance for 2D rendering. Text rendering uses the system font renderer for perfect quality.