mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 09:55:40 +00:00
app,io/pointer: [API] remove CursorNameOp and rename CursorName -> Cursor
It's now possible to directly user pointer.Cursor to add to the ops. pointer.CursorText.Add(gtx.Ops) This is an API change. Use pointer.Cursor directly instead of CursorNameOp. Signed-off-by: Egon Elbre <egonelbre@gmail.com>
This commit is contained in:
+7
-11
@@ -54,11 +54,6 @@ type PassStack struct {
|
||||
macroID int
|
||||
}
|
||||
|
||||
// CursorNameOp sets the cursor for the current area.
|
||||
type CursorNameOp struct {
|
||||
Name CursorName
|
||||
}
|
||||
|
||||
// InputOp declares an input handler ready for pointer
|
||||
// events.
|
||||
type InputOp struct {
|
||||
@@ -90,13 +85,14 @@ type Source uint8
|
||||
// Buttons is a set of mouse buttons
|
||||
type Buttons uint8
|
||||
|
||||
// CursorName is the name of a cursor.
|
||||
type CursorName byte
|
||||
// Cursor denotes a pre-defined cursor shape. Its Add method adds an
|
||||
// operation that sets the cursor shape for the current clip area.
|
||||
type Cursor byte
|
||||
|
||||
// The cursors correspond to CSS pointer naming.
|
||||
const (
|
||||
// CursorDefault is the default cursor.
|
||||
CursorDefault CursorName = iota
|
||||
CursorDefault Cursor = iota
|
||||
// CursorNone hides the cursor. To show it again, use any other cursor.
|
||||
CursorNone
|
||||
// CursorText is for selecting and inserting text.
|
||||
@@ -247,10 +243,10 @@ func (p PassStack) Pop() {
|
||||
data[0] = byte(ops.TypePopPass)
|
||||
}
|
||||
|
||||
func (op CursorNameOp) Add(o *op.Ops) {
|
||||
func (op Cursor) Add(o *op.Ops) {
|
||||
data := ops.Write(&o.Internal, ops.TypeCursorLen)
|
||||
data[0] = byte(ops.TypeCursor)
|
||||
data[1] = byte(op.Name)
|
||||
data[1] = byte(op)
|
||||
}
|
||||
|
||||
// Add panics if the scroll range does not contain zero.
|
||||
@@ -360,7 +356,7 @@ func (b Buttons) String() string {
|
||||
return strings.Join(strs, "|")
|
||||
}
|
||||
|
||||
func (c CursorName) String() string {
|
||||
func (c Cursor) String() string {
|
||||
switch c {
|
||||
case CursorDefault:
|
||||
return "Default"
|
||||
|
||||
@@ -18,7 +18,7 @@ type pointerQueue struct {
|
||||
hitTree []hitNode
|
||||
areas []areaNode
|
||||
cursors []cursorNode
|
||||
cursor pointer.CursorName
|
||||
cursor pointer.Cursor
|
||||
handlers map[event.Tag]*pointerHandler
|
||||
pointers []pointerInfo
|
||||
transfers []io.ReadCloser // pending data transfers
|
||||
@@ -45,8 +45,8 @@ type hitNode struct {
|
||||
}
|
||||
|
||||
type cursorNode struct {
|
||||
name pointer.CursorName
|
||||
area int
|
||||
cursor pointer.Cursor
|
||||
area int
|
||||
}
|
||||
|
||||
type pointerInfo struct {
|
||||
@@ -306,10 +306,10 @@ func (c *pointerCollector) semanticDisabled(disabled bool) {
|
||||
area.semantic.content.disabled = disabled
|
||||
}
|
||||
|
||||
func (c *pointerCollector) cursor(name pointer.CursorName) {
|
||||
func (c *pointerCollector) cursor(cursor pointer.Cursor) {
|
||||
c.q.cursors = append(c.q.cursors, cursorNode{
|
||||
name: name,
|
||||
area: len(c.q.areas) - 1,
|
||||
cursor: cursor,
|
||||
area: len(c.q.areas) - 1,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -725,7 +725,7 @@ func (q *pointerQueue) deliverEnterLeaveEvents(p *pointerInfo, events *handlerEv
|
||||
h := q.handlers[k]
|
||||
for i := len(q.cursors) - 1; i >= 0; i-- {
|
||||
if c := q.cursors[i]; c.area == h.area {
|
||||
q.cursor = c.name
|
||||
q.cursor = c.cursor
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
@@ -572,7 +572,7 @@ func TestMultitouch(t *testing.T) {
|
||||
assertEventPointerTypeSequence(t, r.Events(h2), pointer.Cancel, pointer.Enter, pointer.Press, pointer.Release)
|
||||
}
|
||||
|
||||
func TestCursorNameOp(t *testing.T) {
|
||||
func TestCursor(t *testing.T) {
|
||||
ops := new(op.Ops)
|
||||
var r Router
|
||||
var h, h2 int
|
||||
@@ -582,7 +582,7 @@ func TestCursorNameOp(t *testing.T) {
|
||||
defer clip.Rect(image.Rectangle{Max: image.Pt(100, 100)}).Push(ops).Pop()
|
||||
// The cursor is checked and changed upon cursor movement.
|
||||
pointer.InputOp{Tag: &h}.Add(ops)
|
||||
pointer.CursorNameOp{Name: pointer.CursorPointer}.Add(ops)
|
||||
pointer.CursorPointer.Add(ops)
|
||||
if widget2 != nil {
|
||||
widget2()
|
||||
}
|
||||
@@ -605,7 +605,7 @@ func TestCursorNameOp(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
label string
|
||||
event interface{}
|
||||
want pointer.CursorName
|
||||
want pointer.Cursor
|
||||
}{
|
||||
{label: "move inside",
|
||||
event: _at(50, 50),
|
||||
@@ -638,7 +638,7 @@ func TestCursorNameOp(t *testing.T) {
|
||||
event: func() []event.Event {
|
||||
widget2 = func() {
|
||||
pointer.InputOp{Tag: &h2}.Add(ops)
|
||||
pointer.CursorNameOp{Name: pointer.CursorCrosshair}.Add(ops)
|
||||
pointer.CursorCrosshair.Add(ops)
|
||||
}
|
||||
return []event.Event{
|
||||
_at(50, 50),
|
||||
|
||||
+2
-2
@@ -193,7 +193,7 @@ func (q *Router) ReadClipboard() bool {
|
||||
}
|
||||
|
||||
// Cursor returns the last cursor set.
|
||||
func (q *Router) Cursor() pointer.CursorName {
|
||||
func (q *Router) Cursor() pointer.Cursor {
|
||||
return q.pointer.queue.cursor
|
||||
}
|
||||
|
||||
@@ -298,7 +298,7 @@ func (q *Router) collect() {
|
||||
}
|
||||
pc.inputOp(op, &q.handlers)
|
||||
case ops.TypeCursor:
|
||||
name := pointer.CursorName(encOp.Data[1])
|
||||
name := pointer.Cursor(encOp.Data[1])
|
||||
pc.cursor(name)
|
||||
case ops.TypeSource:
|
||||
op := transfer.SourceOp{
|
||||
|
||||
@@ -49,10 +49,10 @@ const (
|
||||
ActionResizeSouthEast
|
||||
)
|
||||
|
||||
// CursorName returns the cursor for the action.
|
||||
// Cursor returns the cursor for the action.
|
||||
// It must be a single action otherwise the default
|
||||
// cursor is returned.
|
||||
func (a Action) CursorName() pointer.CursorName {
|
||||
func (a Action) Cursor() pointer.Cursor {
|
||||
switch a {
|
||||
case ActionResizeNorthWest:
|
||||
return pointer.CursorNorthWestResize
|
||||
|
||||
Reference in New Issue
Block a user