-
-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #504 from gucio321/key-any
input handler: add possibility to set additional input callback
- Loading branch information
Showing
5 changed files
with
70 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |