Store scale in State, use it everywhere instead of gtx.Metric.PxPerDp
- State.Scale stores the scale factor (default 1.0) - ScaleEvent applies SetScale() which updates State.Scale - Logic.Scale() accessor returns current scale - Renderer.SetScale() updates renderer's scale from State - main.go: uses logic.Scale() to get scale, calls renderer.SetScale() - No more references to gtx.Metric.PxPerDp in render.go or main.go
This commit is contained in:
+5
-8
@@ -40,8 +40,6 @@ func run(w *app.Window) error {
|
||||
|
||||
// Track pixel dimensions from ConfigEvent (for resize handling)
|
||||
var pixelW, pixelH int
|
||||
// Track previous scale to detect changes
|
||||
scale := float32(1.0)
|
||||
|
||||
// Create logic instance with initial DP size and scale=1.0
|
||||
logic := editor.NewLogic(initialDPW, initialDPH)
|
||||
@@ -75,13 +73,9 @@ func run(w *app.Window) error {
|
||||
}
|
||||
case app.FrameEvent:
|
||||
gtx := app.NewContext(&ops, e)
|
||||
newScale := gtx.Metric.PxPerDp
|
||||
|
||||
// If scale changed, send scale event to logic goroutine
|
||||
if newScale != scale {
|
||||
logic.ConfigChan() <- editor.ScaleEvent{Scale: newScale}
|
||||
scale = newScale
|
||||
}
|
||||
// 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)
|
||||
@@ -93,6 +87,9 @@ func run(w *app.Window) error {
|
||||
Height: dpH,
|
||||
}
|
||||
|
||||
// Update renderer with current scale from State
|
||||
renderer.SetScale(newScale)
|
||||
|
||||
// Acquire mutex, read frame, draw, release mutex
|
||||
mu.Lock()
|
||||
currentElems := elems
|
||||
|
||||
Reference in New Issue
Block a user