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:
@@ -19,7 +19,7 @@ import (
|
||||
type Renderer struct {
|
||||
theme Theme
|
||||
shp *text.Shaper
|
||||
scale float32 // pixels per DP, from gtx.Metric.PxPerDp
|
||||
scale float32 // pixels per DP, from State.Scale
|
||||
}
|
||||
|
||||
// New creates a new Renderer.
|
||||
@@ -27,9 +27,9 @@ func New(th Theme, shp *text.Shaper) *Renderer {
|
||||
return &Renderer{theme: th, shp: shp, scale: 1.0}
|
||||
}
|
||||
|
||||
// setScale updates the renderer's scale factor from a layout.Context.
|
||||
func (r *Renderer) setScale(gtx layout.Context) {
|
||||
r.scale = gtx.Metric.PxPerDp
|
||||
// SetScale updates the renderer's scale factor from State.Scale.
|
||||
func (r *Renderer) SetScale(scale float32) {
|
||||
r.scale = scale
|
||||
}
|
||||
|
||||
// toPx converts Dp to physical pixels using the renderer's scale.
|
||||
@@ -45,10 +45,8 @@ 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.
|
||||
func (r *Renderer) Draw(gtx layout.Context, elems []Element) {
|
||||
// Update scale from the frame context
|
||||
r.setScale(gtx)
|
||||
|
||||
// Capture initial constraints once — before any clips modify them.
|
||||
// These are in physical pixels and serve as the window bounds for all positioning.
|
||||
initialConstraints := WindowConstraints{
|
||||
|
||||
Reference in New Issue
Block a user