Redesign ConfigEvent/Scale handling: ConfigEvent sets size, FrameEvent updates scale

- Logic layer has separate ConfigChan and ScaleChan
- ConfigEvent: width/height in Dp, set on ConfigEvent
- ScaleEvent: scale factor, set on FrameEvent when scale changes
- Logic has ScreenSize() accessor for layout/rendering pipeline
- Logic has SetScale() to update scale and recompute layout
- main.go: ConfigEvent stores pixels, converts to DP using current scale
- main.go: FrameEvent gets actual scale, sends ScaleEvent if changed
This commit is contained in:
gmp
2026-05-09 19:59:27 -04:00
parent 3fc28fd54b
commit b581abb691
3 changed files with 50 additions and 11 deletions
+16 -8
View File
@@ -41,7 +41,7 @@ func run(w *app.Window) error {
// Track pixel dimensions from ConfigEvent (for resize handling)
var pixelW, pixelH int
// Create logic instance with initial DP size
// Create logic instance with initial DP size and scale=1.0
logic := editor.NewLogic(initialDPW, initialDPH)
// Shared state protected by mutex
@@ -60,21 +60,29 @@ func run(w *app.Window) error {
case app.DestroyEvent:
return e.Err
case app.ConfigEvent:
// Store pixel dimensions for later conversion
// Store pixel dimensions from ConfigEvent
pixelW = e.Config.Size.X
pixelH = e.Config.Size.Y
// Use initial DP size until we get the scale from FrameEvent
// Convert to DP using current scale (starts at 1.0)
dpW := ui.ToDp(ui.Px(pixelW), 1.0)
dpH := ui.ToDp(ui.Px(pixelH), 1.0)
// Send config event to logic goroutine (in DP)
logic.ConfigChan() <- editor.ConfigEvent{
Width: initialDPW,
Height: initialDPH,
Width: dpW,
Height: dpH,
}
case app.FrameEvent:
gtx := app.NewContext(&ops, e)
scale := gtx.Metric.PxPerDp
newScale := gtx.Metric.PxPerDp
// If scale changed, send scale event to logic goroutine
if newScale != 1.0 {
logic.ScaleChan() <- editor.ScaleEvent{Scale: newScale}
}
// Convert pixel dimensions to DP using actual scale
dpW := ui.ToDp(ui.Px(pixelW), scale)
dpH := ui.ToDp(ui.Px(pixelH), 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{