Explorar el Código

improved cursor api, show i-beam cursor over edit

danaugrs hace 7 años
padre
commit
1fbff9af7b
Se han modificado 3 ficheros con 27 adiciones y 10 borrados
  1. 2 0
      gui/edit.go
  2. 24 9
      gui/root.go
  3. 1 1
      gui/window.go

+ 2 - 0
gui/edit.go

@@ -279,12 +279,14 @@ func (ed *Edit) onMouse(evname string, ev interface{}) {
 func (ed *Edit) onCursor(evname string, ev interface{}) {
 
 	if evname == OnCursorEnter {
+		ed.root.SetCursorText()
 		ed.cursorOver = true
 		ed.update()
 		ed.root.StopPropagation(Stop3D)
 		return
 	}
 	if evname == OnCursorLeave {
+		ed.root.SetCursorNormal()
 		ed.cursorOver = false
 		ed.update()
 		ed.root.StopPropagation(Stop3D)

+ 24 - 9
gui/root.go

@@ -152,34 +152,44 @@ func (r *Root) StopPropagation(events int) {
 	r.stopPropagation |= events
 }
 
-// SetCursorNormal sets the cursor of the associated window to
-// standard type
+// SetCursorNormal sets the cursor over the associated window to the standard type.
 func (r *Root) SetCursorNormal() {
 
 	r.win.SetStandardCursor(window.ArrowCursor)
 }
 
-// SetCursorDrag sets the cursor of the associated window to
-// drag type
-func (r *Root) SetCursorDrag() {
+// SetCursorText sets the cursor over the associated window to the I-Beam type.
+func (r *Root) SetCursorText() {
+
+	r.win.SetStandardCursor(window.IBeamCursor)
+}
+
+// SetCursorText sets the cursor over the associated window to the crosshair type.
+func (r *Root) SetCursorCrosshair() {
+
+	r.win.SetStandardCursor(window.CrosshairCursor)
+}
+
+// SetCursorHand sets the cursor over the associated window to the hand type.
+func (r *Root) SetCursorHand() {
 
 	r.win.SetStandardCursor(window.HandCursor)
 }
 
-// SetCursorHResize sets the cursor of the associated window to
-// horizontal resize type
+// SetCursorHResize sets the cursor over the associated window to the horizontal resize type.
 func (r *Root) SetCursorHResize() {
 
 	r.win.SetStandardCursor(window.HResizeCursor)
 }
 
-// SetCursorVResize sets the cursor of the associated window to
-// vertical resize type
+// SetCursorVResize sets the cursor over the associated window to the vertical resize type.
 func (r *Root) SetCursorVResize() {
 
 	r.win.SetStandardCursor(window.VResizeCursor)
 }
 
+// TODO allow setting a custom cursor
+
 // onKey is called when key events are received
 func (r *Root) onKey(evname string, ev interface{}) {
 
@@ -401,6 +411,11 @@ func (r *Root) canDispatch(ipan IPanel) bool {
 	return checkChildren(r.modalPanel)
 }
 
+//func (r *Root) applyStyleRecursively(s *Style) {
+//	// TODO
+//	// This should probably be in Panel ?
+//}
+
 // For sorting panels by Z coordinate
 type listPanelZ []IPanel
 

+ 1 - 1
gui/window.go

@@ -320,7 +320,7 @@ func (wt *WindowTitle) onMouse(evname string, ev interface{}) {
 func (wt *WindowTitle) onCursor(evname string, ev interface{}) {
 
 	if evname == OnCursorEnter {
-		wt.win.root.SetCursorDrag()
+		wt.win.root.SetCursorHand()
 	} else if evname == OnCursorLeave {
 		wt.win.root.SetCursorNormal()
 	} else if evname == OnCursor {