diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2024-01-17 15:47:12 -0500 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2024-01-17 15:47:12 -0500 |
| commit | 0a696233d721c64d1bb53c7429624313113fa6f5 (patch) | |
| tree | a8f627b6e5b7295747b56c0c4956f6a3fc44ea1c | |
| parent | 29e2be59cc3d0f31241884087624ece7d35115e4 (diff) | |
| download | volute-0a696233d721c64d1bb53c7429624313113fa6f5.zip | |
fix input widget registering backspace when unfocused
| -rw-r--r-- | gui/widget/text.go | 3 | ||||
| -rw-r--r-- | gui/widget/widget.go | 2 |
2 files changed, 2 insertions, 3 deletions
diff --git a/gui/widget/text.go b/gui/widget/text.go index cb66a0a..4723eda 100644 --- a/gui/widget/text.go +++ b/gui/widget/text.go @@ -45,12 +45,11 @@ func drawText(text []byte, dst draw.Image, r image.Rectangle) { Dot: fixed.P(0, 0), } - bounds := textBounds(text, drawer) - // background draw.Draw(dst, r, BG_COLOR, image.ZP, draw.Src) // text image + bounds := textBounds(text, drawer) textImg := image.NewRGBA(bounds) draw.Draw(textImg, bounds, BG_COLOR, image.ZP, draw.Src) drawer.Dst = textImg diff --git a/gui/widget/widget.go b/gui/widget/widget.go index 913809b..fbf866a 100644 --- a/gui/widget/widget.go +++ b/gui/widget/widget.go @@ -42,7 +42,7 @@ func Input(env gui.Env, r image.Rectangle, val chan<- float64) { text = fmt.Appendf(text, "%c", event.Rune) env.Draw() <- redraw(text) case win.KbDown: - if event.Key == win.KeyBackspace && len(text) > 0 { + if event.Key == win.KeyBackspace && focus && len(text) > 0 { text = text[:len(text)-1] env.Draw() <- redraw(text) } |