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:
+4
-4
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user