io/pointer: [API] make cursor name into a byte

Add most of the common cursors defined by different systems.

Normalize cursor names to match CSS.

This is API change: some cursor names have changed, and the
underlying type is no longer a string.

Signed-off-by: Egon Elbre <egonelbre@gmail.com>
This commit is contained in:
Egon Elbre
2022-02-25 16:08:09 +02:00
committed by Elias Naur
parent a401d7aaff
commit 4172566aad
14 changed files with 356 additions and 197 deletions
+30 -19
View File
@@ -1350,26 +1350,37 @@ func (w *window) Wakeup() {
})
}
var androidCursor = [...]uint16{
pointer.CursorDefault: 1000, // TYPE_ARROW
pointer.CursorNone: 0,
pointer.CursorText: 1008, // TYPE_TEXT
pointer.CursorVerticalText: 1009, // TYPE_VERTICAL_TEXT
pointer.CursorPointer: 1002, // TYPE_HAND
pointer.CursorCrosshair: 1007, // TYPE_CROSSHAIR
pointer.CursorAllScroll: 1013, // TYPE_ALL_SCROLL
pointer.CursorColResize: 1014, // TYPE_HORIZONTAL_DOUBLE_ARROW
pointer.CursorRowResize: 1015, // TYPE_VERTICAL_DOUBLE_ARROW
pointer.CursorGrab: 1020, // TYPE_GRAB
pointer.CursorGrabbing: 1021, // TYPE_GRABBING
pointer.CursorNotAllowed: 1012, // TYPE_NO_DROP
pointer.CursorWait: 1004, // TYPE_WAIT
pointer.CursorProgress: 1000, // TYPE_ARROW
pointer.CursorNorthWestResize: 1017, // TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARROW
pointer.CursorNorthEastResize: 1016, // TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_ARROW
pointer.CursorSouthWestResize: 1016, // TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_ARROW
pointer.CursorSouthEastResize: 1017, // TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARROW
pointer.CursorNorthSouthResize: 1015, // TYPE_VERTICAL_DOUBLE_ARROW
pointer.CursorEastWestResize: 1014, // TYPE_HORIZONTAL_DOUBLE_ARROW
pointer.CursorWestResize: 1014, // TYPE_HORIZONTAL_DOUBLE_ARROW
pointer.CursorEastResize: 1014, // TYPE_HORIZONTAL_DOUBLE_ARROW
pointer.CursorNorthResize: 1015, // TYPE_VERTICAL_DOUBLE_ARROW
pointer.CursorSouthResize: 1015, // TYPE_VERTICAL_DOUBLE_ARROW
pointer.CursorNorthEastSouthWestResize: 1016, // TYPE_TOP_RIGHT_DIAGONAL_DOUBLE_ARROW
pointer.CursorNorthWestSouthEastResize: 1017, // TYPE_TOP_LEFT_DIAGONAL_DOUBLE_ARROW
}
func setCursor(env *C.JNIEnv, view C.jobject, name pointer.CursorName) {
var curID int
switch name {
default:
fallthrough
case pointer.CursorDefault:
curID = 1000 // TYPE_ARROW
case pointer.CursorText:
curID = 1008 // TYPE_TEXT
case pointer.CursorPointer:
curID = 1002 // TYPE_HAND
case pointer.CursorCrossHair:
curID = 1007 // TYPE_CROSSHAIR
case pointer.CursorColResize:
curID = 1014 // TYPE_HORIZONTAL_DOUBLE_ARROW
case pointer.CursorRowResize:
curID = 1015 // TYPE_VERTICAL_DOUBLE_ARROW
case pointer.CursorNone:
curID = 0 // TYPE_NULL
}
curID := androidCursor[name]
callVoidMethod(env, view, gioView.setCursor, jvalue(curID))
}
+31 -38
View File
@@ -212,56 +212,49 @@ func gio_onFrameCallback(dl C.CFTypeRef) {
}
}
var macosCursorID = [...]byte{
pointer.CursorDefault: 0,
pointer.CursorNone: 1,
pointer.CursorText: 2,
pointer.CursorVerticalText: 3,
pointer.CursorPointer: 4,
pointer.CursorCrosshair: 5,
pointer.CursorAllScroll: 6,
pointer.CursorColResize: 7,
pointer.CursorRowResize: 8,
pointer.CursorGrab: 9,
pointer.CursorGrabbing: 10,
pointer.CursorNotAllowed: 11,
pointer.CursorWait: 12,
pointer.CursorProgress: 13,
pointer.CursorNorthWestResize: 14,
pointer.CursorNorthEastResize: 15,
pointer.CursorSouthWestResize: 16,
pointer.CursorSouthEastResize: 17,
pointer.CursorNorthSouthResize: 18,
pointer.CursorEastWestResize: 19,
pointer.CursorWestResize: 20,
pointer.CursorEastResize: 21,
pointer.CursorNorthResize: 22,
pointer.CursorSouthResize: 23,
pointer.CursorNorthEastSouthWestResize: 24,
pointer.CursorNorthWestSouthEastResize: 25,
}
// windowSetCursor updates the cursor from the current one to a new one
// and returns the new one.
func windowSetCursor(from, to pointer.CursorName) pointer.CursorName {
if from == to {
return to
}
var curID int
switch to {
default:
to = pointer.CursorDefault
fallthrough
case pointer.CursorDefault:
curID = 1
case pointer.CursorText:
curID = 2
case pointer.CursorPointer:
curID = 3
case pointer.CursorCrossHair:
curID = 4
case pointer.CursorColResize:
curID = 5
case pointer.CursorRowResize:
curID = 6
case pointer.CursorGrab:
curID = 7
case pointer.CursorTopLeftResize:
curID = 8
case pointer.CursorTopRightResize:
curID = 9
case pointer.CursorBottomLeftResize:
curID = 10
case pointer.CursorBottomRightResize:
curID = 11
case pointer.CursorLeftResize:
curID = 12
case pointer.CursorRightResize:
curID = 13
case pointer.CursorTopResize:
curID = 14
case pointer.CursorBottomResize:
curID = 15
case pointer.CursorNone:
if to == pointer.CursorNone {
C.gio_hideCursor()
return to
}
if from == pointer.CursorNone {
C.gio_showCursor()
}
C.gio_setCursor(C.NSUInteger(curID))
C.gio_setCursor(C.NSUInteger(macosCursorID[to]))
return to
}
+30 -1
View File
@@ -545,9 +545,38 @@ func (w *window) Perform(system.Action) {}
func (w *window) Raise() {}
var webCursor = [...]string{
pointer.CursorDefault: "default",
pointer.CursorNone: "none",
pointer.CursorText: "text",
pointer.CursorVerticalText: "vertical-text",
pointer.CursorPointer: "pointer",
pointer.CursorCrosshair: "crosshair",
pointer.CursorAllScroll: "all-scroll",
pointer.CursorColResize: "col-resize",
pointer.CursorRowResize: "row-resize",
pointer.CursorGrab: "grab",
pointer.CursorGrabbing: "grabbing",
pointer.CursorNotAllowed: "not-allowed",
pointer.CursorWait: "wait",
pointer.CursorProgress: "progress",
pointer.CursorNorthWestResize: "nw-resize",
pointer.CursorNorthEastResize: "ne-resize",
pointer.CursorSouthWestResize: "sw-resize",
pointer.CursorSouthEastResize: "se-resize",
pointer.CursorNorthSouthResize: "ns-resize",
pointer.CursorEastWestResize: "ew-resize",
pointer.CursorWestResize: "w-resize",
pointer.CursorEastResize: "e-resize",
pointer.CursorNorthResize: "n-resize",
pointer.CursorSouthResize: "s-resize",
pointer.CursorNorthEastSouthWestResize: "nesw-resize",
pointer.CursorNorthWestSouthEastResize: "nwse-resize",
}
func (w *window) SetCursor(name pointer.CursorName) {
style := w.cnv.Get("style")
style.Set("cursor", string(name))
style.Set("cursor", webCursor[name])
}
func (w *window) Wakeup() {
+50 -15
View File
@@ -248,51 +248,86 @@ void gio_trySetPrivateCursor(SEL cursorName, NSCursor* fallback) {
void gio_setCursor(NSUInteger curID) {
@autoreleasepool {
switch (curID) {
case 1: // pointer.CursorDefault
case 0: // pointer.CursorDefault
[NSCursor.arrowCursor set];
break;
// case 1: // pointer.CursorNone
case 2: // pointer.CursorText
[NSCursor.IBeamCursor set];
break;
case 3: // pointer.CursorPointer
case 3: // pointer.CursorVerticalText
[NSCursor.IBeamCursorForVerticalLayout set];
break;
case 4: // pointer.CursorPointer
[NSCursor.pointingHandCursor set];
break;
case 4: // pointer.CursorCrossHair
case 5: // pointer.CursorCrosshair
[NSCursor.crosshairCursor set];
break;
case 5: // pointer.CursorColResize
case 6: // pointer.CursorAllScroll
// For some reason, using _moveCursor fails on Monterey.
// gio_trySetPrivateCursor(@selector(_moveCursor), NSCursor.arrowCursor);
[NSCursor.arrowCursor set];
break;
case 7: // pointer.CursorColResize
[NSCursor.resizeLeftRightCursor set];
break;
case 6: // pointer.CursorRowResize
case 8: // pointer.CursorRowResize
[NSCursor.resizeUpDownCursor set];
break;
case 7: // pointer.CursorGrab
[NSCursor.openHandCursor set];
case 9: // pointer.CursorGrab
// [NSCursor.openHandCursor set];
gio_trySetPrivateCursor(@selector(openHandCursor), NSCursor.arrowCursor);
break;
case 8: // pointer.CursorTopLeftResize
case 10: // pointer.CursorGrabbing
// [NSCursor.closedHandCursor set];
gio_trySetPrivateCursor(@selector(closedHandCursor), NSCursor.arrowCursor);
break;
case 11: // pointer.CursorNotAllowed
[NSCursor.operationNotAllowedCursor set];
break;
case 12: // pointer.CursorWait
gio_trySetPrivateCursor(@selector(busyButClickableCursor), NSCursor.arrowCursor);
break;
case 13: // pointer.CursorProgress
gio_trySetPrivateCursor(@selector(busyButClickableCursor), NSCursor.arrowCursor);
break;
case 14: // pointer.CursorNorthWestResize
gio_trySetPrivateCursor(@selector(_windowResizeNorthWestCursor), NSCursor.resizeUpDownCursor);
break;
case 9: // pointer.CursorTopRightResize
case 15: // pointer.CursorNorthEastResize
gio_trySetPrivateCursor(@selector(_windowResizeNorthEastCursor), NSCursor.resizeUpDownCursor);
break;
case 10: // pointer.CursorBottomLeftResize
case 16: // pointer.CursorSouthWestResize
gio_trySetPrivateCursor(@selector(_windowResizeSouthWestCursor), NSCursor.resizeUpDownCursor);
break;
case 11: // pointer.CursorBottomRightResize
case 17: // pointer.CursorSouthEastResize
gio_trySetPrivateCursor(@selector(_windowResizeSouthEastCursor), NSCursor.resizeUpDownCursor);
break;
case 12: // pointer.CursorLeftResize
case 18: // pointer.CursorNorthSouthResize
[NSCursor.resizeUpDownCursor set];
break;
case 19: // pointer.CursorEastWestResize
[NSCursor.resizeLeftRightCursor set];
break;
case 20: // pointer.CursorWestResize
[NSCursor.resizeLeftCursor set];
break;
case 13: // pointer.CursorRightResize
case 21: // pointer.CursorEastResize
[NSCursor.resizeRightCursor set];
break;
case 14: // pointer.CursorTopResize
case 22: // pointer.CursorNorthResize
[NSCursor.resizeUpCursor set];
break;
case 15: // pointer.CursorBottomResize
case 23: // pointer.CursorSouthResize
[NSCursor.resizeDownCursor set];
break;
case 24: // pointer.CursorNorthEastSouthWestResize
gio_trySetPrivateCursor(@selector(_windowResizeNorthEastSouthWestCursor), NSCursor.resizeUpDownCursor);
break;
case 25: // pointer.CursorNorthWestSouthEastResize
gio_trySetPrivateCursor(@selector(_windowResizeNorthWestSouthEastCursor), NSCursor.resizeUpDownCursor);
break;
default:
[NSCursor.arrowCursor set];
break;
+32
View File
@@ -8,6 +8,8 @@ package app
import (
"errors"
"unsafe"
"gioui.org/io/pointer"
)
// ViewEvent provides handles to the underlying window objects for the
@@ -66,3 +68,33 @@ func newWindow(window *callbacks, options []Option) error {
}
return errors.New("app: no window driver available")
}
// xCursor contains mapping from pointer.CursorName to XCursor.
var xCursor = [...]string{
pointer.CursorDefault: "left_ptr",
pointer.CursorNone: "",
pointer.CursorText: "xterm",
pointer.CursorVerticalText: "vertical-text",
pointer.CursorPointer: "hand2",
pointer.CursorCrosshair: "crosshair",
pointer.CursorAllScroll: "fleur",
pointer.CursorColResize: "sb_h_double_arrow",
pointer.CursorRowResize: "sb_v_double_arrow",
pointer.CursorGrab: "hand1",
pointer.CursorGrabbing: "move",
pointer.CursorNotAllowed: "crossed_circle",
pointer.CursorWait: "watch",
pointer.CursorProgress: "left_ptr_watch",
pointer.CursorNorthWestResize: "top_left_corner",
pointer.CursorNorthEastResize: "top_right_corner",
pointer.CursorSouthWestResize: "bottom_left_corner",
pointer.CursorSouthEastResize: "bottom_right_corner",
pointer.CursorNorthSouthResize: "sb_v_double_arrow",
pointer.CursorEastWestResize: "sb_h_double_arrow",
pointer.CursorWestResize: "left_side",
pointer.CursorEastResize: "right_side",
pointer.CursorNorthResize: "top_side",
pointer.CursorSouthResize: "bottom_side",
pointer.CursorNorthEastSouthWestResize: "fd_double_arrow",
pointer.CursorNorthWestSouthEastResize: "bd_double_arrow",
}
+3 -35
View File
@@ -1095,41 +1095,9 @@ func (w *window) SetCursor(name pointer.CursorName) {
C.wl_pointer_set_cursor(ptr, w.serial, nil, 0, 0)
return
}
switch name {
default:
fallthrough
case pointer.CursorDefault:
name = "left_ptr"
case pointer.CursorText:
name = "xterm"
case pointer.CursorPointer:
name = "hand1"
case pointer.CursorCrossHair:
name = "crosshair"
case pointer.CursorRowResize:
name = "top_side"
case pointer.CursorColResize:
name = "left_side"
case pointer.CursorGrab:
name = "hand1"
case pointer.CursorTopLeftResize:
name = "top_left_corner"
case pointer.CursorTopRightResize:
name = "top_right_corner"
case pointer.CursorBottomLeftResize:
name = "bottom_left_corner"
case pointer.CursorBottomRightResize:
name = "bottom_right_corner"
case pointer.CursorLeftResize:
name = "right_side"
case pointer.CursorRightResize:
name = "left_side"
case pointer.CursorTopResize:
name = "top_side"
case pointer.CursorBottomResize:
name = "bottom_side"
}
cname := C.CString(string(name))
xcursor := xCursor[name]
cname := C.CString(xcursor)
defer C.free(unsafe.Pointer(cname))
c := C.wl_cursor_theme_get_cursor(w.cursor.theme, cname)
if c == nil {
+32 -32
View File
@@ -715,45 +715,45 @@ func (w *window) SetCursor(name pointer.CursorName) {
}
}
// windowsCursor contains mapping from CursorName to an IDC.
var windowsCursor = [...]uint16{
pointer.CursorDefault: windows.IDC_ARROW,
pointer.CursorNone: 0,
pointer.CursorText: windows.IDC_IBEAM,
pointer.CursorVerticalText: windows.IDC_IBEAM,
pointer.CursorPointer: windows.IDC_HAND,
pointer.CursorCrosshair: windows.IDC_CROSS,
pointer.CursorAllScroll: windows.IDC_SIZEALL,
pointer.CursorColResize: windows.IDC_SIZEWE,
pointer.CursorRowResize: windows.IDC_SIZENS,
pointer.CursorGrab: windows.IDC_SIZEALL,
pointer.CursorGrabbing: windows.IDC_SIZEALL,
pointer.CursorNotAllowed: windows.IDC_NO,
pointer.CursorWait: windows.IDC_WAIT,
pointer.CursorProgress: windows.IDC_APPSTARTING,
pointer.CursorNorthWestResize: windows.IDC_SIZENWSE,
pointer.CursorNorthEastResize: windows.IDC_SIZENESW,
pointer.CursorSouthWestResize: windows.IDC_SIZENESW,
pointer.CursorSouthEastResize: windows.IDC_SIZENWSE,
pointer.CursorNorthSouthResize: windows.IDC_SIZENS,
pointer.CursorEastWestResize: windows.IDC_SIZEWE,
pointer.CursorWestResize: windows.IDC_SIZEWE,
pointer.CursorEastResize: windows.IDC_SIZEWE,
pointer.CursorNorthResize: windows.IDC_SIZENS,
pointer.CursorSouthResize: windows.IDC_SIZENS,
pointer.CursorNorthEastSouthWestResize: windows.IDC_SIZENESW,
pointer.CursorNorthWestSouthEastResize: windows.IDC_SIZENWSE,
}
func loadCursor(name pointer.CursorName) (syscall.Handle, error) {
var curID uint16
switch name {
default:
fallthrough
case pointer.CursorDefault:
return resources.cursor, nil
case pointer.CursorText:
curID = windows.IDC_IBEAM
case pointer.CursorPointer:
curID = windows.IDC_HAND
case pointer.CursorCrossHair:
curID = windows.IDC_CROSS
case pointer.CursorColResize:
curID = windows.IDC_SIZEWE
case pointer.CursorRowResize:
curID = windows.IDC_SIZENS
case pointer.CursorGrab:
curID = windows.IDC_SIZEALL
case pointer.CursorTopLeftResize:
curID = windows.IDC_SIZENWSE
case pointer.CursorTopRightResize:
curID = windows.IDC_SIZENESW
case pointer.CursorBottomLeftResize:
curID = windows.IDC_SIZENESW
case pointer.CursorBottomRightResize:
curID = windows.IDC_SIZENWSE
case pointer.CursorLeftResize:
curID = windows.IDC_SIZEWE
case pointer.CursorRightResize:
curID = windows.IDC_SIZEWE
case pointer.CursorTopResize:
curID = windows.IDC_SIZENS
case pointer.CursorBottomResize:
curID = windows.IDC_SIZENS
case pointer.CursorNone:
return 0, nil
default:
return windows.LoadCursor(windowsCursor[name])
}
return windows.LoadCursor(curID)
}
func (w *window) ShowTextInput(show bool) {}
+4 -8
View File
@@ -296,18 +296,14 @@ func (w *x11Window) Raise() {
}
func (w *x11Window) SetCursor(name pointer.CursorName) {
switch name {
case pointer.CursorNone:
if name == pointer.CursorNone {
w.cursor = name
C.XFixesHideCursor(w.x, w.xw)
return
case pointer.CursorGrab:
name = "hand1"
}
if w.cursor == pointer.CursorNone {
C.XFixesShowCursor(w.x, w.xw)
}
cname := C.CString(string(name))
xcursor := xCursor[name]
cname := C.CString(xcursor)
defer C.free(unsafe.Pointer(cname))
c := C.XcursorLibraryLoadCursor(w.x, cname)
if c == 0 {
+2 -2
View File
@@ -148,7 +148,7 @@ const (
TypeClipLen = 1 + 4*4 + 1 + 1
TypePopClipLen = 1
TypeProfileLen = 1
TypeCursorLen = 1 + 1
TypeCursorLen = 2
TypePathLen = 8 + 1
TypeStrokeLen = 1 + 4
TypeSemanticLabelLen = 1
@@ -423,7 +423,7 @@ func (t OpType) Size() int {
func (t OpType) NumRefs() int {
switch t {
case TypeKeyInput, TypeKeyFocus, TypePointerInput, TypeProfile, TypeCall, TypeClipboardRead, TypeClipboardWrite, TypeCursor, TypeSemanticLabel, TypeSemanticDesc, TypeSelection:
case TypeKeyInput, TypeKeyFocus, TypePointerInput, TypeProfile, TypeCall, TypeClipboardRead, TypeClipboardWrite, TypeSemanticLabel, TypeSemanticDesc, TypeSelection:
return 1
case TypeImage, TypeSource, TypeTarget, TypeSnippet:
return 2
+130 -35
View File
@@ -91,41 +91,83 @@ type Source uint8
type Buttons uint8
// CursorName is the name of a cursor.
type CursorName string
type CursorName byte
// The cursors correspond to CSS pointer naming.
const (
// CursorDefault is the default cursor.
CursorDefault CursorName = ""
// CursorText is the cursor for text.
CursorText CursorName = "text"
// CursorPointer is the cursor for a link.
CursorPointer CursorName = "pointer"
// CursorCrossHair is the cursor for precise location.
CursorCrossHair CursorName = "crosshair"
// CursorColResize is the cursor for vertical resize.
CursorColResize CursorName = "col-resize"
// CursorRowResize is the cursor for horizontal resize.
CursorRowResize CursorName = "row-resize"
// CursorGrab is the cursor for moving object in any direction.
CursorGrab CursorName = "grab"
CursorDefault CursorName = iota
// CursorNone hides the cursor. To show it again, use any other cursor.
CursorNone CursorName = "none"
// CursorTopLeftResize is the cursor for top-left corner resizing.
CursorTopLeftResize CursorName = "nw-resize"
// CursorTopRightResize is the cursor for top-right corner resizing.
CursorTopRightResize CursorName = "ne-resize"
// CursorBottomLeftResize is the cursor for bottom-left corner resizing.
CursorBottomLeftResize CursorName = "sw-resize"
// CursorBottomRightResize is the cursor for bottom-right corner resizing.
CursorBottomRightResize CursorName = "se-resize"
// CursorLeftResize is the cursor for left resizing.
CursorLeftResize CursorName = "w-resize"
// CursorRightResize is the cursor for right resizing.
CursorRightResize CursorName = "e-resize"
// CursorTopResize is the cursor for top resizing.
CursorTopResize CursorName = "n-resize"
// CursorBottomResize is the cursor for bottom resizing.
CursorBottomResize CursorName = "s-resize"
CursorNone
// CursorText is for selecting and inserting text.
CursorText
// CursorVerticalText is for selecting and inserting vertical text.
CursorVerticalText
// CursorPointer is for a link.
// Usually displayed as a pointing hand.
CursorPointer
// CursorCrosshair is for a precise location.
CursorCrosshair
// CursorAllScroll is for indicating scrolling in all directions.
// Usually displayed as arrows to all four directions.
CursorAllScroll
// CursorColResize is for vertical resize.
// Usually displayed as a vertical bar with arrows pointing east and west.
CursorColResize
// CursorRowResize is for horizontal resize.
// Usually displayed as a horizontal bar with arrows pointing north and south.
CursorRowResize
// CursorGrab is for content that can be grabbed (dragged to be moved).
// Usually displayed as an open hand.
CursorGrab
// CursorGrabbing is for content that is being grabbed (dragged to be moved).
// Usually displayed as a closed hand.
CursorGrabbing
// CursorWait is shown when the program is busy and user cannot interact.
// Usually displayed as a hourglass or the system equivalent.
CursorNotAllowed
// CursorNotAllowed is shown when the request action cannot be carried out.
// Usually displayed as a circle with a line through.
CursorWait
// CursorProgress is shown when the program is busy, but the user can still interact.
// Usually displayed as a default cursor with a hourglass.
CursorProgress
// CursorNorthWestResize is for top-left corner resizing.
// Usually displayed as an arrow towards north-west.
CursorNorthWestResize
// CursorNorthEastResize is for top-right corner resizing.
// Usually displayed as an arrow towards north-east.
CursorNorthEastResize
// CursorSouthWestResize is for bottom-left corner resizing.
// Usually displayed as an arrow towards south-west.
CursorSouthWestResize
// CursorSouthEastResize is for bottom-right corner resizing.
// Usually displayed as an arrow towards south-east.
CursorSouthEastResize
// CursorNorthSouth is for top-bottom resizing.
// Usually displayed as a bi-directional arrow towards north-south.
CursorNorthSouthResize
// CursorEastWestResize is for left-right resizing.
// Usually displayed as a bi-directional arrow towards east-west.
CursorEastWestResize
// CursorWestResize is for left resizing.
// Usually displayed as an arrow towards west.
CursorWestResize
// CursorEastResize is for right resizing.
// Usually displayed as an arrow towards east.
CursorEastResize
// CursorNorthResize is for top resizing.
// Usually displayed as an arrow towards north.
CursorNorthResize
// CursorSouthResize is for bottom resizing.
// Usually displayed as an arrow towards south.
CursorSouthResize
// CursorNorthEastSouthWestResize is for top-right to bottom-left diagonal resizing.
// Usually displayed as a double ended arrow on the corresponding diagonal.
CursorNorthEastSouthWestResize
// CursorNorthWestSouthEastResize is for top-left to bottom-right diagonal resizing.
// Usually displayed as a double ended arrow on the corresponding diagonal.
CursorNorthWestSouthEastResize
)
const (
@@ -206,8 +248,9 @@ func (p PassStack) Pop() {
}
func (op CursorNameOp) Add(o *op.Ops) {
data := ops.Write1(&o.Internal, ops.TypeCursorLen, op.Name)
data := ops.Write(&o.Internal, ops.TypeCursorLen)
data[0] = byte(ops.TypeCursor)
data[1] = byte(op.Name)
}
// Add panics if the scroll range does not contain zero.
@@ -318,10 +361,62 @@ func (b Buttons) String() string {
}
func (c CursorName) String() string {
if c == CursorDefault {
return "default"
switch c {
case CursorDefault:
return "Default"
case CursorNone:
return "None"
case CursorText:
return "Text"
case CursorVerticalText:
return "VerticalText"
case CursorPointer:
return "Pointer"
case CursorCrosshair:
return "Crosshair"
case CursorAllScroll:
return "AllScroll"
case CursorColResize:
return "ColResize"
case CursorRowResize:
return "RowResize"
case CursorGrab:
return "Grab"
case CursorGrabbing:
return "Grabbing"
case CursorNotAllowed:
return "NotAllowed"
case CursorWait:
return "Wait"
case CursorProgress:
return "Progress"
case CursorNorthWestResize:
return "NorthWestResize"
case CursorNorthEastResize:
return "NorthEastResize"
case CursorSouthWestResize:
return "SouthWestResize"
case CursorSouthEastResize:
return "SouthEastResize"
case CursorNorthSouthResize:
return "NorthSouthResize"
case CursorEastWestResize:
return "EastWestResize"
case CursorWestResize:
return "WestResize"
case CursorEastResize:
return "EastResize"
case CursorNorthResize:
return "NorthResize"
case CursorSouthResize:
return "SouthResize"
case CursorNorthEastSouthWestResize:
return "NorthEastSouthWestResize"
case CursorNorthWestSouthEastResize:
return "NorthWestSouthEastResize"
default:
panic("unknown Type")
}
return string(c)
}
func (Event) ImplementsEvent() {}
+2 -2
View File
@@ -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.CursorNameOp{Name: pointer.CursorCrosshair}.Add(ops)
}
return []event.Event{
_at(50, 50),
@@ -648,7 +648,7 @@ func TestCursorNameOp(t *testing.T) {
},
}
},
want: pointer.CursorCrossHair,
want: pointer.CursorCrosshair,
},
{label: "remove input on top while inside",
event: func() []event.Event {
+1 -1
View File
@@ -298,7 +298,7 @@ func (q *Router) collect() {
}
pc.inputOp(op, &q.handlers)
case ops.TypeCursor:
name := encOp.Refs[0].(pointer.CursorName)
name := pointer.CursorName(encOp.Data[1])
pc.cursor(name)
case ops.TypeSource:
op := transfer.SourceOp{
+8 -8
View File
@@ -55,21 +55,21 @@ const (
func (a Action) CursorName() pointer.CursorName {
switch a {
case ActionResizeNorthWest:
return pointer.CursorTopLeftResize
return pointer.CursorNorthWestResize
case ActionResizeSouthEast:
return pointer.CursorBottomRightResize
return pointer.CursorSouthEastResize
case ActionResizeNorthEast:
return pointer.CursorTopRightResize
return pointer.CursorNorthEastResize
case ActionResizeSouthWest:
return pointer.CursorBottomLeftResize
return pointer.CursorSouthWestResize
case ActionResizeWest:
return pointer.CursorLeftResize
return pointer.CursorWestResize
case ActionResizeEast:
return pointer.CursorRightResize
return pointer.CursorEastResize
case ActionResizeNorth:
return pointer.CursorTopResize
return pointer.CursorNorthResize
case ActionResizeSouth:
return pointer.CursorBottomResize
return pointer.CursorSouthResize
}
return pointer.CursorDefault
}
+1 -1
View File
@@ -37,7 +37,7 @@ func TestPathBegin(t *testing.T) {
ops := new(op.Ops)
var p clip.Path
p.Begin(ops)
p.LineTo(f32.Point{10, 10})
p.LineTo(f32.Pt(10, 10))
p.Close()
stack := clip.Outline{Path: p.End()}.Op().Push(ops)
paint.Fill(ops, color.NRGBA{A: 255})