diff options
Diffstat (limited to 'gui/widget')
| -rw-r--r-- | gui/widget/input.go | 9 | ||||
| -rw-r--r-- | gui/widget/label.go | 2 | ||||
| -rw-r--r-- | gui/widget/output.go | 2 | ||||
| -rw-r--r-- | gui/widget/tree.go | 6 |
4 files changed, 11 insertions, 8 deletions
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') diff --git a/gui/widget/label.go b/gui/widget/label.go index fe451f8..7a583bc 100644 --- a/gui/widget/label.go +++ b/gui/widget/label.go @@ -15,7 +15,7 @@ func Label(str string, r image.Rectangle, env gui.Env, wg *sync.WaitGroup) { defer close(env.Draw()) redraw := func(drw draw.Image) image.Rectangle { - text.Draw([]byte(str), drw, r, BLACK, WHITE, text.ALIGN_LEFT) + text.Draw(str, drw, r, BLACK, WHITE, text.ALIGN_LEFT) return r } diff --git a/gui/widget/output.go b/gui/widget/output.go index ecca18c..16aacca 100644 --- a/gui/widget/output.go +++ b/gui/widget/output.go @@ -35,7 +35,7 @@ Loop: func outputDraw(v float64, r image.Rectangle) func(draw.Image) image.Rectangle { return func(drw draw.Image) image.Rectangle { - text.Draw([]byte(fmt.Sprintf("%.3f", v)), drw, r, BLACK, WHITE, text.ALIGN_RIGHT) + text.Draw(fmt.Sprintf("%.3f", v), drw, r, BLACK, WHITE, text.ALIGN_RIGHT) return r } } diff --git a/gui/widget/tree.go b/gui/widget/tree.go index 14d7b9d..633d440 100644 --- a/gui/widget/tree.go +++ b/gui/widget/tree.go @@ -9,6 +9,8 @@ import ( "volute/gui/layout" ) +const INDENT = 2 + type Node[T any] struct { Label string Value T @@ -50,7 +52,9 @@ func Tree[T any](trees []Node[T], r image.Rectangle, focus FocusSlave, mux *gui. } func flatten[T any](root Node[T], depth int) []string { - indent := string(populate(make([]byte, 2*depth), ' ')) + indent := string(populate( + make([]rune, INDENT*depth), + '─')) nodes := []string{indent + root.Label} root.expanded = true // TODO: remove me if root.expanded { |