Document background drawing with clips — use push/pop, not op.Record macro
This commit is contained in:
parent
f433a992b7
commit
3fc28fd54b
|
|
@ -627,6 +627,33 @@ func (r *Renderer) drawBottomBar(gtx layout.Context, bb BottomBar, constraints W
|
|||
- **Don't mix Dp and Px**: The compiler will catch it. Use explicit conversions.
|
||||
- **Don't pass pixels as Dp to EditorLayout**: `main.go` must convert `app.ConfigEvent` pixels to Dp before passing to the logic layer.
|
||||
|
||||
## 9.6 Background Drawing with Clips
|
||||
|
||||
When drawing backgrounds (rectangles with solid colors), use `clip.Rect{...}.Push(gtx.Ops)` followed immediately by `clip.Pop()`. **Never use `op.Record`/`m.Stop()` macros for simple background clips** — the macro leaves the clip on the stack, preventing subsequent elements from drawing.
|
||||
|
||||
**Correct pattern**:
|
||||
```go
|
||||
bgClip := clip.Rect{
|
||||
Min: image.Point{X: pxMinX, Y: pxMinY},
|
||||
Max: image.Point{X: pxMaxX, Y: pxMaxY},
|
||||
}.Push(gtx.Ops)
|
||||
paint.ColorOp{Color: bgColor}.Add(gtx.Ops)
|
||||
paint.PaintOp{}.Add(gtx.Ops)
|
||||
bgClip.Pop() // Immediately pop — clip stack must be clean
|
||||
```
|
||||
|
||||
**Wrong pattern** (leaves clip on stack):
|
||||
```go
|
||||
m := op.Record(gtx.Ops)
|
||||
clip.Rect{...}.Op().Push(gtx.Ops) // Push inside macro
|
||||
paint.ColorOp{...}.Add(gtx.Ops)
|
||||
paint.PaintOp{}.Add(gtx.Ops)
|
||||
call := m.Stop()
|
||||
call.Add(gtx.Ops) // When replayed, clip is pushed but never popped!
|
||||
```
|
||||
|
||||
**Why this matters**: When the StatusBar draws its background with a macro, the clip inside is pushed during macro replay but never popped. The BottomBar then draws while that stale clip is still active, causing it to be clipped out of visibility.
|
||||
|
||||
## 10. Summary
|
||||
|
||||
- **Always** use `fixed.I(gtx.Sp(size))` for `PxPerEm`
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user