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
+14 -7
View File
@@ -20,6 +20,9 @@ type Renderer struct {
theme Theme
shp *text.Shaper
scale float32 // pixels per DP, from State.Scale
// Window dimensions in physical pixels, from State
windowW int
windowH int
}
// New creates a new Renderer.
@@ -32,6 +35,12 @@ func (r *Renderer) SetScale(scale float32) {
r.scale = scale
}
// SetWindowSize updates the window dimensions in physical pixels from State.
func (r *Renderer) SetWindowSize(w, h int) {
r.windowW = w
r.windowH = h
}
// toPx converts Dp to physical pixels using the renderer's scale.
func (r *Renderer) toPx(dp Dp) Px {
return ToPx(dp, r.scale)
@@ -43,15 +52,13 @@ func (r *Renderer) toDp(px Px) Dp {
}
// Draw iterates elements and draws each in slice order (back-to-front).
// It captures the initial constraints once at the start, then passes them
// to each render function for consistent positioning.
// The scale is set externally via SetScale() from State.Scale.
// Window constraints come from State (set via SetWindowSize), not from gtx.
// Scale comes from State (set via SetScale), not from gtx.Metric.PxPerDp.
func (r *Renderer) Draw(gtx layout.Context, elems []Element) {
// Capture initial constraints once — before any clips modify them.
// These are in physical pixels and serve as the window bounds for all positioning.
// Use window dimensions from State — never from gtx.Constraints
initialConstraints := WindowConstraints{
Min: gtx.Constraints.Min,
Max: gtx.Constraints.Max,
Min: image.Point{X: 0, Y: 0},
Max: image.Point{X: r.windowW, Y: r.windowH},
}
for _, e := range elems {