Fix event flow: ConfigEvent sets size, FrameEvent sets scale only

- ConfigEvent: ONLY from app.ConfigEvent, sets width/height in State
- FrameEvent: gets scale from gtx.Metric.PxPerDp, sends ScaleEvent only if changed
- ScaleEvent: updates State.Scale
- Renderer reads windowW/windowH from State (SetWindowSize), not gtx.Constraints
- Renderer reads scale from State (SetScale), not gtx.Metric.PxPerDp
- main.go: ConfigEvent calls SetWindowSize, FrameEvent calls SetScale
This commit is contained in:
gmp
2026-05-09 20:26:10 -04:00
parent 68437c32a7
commit 21b4df59a3
2 changed files with 24 additions and 19 deletions
+10 -12
View File
@@ -40,6 +40,8 @@ func run(w *app.Window) error {
// Track pixel dimensions from ConfigEvent (for resize handling)
var pixelW, pixelH int
// Track previous scale to detect changes
prevScale := float32(1.0)
// Create logic instance with initial DP size and scale=1.0
logic := editor.NewLogic(initialDPW, initialDPH)
@@ -71,24 +73,20 @@ func run(w *app.Window) error {
Width: dpW,
Height: dpH,
}
// Update renderer with window size from State
renderer.SetWindowSize(pixelW, pixelH)
case app.FrameEvent:
gtx := app.NewContext(&ops, e)
newScale := gtx.Metric.PxPerDp
// Get scale from State — this is updated by ScaleEvent
newScale := logic.Scale()
// Convert pixel dimensions to DP using actual scale
dpW := ui.ToDp(ui.Px(pixelW), newScale)
dpH := ui.ToDp(ui.Px(pixelH), newScale)
// Send updated config to logic goroutine
logic.ConfigChan() <- editor.ConfigEvent{
Width: dpW,
Height: dpH,
// If scale changed, send scale event to logic goroutine
if newScale != prevScale {
logic.ConfigChan() <- editor.ScaleEvent{Scale: newScale}
prevScale = newScale
}
// Update renderer with current scale from State
renderer.SetScale(newScale)
renderer.SetScale(logic.Scale())
// Acquire mutex, read frame, draw, release mutex
mu.Lock()