forked from joejulian/gio
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 {
|
||||
kind areaKind
|
||||
size image.Point
|
||||
rect image.Rectangle
|
||||
}
|
||||
|
||||
type areaNode struct {
|
||||
@@ -268,28 +268,40 @@ func (op *areaOp) Decode(d []byte) {
|
||||
panic("invalid op")
|
||||
}
|
||||
bo := binary.LittleEndian
|
||||
size := image.Point{
|
||||
X: int(bo.Uint32(d[2:])),
|
||||
Y: int(bo.Uint32(d[6:])),
|
||||
rect := image.Rectangle{
|
||||
Min: image.Point{
|
||||
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{
|
||||
kind: areaKind(d[1]),
|
||||
size: size,
|
||||
rect: rect,
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
case areaRect:
|
||||
if 0 <= pos.X && pos.X < float32(op.size.X) &&
|
||||
0 <= pos.Y && pos.Y < float32(op.size.Y) {
|
||||
if 0 <= pos.X && pos.X < float32(size.X) &&
|
||||
0 <= pos.Y && pos.Y < float32(size.Y) {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
case areaEllipse:
|
||||
rx := float32(op.size.X) / 2
|
||||
ry := float32(op.size.Y) / 2
|
||||
rx := float32(size.X) / 2
|
||||
ry := float32(size.Y) / 2
|
||||
rx2 := rx * rx
|
||||
ry2 := ry * ry
|
||||
xh := pos.X - rx
|
||||
|
||||
@@ -35,7 +35,7 @@ const (
|
||||
TypeImageLen = 1 + 4*4
|
||||
TypeDrawLen = 1 + 4*4
|
||||
TypeColorLen = 1 + 4
|
||||
TypeAreaLen = 1 + 1 + 2*4
|
||||
TypeAreaLen = 1 + 1 + 4*4
|
||||
TypePointerHandlerLen = 1 + 1
|
||||
TypePassLen = 1 + 1
|
||||
TypeKeyHandlerLen = 1 + 1
|
||||
|
||||
+1
-1
@@ -243,7 +243,7 @@ func (l *List) Layout() Dimens {
|
||||
}
|
||||
dims := axisPoint(l.Axis, mainc.Constrain(pos), maxCross)
|
||||
l.macro.Stop()
|
||||
pointer.RectAreaOp{Size: dims}.Add(ops)
|
||||
pointer.RectAreaOp{Rect: image.Rectangle{Max: dims}}.Add(ops)
|
||||
l.scroll.Add(ops)
|
||||
l.macro.Add(ops)
|
||||
return Dimens{Size: dims}
|
||||
|
||||
@@ -25,17 +25,17 @@ type Event struct {
|
||||
}
|
||||
|
||||
type RectAreaOp struct {
|
||||
Size image.Point
|
||||
Rect image.Rectangle
|
||||
}
|
||||
|
||||
type EllipseAreaOp struct {
|
||||
Size image.Point
|
||||
Rect image.Rectangle
|
||||
}
|
||||
|
||||
// Must match the structure in input.areaOp
|
||||
type areaOp struct {
|
||||
kind areaKind
|
||||
size image.Point
|
||||
rect image.Rectangle
|
||||
}
|
||||
|
||||
type HandlerOp struct {
|
||||
@@ -83,14 +83,14 @@ const (
|
||||
func (op RectAreaOp) Add(ops *ui.Ops) {
|
||||
areaOp{
|
||||
kind: areaRect,
|
||||
size: op.Size,
|
||||
rect: op.Rect,
|
||||
}.add(ops)
|
||||
}
|
||||
|
||||
func (op EllipseAreaOp) Add(ops *ui.Ops) {
|
||||
areaOp{
|
||||
kind: areaEllipse,
|
||||
size: op.Size,
|
||||
rect: op.Rect,
|
||||
}.add(ops)
|
||||
}
|
||||
|
||||
@@ -99,8 +99,10 @@ func (op areaOp) add(o *ui.Ops) {
|
||||
data[0] = byte(ops.TypeArea)
|
||||
data[1] = byte(op.kind)
|
||||
bo := binary.LittleEndian
|
||||
bo.PutUint32(data[2:], uint32(op.size.X))
|
||||
bo.PutUint32(data[6:], uint32(op.size.Y))
|
||||
bo.PutUint32(data[2:], uint32(op.rect.Min.X))
|
||||
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)
|
||||
}
|
||||
|
||||
|
||||
+7
-1
@@ -248,7 +248,13 @@ func (e *Editor) Layout(cfg ui.Config, queue input.Queue, ops *ui.Ops, cs layout
|
||||
stack.Pop()
|
||||
|
||||
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.clicker.Add(ops)
|
||||
return layout.Dimens{Size: e.viewSize, Baseline: baseline}
|
||||
|
||||
Reference in New Issue
Block a user