mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-04 17:05:38 +00:00
op/clip: replace Rect and RoundRect with Rect type
Remembering the order of the corners in the RoundRect is difficult, which suggest that RoundRect should be a struct with named fields. Do that, and make Rect the special case where corner radii are all zero. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+15
-12
@@ -77,13 +77,13 @@ func (b Button) Layout(gtx *layout.Context, button *widget.Button) {
|
||||
})
|
||||
bg := st.Expand(gtx, func() {
|
||||
rr := float32(gtx.Px(unit.Dp(4)))
|
||||
clip.RoundRect(gtx.Ops,
|
||||
f32.Rectangle{Max: f32.Point{
|
||||
clip.Rect{
|
||||
Rect: f32.Rectangle{Max: f32.Point{
|
||||
X: float32(gtx.Constraints.Width.Min),
|
||||
Y: float32(gtx.Constraints.Height.Min),
|
||||
}},
|
||||
rr, rr, rr, rr,
|
||||
).Add(gtx.Ops)
|
||||
NE: rr, NW: rr, SE: rr, SW: rr,
|
||||
}.Op(gtx.Ops).Add(gtx.Ops)
|
||||
fill(gtx, bgcol)
|
||||
for _, c := range button.History() {
|
||||
drawInk(gtx, c)
|
||||
@@ -112,10 +112,10 @@ func (b IconButton) Layout(gtx *layout.Context, button *widget.Button) {
|
||||
bg := st.Expand(gtx, func() {
|
||||
size := float32(gtx.Constraints.Width.Min)
|
||||
rr := float32(size) * .5
|
||||
clip.RoundRect(gtx.Ops,
|
||||
f32.Rectangle{Max: f32.Point{X: size, Y: size}},
|
||||
rr, rr, rr, rr,
|
||||
).Add(gtx.Ops)
|
||||
clip.Rect{
|
||||
Rect: f32.Rectangle{Max: f32.Point{X: size, Y: size}},
|
||||
NE: rr, NW: rr, SE: rr, SW: rr,
|
||||
}.Op(gtx.Ops).Add(gtx.Ops)
|
||||
fill(gtx, bgcol)
|
||||
for _, c := range button.History() {
|
||||
drawInk(gtx, c)
|
||||
@@ -154,10 +154,13 @@ func drawInk(gtx *layout.Context, c widget.Click) {
|
||||
X: -rr,
|
||||
Y: -rr,
|
||||
}).Add(gtx.Ops)
|
||||
clip.RoundRect(gtx.Ops, f32.Rectangle{Max: f32.Point{
|
||||
X: float32(size),
|
||||
Y: float32(size),
|
||||
}}, rr, rr, rr, rr).Add(gtx.Ops)
|
||||
clip.Rect{
|
||||
Rect: f32.Rectangle{Max: f32.Point{
|
||||
X: float32(size),
|
||||
Y: float32(size),
|
||||
}},
|
||||
NE: rr, NW: rr, SE: rr, SW: rr,
|
||||
}.Op(gtx.Ops).Add(gtx.Ops)
|
||||
paint.PaintOp{Rect: f32.Rectangle{Max: f32.Point{X: float32(size), Y: float32(size)}}}.Add(gtx.Ops)
|
||||
stack.Pop()
|
||||
op.InvalidateOp{}.Add(gtx.Ops)
|
||||
|
||||
@@ -37,7 +37,7 @@ func (im Image) Layout(gtx *layout.Context) {
|
||||
d := image.Point{X: cs.Width.Constrain(w), Y: cs.Height.Constrain(h)}
|
||||
var s op.StackOp
|
||||
s.Push(gtx.Ops)
|
||||
clip.Rect(gtx.Ops, f32.Rectangle{Max: toPointF(d)}).Add(gtx.Ops)
|
||||
clip.Rect{Rect: f32.Rectangle{Max: toPointF(d)}}.Op(gtx.Ops).Add(gtx.Ops)
|
||||
im.Src.Add(gtx.Ops)
|
||||
paint.PaintOp{Rect: f32.Rectangle{Max: f32.Point{X: float32(w), Y: float32(h)}}}.Add(gtx.Ops)
|
||||
s.Pop()
|
||||
|
||||
Reference in New Issue
Block a user