Unify ConfigEvent and ScaleEvent on single channel with type switch

- ConfigUpdate interface with apply(*State) method
- ConfigEvent and ScaleEvent both implement ConfigUpdate
- Logic.ConfigChan() accepts both types
- Type switch in Run() differentiates ConfigEvent vs ScaleEvent
- main.go sends both on same ConfigChan()
This commit is contained in:
gmp
2026-05-09 20:10:06 -04:00
parent fbf6cfac95
commit ef31701d87
2 changed files with 39 additions and 31 deletions
+4 -4
View File
@@ -41,7 +41,7 @@ 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)
scale := float32(1.0)
// Create logic instance with initial DP size and scale=1.0
logic := editor.NewLogic(initialDPW, initialDPH)
@@ -78,9 +78,9 @@ func run(w *app.Window) error {
newScale := gtx.Metric.PxPerDp
// If scale changed, send scale event to logic goroutine
if newScale != prevScale {
logic.ScaleChan() <- editor.ScaleEvent{Scale: newScale}
prevScale = newScale
if newScale != scale {
logic.ConfigChan() <- editor.ScaleEvent{Scale: newScale}
scale = newScale
}
// Convert pixel dimensions to DP using actual scale