Skip to content

Instantly share code, notes, and snippets.

@rr3tt
Created December 20, 2023 02:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rr3tt/c01970ad2c41592472c1892bf76d6e4e to your computer and use it in GitHub Desktop.
Save rr3tt/c01970ad2c41592472c1892bf76d6e4e to your computer and use it in GitHub Desktop.
package main
import (
"log/slog"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"
)
type Editor struct {
widget.TextGrid
}
func NewEditor() *Editor {
e := &Editor{}
e.ExtendBaseWidget(e)
return e
}
// Tappable interface
func (e *Editor) Tapped(pe *fyne.PointEvent) {
slog.Info("Tapped")
fyne.CurrentApp().Driver().CanvasForObject(e).Focus(e)
}
// Focusable interface
func (e *Editor) TypedKey(k *fyne.KeyEvent) {
slog.Info("TypedKey", "k", k)
}
// Focusable interface
func (e *Editor) TypedRune(r rune) {
input := string(r)
slog.Info("TypedRune", "input", input)
e.SetText(input)
e.Refresh()
}
// Focusable interface
func (e *Editor) FocusGained() {
slog.Info("FocusGained")
}
// Focusable interface
func (e *Editor) FocusLost() {
slog.Info("FocusLost")
}
func main() {
a := app.New()
window := a.NewWindow("")
window.Resize(fyne.NewSize(500, 500))
editor := NewEditor()
entry := widget.NewEntry()
editor.SetText("editor area")
window.SetContent(container.NewVBox(entry, editor))
window.Canvas().Focus(editor)
window.ShowAndRun()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment