Skip to content

Always set/keep focus on certain TextInput widget & capture pressing enter #704

Answered by gucio321
hjlklink asked this question in Q&A
Discussion options

You must be logged in to vote
package main

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

var (
	consoleOutput, userInput string = "line1\nline 2\nline 3", ""
)

func loop() {
	giu.SingleWindow().Layout(
		giu.Label("data about user location"),
		giu.InputTextMultiline(&consoleOutput).Flags(giu.InputTextFlagsReadOnly),
		giu.Custom(func() {
			giu.SetKeyboardFocusHere()
		}),
		giu.InputText(&userInput),
		giu.Event().OnKeyPressed(giu.KeyEnter, func() {
			fmt.Print("enter clicked!")
		}),
	)
}

func main() {
	wnd := giu.NewMasterWindow("A simple text game [discussion 704]", 640, 480, 0)
	wnd.Run(loop)
}

ok, here is some code but it doesn't catch enter for some reason 🤔

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@gucio321
Comment options

Answer selected by hjlklink
@hjlklink
Comment options

@gucio321
Comment options

@hjlklink
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants