mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 18:05:35 +00:00
ui: change area ops to use rectangles, not sizes
And then use the more general rectangles to add a buffer around text.Editor click and scroll area. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -47,7 +47,7 @@ type pointerHandler struct {
|
|||||||
|
|
||||||
type areaOp struct {
|
type areaOp struct {
|
||||||
kind areaKind
|
kind areaKind
|
||||||
size image.Point
|
rect image.Rectangle
|
||||||
}
|
}
|
||||||
|
|
||||||
type areaNode struct {
|
type areaNode struct {
|
||||||
@@ -268,28 +268,40 @@ func (op *areaOp) Decode(d []byte) {
|
|||||||
panic("invalid op")
|
panic("invalid op")
|
||||||
}
|
}
|
||||||
bo := binary.LittleEndian
|
bo := binary.LittleEndian
|
||||||
size := image.Point{
|
rect := image.Rectangle{
|
||||||
X: int(bo.Uint32(d[2:])),
|
Min: image.Point{
|
||||||
Y: int(bo.Uint32(d[6:])),
|
X: int(int32(bo.Uint32(d[2:]))),
|
||||||
|
Y: int(int32(bo.Uint32(d[6:]))),
|
||||||
|
},
|
||||||
|
Max: image.Point{
|
||||||
|
X: int(int32(bo.Uint32(d[10:]))),
|
||||||
|
Y: int(int32(bo.Uint32(d[14:]))),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
*op = areaOp{
|
*op = areaOp{
|
||||||
kind: areaKind(d[1]),
|
kind: areaKind(d[1]),
|
||||||
size: size,
|
rect: rect,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (op *areaOp) Hit(pos f32.Point) bool {
|
func (op *areaOp) Hit(pos f32.Point) bool {
|
||||||
|
min := f32.Point{
|
||||||
|
X: float32(op.rect.Min.X),
|
||||||
|
Y: float32(op.rect.Min.Y),
|
||||||
|
}
|
||||||
|
pos = pos.Sub(min)
|
||||||
|
size := op.rect.Size()
|
||||||
switch op.kind {
|
switch op.kind {
|
||||||
case areaRect:
|
case areaRect:
|
||||||
if 0 <= pos.X && pos.X < float32(op.size.X) &&
|
if 0 <= pos.X && pos.X < float32(size.X) &&
|
||||||
0 <= pos.Y && pos.Y < float32(op.size.Y) {
|
0 <= pos.Y && pos.Y < float32(size.Y) {
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
case areaEllipse:
|
case areaEllipse:
|
||||||
rx := float32(op.size.X) / 2
|
rx := float32(size.X) / 2
|
||||||
ry := float32(op.size.Y) / 2
|
ry := float32(size.Y) / 2
|
||||||
rx2 := rx * rx
|
rx2 := rx * rx
|
||||||
ry2 := ry * ry
|
ry2 := ry * ry
|
||||||
xh := pos.X - rx
|
xh := pos.X - rx
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ const (
|
|||||||
TypeImageLen = 1 + 4*4
|
TypeImageLen = 1 + 4*4
|
||||||
TypeDrawLen = 1 + 4*4
|
TypeDrawLen = 1 + 4*4
|
||||||
TypeColorLen = 1 + 4
|
TypeColorLen = 1 + 4
|
||||||
TypeAreaLen = 1 + 1 + 2*4
|
TypeAreaLen = 1 + 1 + 4*4
|
||||||
TypePointerHandlerLen = 1 + 1
|
TypePointerHandlerLen = 1 + 1
|
||||||
TypePassLen = 1 + 1
|
TypePassLen = 1 + 1
|
||||||
TypeKeyHandlerLen = 1 + 1
|
TypeKeyHandlerLen = 1 + 1
|
||||||
|
|||||||
+1
-1
@@ -243,7 +243,7 @@ func (l *List) Layout() Dimens {
|
|||||||
}
|
}
|
||||||
dims := axisPoint(l.Axis, mainc.Constrain(pos), maxCross)
|
dims := axisPoint(l.Axis, mainc.Constrain(pos), maxCross)
|
||||||
l.macro.Stop()
|
l.macro.Stop()
|
||||||
pointer.RectAreaOp{Size: dims}.Add(ops)
|
pointer.RectAreaOp{Rect: image.Rectangle{Max: dims}}.Add(ops)
|
||||||
l.scroll.Add(ops)
|
l.scroll.Add(ops)
|
||||||
l.macro.Add(ops)
|
l.macro.Add(ops)
|
||||||
return Dimens{Size: dims}
|
return Dimens{Size: dims}
|
||||||
|
|||||||
@@ -25,17 +25,17 @@ type Event struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type RectAreaOp struct {
|
type RectAreaOp struct {
|
||||||
Size image.Point
|
Rect image.Rectangle
|
||||||
}
|
}
|
||||||
|
|
||||||
type EllipseAreaOp struct {
|
type EllipseAreaOp struct {
|
||||||
Size image.Point
|
Rect image.Rectangle
|
||||||
}
|
}
|
||||||
|
|
||||||
// Must match the structure in input.areaOp
|
// Must match the structure in input.areaOp
|
||||||
type areaOp struct {
|
type areaOp struct {
|
||||||
kind areaKind
|
kind areaKind
|
||||||
size image.Point
|
rect image.Rectangle
|
||||||
}
|
}
|
||||||
|
|
||||||
type HandlerOp struct {
|
type HandlerOp struct {
|
||||||
@@ -83,14 +83,14 @@ const (
|
|||||||
func (op RectAreaOp) Add(ops *ui.Ops) {
|
func (op RectAreaOp) Add(ops *ui.Ops) {
|
||||||
areaOp{
|
areaOp{
|
||||||
kind: areaRect,
|
kind: areaRect,
|
||||||
size: op.Size,
|
rect: op.Rect,
|
||||||
}.add(ops)
|
}.add(ops)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (op EllipseAreaOp) Add(ops *ui.Ops) {
|
func (op EllipseAreaOp) Add(ops *ui.Ops) {
|
||||||
areaOp{
|
areaOp{
|
||||||
kind: areaEllipse,
|
kind: areaEllipse,
|
||||||
size: op.Size,
|
rect: op.Rect,
|
||||||
}.add(ops)
|
}.add(ops)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,8 +99,10 @@ func (op areaOp) add(o *ui.Ops) {
|
|||||||
data[0] = byte(ops.TypeArea)
|
data[0] = byte(ops.TypeArea)
|
||||||
data[1] = byte(op.kind)
|
data[1] = byte(op.kind)
|
||||||
bo := binary.LittleEndian
|
bo := binary.LittleEndian
|
||||||
bo.PutUint32(data[2:], uint32(op.size.X))
|
bo.PutUint32(data[2:], uint32(op.rect.Min.X))
|
||||||
bo.PutUint32(data[6:], uint32(op.size.Y))
|
bo.PutUint32(data[6:], uint32(op.rect.Min.Y))
|
||||||
|
bo.PutUint32(data[10:], uint32(op.rect.Max.X))
|
||||||
|
bo.PutUint32(data[14:], uint32(op.rect.Max.Y))
|
||||||
o.Write(data)
|
o.Write(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-1
@@ -248,7 +248,13 @@ func (e *Editor) Layout(cfg ui.Config, queue input.Queue, ops *ui.Ops, cs layout
|
|||||||
stack.Pop()
|
stack.Pop()
|
||||||
|
|
||||||
baseline := e.padTop + e.dims.Baseline
|
baseline := e.padTop + e.dims.Baseline
|
||||||
pointer.RectAreaOp{Size: e.viewSize}.Add(ops)
|
pointerPadding := cfg.Px(ui.Dp(4))
|
||||||
|
r := image.Rectangle{Max: e.viewSize}
|
||||||
|
r.Min.X -= pointerPadding
|
||||||
|
r.Min.Y -= pointerPadding
|
||||||
|
r.Max.X += pointerPadding
|
||||||
|
r.Max.X += pointerPadding
|
||||||
|
pointer.RectAreaOp{Rect: r}.Add(ops)
|
||||||
e.scroller.Add(ops)
|
e.scroller.Add(ops)
|
||||||
e.clicker.Add(ops)
|
e.clicker.Add(ops)
|
||||||
return layout.Dimens{Size: e.viewSize, Baseline: baseline}
|
return layout.Dimens{Size: e.viewSize, Baseline: baseline}
|
||||||
|
|||||||
Reference in New Issue
Block a user