mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 18:05:35 +00:00
io/pointer: unify area ops into a single AreaOp
Make Rect and Ellipse constructors of AreaOp. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+1
-1
@@ -19,7 +19,7 @@ For example, to set up a rectangular hit area:
|
|||||||
var h *Handler = ...
|
var h *Handler = ...
|
||||||
|
|
||||||
r := image.Rectangle{...}
|
r := image.Rectangle{...}
|
||||||
pointer.RectAreaOp{Rect: r}.Add(ops)
|
pointer.Rect().Add(ops)
|
||||||
pointer.InputOp{Key: h}.Add(ops)
|
pointer.InputOp{Key: h}.Add(ops)
|
||||||
|
|
||||||
Note that areas compound: the effective area of multiple area
|
Note that areas compound: the effective area of multiple area
|
||||||
|
|||||||
+15
-27
@@ -42,24 +42,10 @@ type Event struct {
|
|||||||
Scroll f32.Point
|
Scroll f32.Point
|
||||||
}
|
}
|
||||||
|
|
||||||
// RectAreaOp updates the hit area to the intersection
|
// AreaOp updates the hit area to the intersection of the current
|
||||||
// of the current hit area with a rectangular area.
|
// hit area and the area. The area is transformed before applying
|
||||||
type RectAreaOp struct {
|
// it.
|
||||||
// Rect defines the rectangle. The current transform
|
type AreaOp struct {
|
||||||
// is applied to it.
|
|
||||||
Rect image.Rectangle
|
|
||||||
}
|
|
||||||
|
|
||||||
// EllipseAreaOp updates the hit area to the intersection
|
|
||||||
// of the current hit area with an elliptical area.
|
|
||||||
type EllipseAreaOp struct {
|
|
||||||
// Rect is the bounds for the ellipse. The current transform
|
|
||||||
// is applied to the rectangle.
|
|
||||||
Rect image.Rectangle
|
|
||||||
}
|
|
||||||
|
|
||||||
// Must match the structure in input.areaOp
|
|
||||||
type areaOp struct {
|
|
||||||
kind areaKind
|
kind areaKind
|
||||||
rect image.Rectangle
|
rect image.Rectangle
|
||||||
}
|
}
|
||||||
@@ -133,21 +119,23 @@ const (
|
|||||||
areaEllipse
|
areaEllipse
|
||||||
)
|
)
|
||||||
|
|
||||||
func (op RectAreaOp) Add(ops *op.Ops) {
|
// Rect constructs a rectangular hit area.
|
||||||
areaOp{
|
func Rect(size image.Rectangle) AreaOp {
|
||||||
|
return AreaOp{
|
||||||
kind: areaRect,
|
kind: areaRect,
|
||||||
rect: op.Rect,
|
rect: size,
|
||||||
}.add(ops)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (op EllipseAreaOp) Add(ops *op.Ops) {
|
// Ellipse constructs an ellipsoid hit area.
|
||||||
areaOp{
|
func Ellipse(size image.Rectangle) AreaOp {
|
||||||
|
return AreaOp{
|
||||||
kind: areaEllipse,
|
kind: areaEllipse,
|
||||||
rect: op.Rect,
|
rect: size,
|
||||||
}.add(ops)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (op areaOp) add(o *op.Ops) {
|
func (op AreaOp) Add(o *op.Ops) {
|
||||||
data := o.Write(opconst.TypeAreaLen)
|
data := o.Write(opconst.TypeAreaLen)
|
||||||
data[0] = byte(opconst.TypeArea)
|
data[0] = byte(opconst.TypeArea)
|
||||||
data[1] = byte(op.kind)
|
data[1] = byte(op.kind)
|
||||||
|
|||||||
+1
-1
@@ -263,7 +263,7 @@ func (l *List) layout() Dimensions {
|
|||||||
l.beforeEnd = !atEnd
|
l.beforeEnd = !atEnd
|
||||||
dims := axisPoint(l.Axis, mainc.Constrain(pos), maxCross)
|
dims := axisPoint(l.Axis, mainc.Constrain(pos), maxCross)
|
||||||
l.macro.Stop()
|
l.macro.Stop()
|
||||||
pointer.RectAreaOp{Rect: image.Rectangle{Max: dims}}.Add(ops)
|
pointer.Rect(image.Rectangle{Max: dims}).Add(ops)
|
||||||
l.scroll.Add(ops)
|
l.scroll.Add(ops)
|
||||||
l.macro.Add(ops)
|
l.macro.Add(ops)
|
||||||
return Dimensions{Size: dims}
|
return Dimensions{Size: dims}
|
||||||
|
|||||||
+1
-1
@@ -258,7 +258,7 @@ func (e *Editor) layout(gtx *layout.Context, sh *text.Shaper) {
|
|||||||
r.Min.Y -= pointerPadding
|
r.Min.Y -= pointerPadding
|
||||||
r.Max.X += pointerPadding
|
r.Max.X += pointerPadding
|
||||||
r.Max.X += pointerPadding
|
r.Max.X += pointerPadding
|
||||||
pointer.RectAreaOp{Rect: r}.Add(gtx.Ops)
|
pointer.Rect(r).Add(gtx.Ops)
|
||||||
e.scroller.Add(gtx.Ops)
|
e.scroller.Add(gtx.Ops)
|
||||||
e.clicker.Add(gtx.Ops)
|
e.clicker.Add(gtx.Ops)
|
||||||
e.caretOn = false
|
e.caretOn = false
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ func (b Button) Layout(gtx *layout.Context, button *widget.Button) {
|
|||||||
widget.Label{}.Layout(gtx, b.shaper, b.Font, b.Text)
|
widget.Label{}.Layout(gtx, b.shaper, b.Font, b.Text)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
pointer.RectAreaOp{Rect: image.Rectangle{Max: gtx.Dimensions.Size}}.Add(gtx.Ops)
|
pointer.Rect(image.Rectangle{Max: gtx.Dimensions.Size}).Add(gtx.Ops)
|
||||||
button.Layout(gtx)
|
button.Layout(gtx)
|
||||||
})
|
})
|
||||||
bg := st.Expand(gtx, func() {
|
bg := st.Expand(gtx, func() {
|
||||||
@@ -105,7 +105,7 @@ func (b IconButton) Layout(gtx *layout.Context, button *widget.Button) {
|
|||||||
Size: image.Point{X: size, Y: size},
|
Size: image.Point{X: size, Y: size},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
pointer.EllipseAreaOp{Rect: image.Rectangle{Max: gtx.Dimensions.Size}}.Add(gtx.Ops)
|
pointer.Ellipse(image.Rectangle{Max: gtx.Dimensions.Size}).Add(gtx.Ops)
|
||||||
button.Layout(gtx)
|
button.Layout(gtx)
|
||||||
})
|
})
|
||||||
bgcol := b.Background
|
bgcol := b.Background
|
||||||
|
|||||||
@@ -63,5 +63,5 @@ func (c *checkable) layout(gtx *layout.Context, checked bool) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
flex.Layout(gtx, ico, lbl)
|
flex.Layout(gtx, ico, lbl)
|
||||||
pointer.RectAreaOp{Rect: image.Rectangle{Max: gtx.Dimensions.Size}}.Add(gtx.Ops)
|
pointer.Rect(image.Rectangle{Max: gtx.Dimensions.Size}).Add(gtx.Ops)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user