Skip to content

Commit

Permalink
additional input handler callback: add example (issue-501)
Browse files Browse the repository at this point in the history
  • Loading branch information
gucio321 committed May 8, 2022
1 parent 693f66f commit 5857d7e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions MasterWindow.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ func (w *MasterWindow) SetInputHandler(handler InputHandler) {
}

// SetAdditionalInputHandlerCallback allows to set an input callback to handle more events (not only these from giu.inputHandler)
// see examples/issue-501
func (w *MasterWindow) SetAdditionalInputHandlerCallback(cb InputHandlerHandleCallback) {
w.additionalInputCallback = cb
}
37 changes: 37 additions & 0 deletions examples/issue-501/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package main

import (
"github.com/AllenDang/giu"
)

var (
command string
shouldFocus bool
)

func loop() {
giu.SingleWindow().Layout(
giu.Custom(func() {
if shouldFocus {
shouldFocus = false
giu.SetKeyboardFocusHere()
}
}),
giu.Row(
giu.InputText(&command).Size(200),
giu.Label("<- press any key to start typing here!"),
),
)
}

func onAnyKeyPressed(key giu.Key, mod giu.Modifier, action giu.Action) {
if action == giu.Press {
shouldFocus = true
}
}

func main() {
wnd := giu.NewMasterWindow("Handle any key event", 640, 480, 0)
wnd.SetAdditionalInputHandlerCallback(onAnyKeyPressed)
wnd.Run(loop)
}

0 comments on commit 5857d7e

Please sign in to comment.