From 2a75e404af43ca8fa6e707d4506b41dad0ba1b83 Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Fri, 10 May 2024 15:12:40 -0400 Subject: unicode support --- gui/widget/input.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'gui/widget/input.go') diff --git a/gui/widget/input.go b/gui/widget/input.go index f47f587..1e15da9 100644 --- a/gui/widget/input.go +++ b/gui/widget/input.go @@ -1,7 +1,6 @@ package widget import ( - "fmt" "image" "image/draw" "sync" @@ -16,7 +15,7 @@ func Input(val chan<- uint, r image.Rectangle, focus FocusSlave, env gui.Env, wg defer close(env.Draw()) defer close(val) - text := []byte{'0'} + text := "0" focused := false env.Draw() <- inputDraw(text, focused, r) Loop: @@ -46,7 +45,7 @@ Loop: } case win.KbType: if focused && isDigit(event.Rune) { - text = fmt.Appendf(text, "%c", event.Rune) + text = text + string(event.Rune) env.Draw() <- inputDraw(text, focused, r) val <- atoi(text) } @@ -61,7 +60,7 @@ Loop: } } -func inputDraw(str []byte, focused bool, r image.Rectangle) func(draw.Image) image.Rectangle { +func inputDraw(str string, focused bool, r image.Rectangle) func(draw.Image) image.Rectangle { return func(drw draw.Image) image.Rectangle { if focused { text.Draw(str, drw, r, GREEN, FOCUS_COLOR, text.ALIGN_RIGHT) @@ -76,7 +75,7 @@ func isDigit(r rune) bool { return '0' <= r && r <= '9' } -func atoi(s []byte) uint { +func atoi(s string) uint { var n uint = 0 for _, d := range s { n = n*10 + uint(d-'0') -- cgit v1.2.3