Created
December 20, 2023 02:40
-
-
Save gjkliewer/c01970ad2c41592472c1892bf76d6e4e to your computer and use it in GitHub Desktop.
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
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