refactor: unified Element interface with Draw method and Container type
- Add Draw(gtx, r *Renderer) to Element interface - Add Container type that implements Element and holds []Element children - Leaf types (Label, Icon, Button) implement Draw themselves - Single recursive drawElement function in Renderer — no switch/case - Remove StatusBar/BottomBar — replaced by Container - Remove shaper.go — no longer needed with Gio material labels - Simplify main.go — scale via ScaleProvider interface - 5 files changed, shaper.go deleted
This commit is contained in:
+9
-13
@@ -33,16 +33,17 @@ func run(w *app.Window) error {
|
||||
|
||||
shaper := text.NewShaper(text.WithCollection(gofont.Collection()))
|
||||
|
||||
// Initial DP size from app.Size() — used before we know the scale factor
|
||||
// Initial DP size from app.Size()
|
||||
initialDPW := ui.Dp(390)
|
||||
initialDPH := ui.Dp(844)
|
||||
|
||||
// Create logic instance with initial DP size and scale=1.0
|
||||
// Create logic instance
|
||||
logic := editor.NewLogic(initialDPW, initialDPH)
|
||||
|
||||
// Create renderer — reads scale from State via ScaleProvider
|
||||
renderer := ui.New(ui.Theme{FontSize: 14}, shaper, logic.State())
|
||||
|
||||
// Track pixel dimensions from ConfigEvent (for resize handling)
|
||||
// Track pixel dimensions from ConfigEvent
|
||||
var pixelW, pixelH int
|
||||
|
||||
// Shared state protected by mutex
|
||||
@@ -54,7 +55,6 @@ func run(w *app.Window) error {
|
||||
|
||||
// Start frame receiver goroutine
|
||||
go frameReceiver(w, &mu, &elems, logic.FrameChan())
|
||||
scale := float32(1.0)
|
||||
|
||||
// Main event loop
|
||||
for {
|
||||
@@ -62,13 +62,12 @@ func run(w *app.Window) error {
|
||||
case app.DestroyEvent:
|
||||
return e.Err
|
||||
case app.ConfigEvent:
|
||||
// Store pixel dimensions from ConfigEvent
|
||||
pixelW = e.Config.Size.X
|
||||
pixelH = e.Config.Size.Y
|
||||
// Convert to DP using current scale
|
||||
// Convert pixels to DP using current scale
|
||||
scale := logic.Scale()
|
||||
dpW := ui.ToDp(ui.Px(pixelW), scale)
|
||||
dpH := ui.ToDp(ui.Px(pixelH), scale)
|
||||
// Send config event to logic goroutine (in DP)
|
||||
logic.ConfigChan() <- editor.ConfigEvent{
|
||||
Width: dpW,
|
||||
Height: dpH,
|
||||
@@ -76,19 +75,16 @@ func run(w *app.Window) error {
|
||||
case app.FrameEvent:
|
||||
gtx := app.NewContext(&ops, e)
|
||||
|
||||
// Get scale from State — this is updated by ScaleEvent
|
||||
// Update scale if changed
|
||||
newScale := gtx.Metric.PxPerDp
|
||||
|
||||
if newScale != scale {
|
||||
// Send updated scale to logic goroutine
|
||||
curScale := logic.Scale()
|
||||
if newScale != curScale {
|
||||
logic.ConfigChan() <- editor.ScaleEvent{newScale}
|
||||
scale = newScale
|
||||
}
|
||||
|
||||
// Acquire mutex, read frame, draw, release mutex
|
||||
mu.Lock()
|
||||
currentElems := elems
|
||||
|
||||
renderer.Draw(gtx, currentElems)
|
||||
e.Frame(&ops)
|
||||
mu.Unlock()
|
||||
|
||||
Reference in New Issue
Block a user