Added quick chars to MenuBar and Menus

This commit is contained in:
Luke I. Wilson
2021-03-19 19:58:59 -05:00
parent 83567c1341
commit ffaad36c78
4 changed files with 54 additions and 25 deletions

View File

@@ -15,11 +15,33 @@ func DrawRect(s tcell.Screen, x, y, width, height int, char rune, style tcell.St
// DrawStr will render each character of a string at `x` and `y`.
func DrawStr(s tcell.Screen, x, y int, str string, style tcell.Style) {
runes := []rune(str)
for idx := 0; idx < len(runes); idx++ {
s.SetContent(x+idx, y, runes[idx], nil, style)
for idx, r := range runes {
s.SetContent(x+idx, y, r, nil, style)
}
}
// DrawQuickCharStr renders a string very similar to how DrawStr works, but stylizes the
// quick char (any rune after an underscore) with an underline. Returned is the number of
// columns that were drawn to the screen. This is useful to know the length of the string
// drawn, minus the underscore.
func DrawQuickCharStr(s tcell.Screen, x, y int, str string, style tcell.Style) int {
runes := []rune(str)
col := 0
for i := 0; i < len(runes); i++ {
r := runes[i]
if r == '_' && i+1 < len(runes) {
i++
sty := style.Underline(true)
s.SetContent(x+col, y, runes[i], nil, sty)
} else {
s.SetContent(x+col, y, r, nil, style)
}
col++
}
return col
}
// DrawRectOutline draws only the outline of a rectangle, using `ul`, `ur`, `bl`, and `br`
// for the corner runes, and `hor` and `vert` for the horizontal and vertical runes, respectively.
func DrawRectOutline(s tcell.Screen, x, y, _width, _height int, ul, ur, bl, br, hor, vert rune, style tcell.Style) {