Bladeren bron

key repeat support

leonsal 8 jaren geleden
bovenliggende
commit
c34c35c937
7 gewijzigde bestanden met toevoegingen van 11 en 1 verwijderingen
  1. 1 0
      gui/edit.go
  2. 2 1
      gui/events.go
  3. 1 0
      gui/list.go
  4. 1 0
      gui/root.go
  5. 1 0
      gui/slider.go
  6. 4 0
      window/glfw.go
  7. 1 0
      window/window.go

+ 1 - 0
gui/edit.go

@@ -63,6 +63,7 @@ func NewEdit(width int, placeHolder string) *Edit {
 
 	ed.Label.initialize("", StyleDefault.Font)
 	ed.Label.Subscribe(OnKeyDown, ed.onKey)
+	ed.Label.Subscribe(OnKeyRepeat, ed.onKey)
 	ed.Label.Subscribe(OnChar, ed.onChar)
 	ed.Label.Subscribe(OnMouseDown, ed.onMouse)
 	ed.Label.Subscribe(OnCursorEnter, ed.onCursor)

+ 2 - 1
gui/events.go

@@ -8,7 +8,7 @@ import (
 	"github.com/g3n/engine/window"
 )
 
-// Events
+// Consolidate window events plus GUI events
 const (
 	OnClick       = "gui.OnClick"       // Widget clicked by mouse or key
 	OnCursor      = window.OnCursor     // cursor (mouse) position events
@@ -19,6 +19,7 @@ const (
 	OnMouseOut    = "gui.OnMouseOut"    // mouse button pressed outside of the panel
 	OnKeyDown     = window.OnKeyDown    // key is pressed
 	OnKeyUp       = window.OnKeyUp      // key is released
+	OnKeyRepeat   = window.OnKeyRepeat  // key is pressed again by automatic repeat
 	OnChar        = window.OnChar       // key is pressed and has unicode
 	OnResize      = "gui.OnResize"      // panel size changed (no parameters)
 	OnEnable      = "gui.OnEnable"      // panel enabled state changed (no parameters)

+ 1 - 0
gui/list.go

@@ -84,6 +84,7 @@ func (li *List) initialize(vert bool, width, height float32) {
 	li.Scroller.adjustItem = true
 	li.Scroller.Subscribe(OnMouseDown, li.onMouseEvent)
 	li.Scroller.Subscribe(OnKeyDown, li.onKeyEvent)
+	li.Scroller.Subscribe(OnKeyRepeat, li.onKeyEvent)
 
 	if vert {
 		li.keyNext = window.KeyDown

+ 1 - 0
gui/root.go

@@ -51,6 +51,7 @@ func (r *Root) SubscribeWin() {
 
 	r.win.Subscribe(window.OnKeyUp, r.onKey)
 	r.win.Subscribe(window.OnKeyDown, r.onKey)
+	r.win.Subscribe(window.OnKeyRepeat, r.onKey)
 	r.win.Subscribe(window.OnChar, r.onChar)
 	r.win.Subscribe(window.OnMouseUp, r.onMouse)
 	r.win.Subscribe(window.OnMouseDown, r.onMouse)

+ 1 - 0
gui/slider.go

@@ -85,6 +85,7 @@ func newSlider(horiz bool, width, height float32) *Slider {
 	s.Panel.Subscribe(OnCursorLeave, s.onCursor)
 	s.Panel.Subscribe(OnScroll, s.onScroll)
 	s.Panel.Subscribe(OnKeyDown, s.onKey)
+	s.Panel.Subscribe(OnKeyRepeat, s.onKey)
 	s.Panel.Subscribe(OnResize, s.onResize)
 
 	// Initialize slider panel

+ 4 - 0
window/glfw.go

@@ -84,6 +84,10 @@ func newGLFW(width, height int, title string, full bool) (*GLFW, error) {
 			w.Dispatch(OnKeyUp, &w.keyEv)
 			return
 		}
+		if action == glfw.Repeat {
+			w.Dispatch(OnKeyRepeat, &w.keyEv)
+			return
+		}
 	})
 
 	// Set char callback

+ 1 - 0
window/window.go

@@ -241,6 +241,7 @@ const (
 	OnWindowSize = "win.OnWindowSize"
 	OnKeyUp      = "win.OnKeyUp"
 	OnKeyDown    = "win.OnKeyDown"
+	OnKeyRepeat  = "win.OnKeyRepeat"
 	OnChar       = "win.OnChar"
 	OnCursor     = "win.OnCursor"
 	OnMouseUp    = "win.OnMouseUp"