closes #45 - allow to use color tags in listbox

This commit is contained in:
Vladimir Markelov 2015-11-30 14:17:39 -08:00
parent 187fb9bdd0
commit 2b10c92a2f
1 changed files with 21 additions and 2 deletions

View File

@ -23,6 +23,7 @@ type ListBox struct {
currSelection int
topLine int
buttonPos int
multicolor bool
onSelectItem func(Event)
onKeyPress func(term.Key) bool
@ -95,8 +96,12 @@ func (l *ListBox) redrawItems(canvas Canvas, tm Theme) {
}
canvas.FillRect(l.x, l.y+dy, l.width-1, 1, term.Cell{Bg: b, Ch: ' ', Fg: f})
_, text := AlignText(l.items[curr], maxWidth, AlignLeft)
canvas.PutText(l.x, l.y+dy, text, f, b)
if l.multicolor {
canvas.PutColorizedText(l.x, l.y+dy, maxWidth, l.items[curr], f, b, Horizontal)
} else {
_, text := AlignText(l.items[curr], maxWidth, AlignLeft)
canvas.PutText(l.x, l.y+dy, text, f, b)
}
curr++
dy++
@ -397,3 +402,17 @@ func (l *ListBox) OnKeyPress(fn func(term.Key) bool) {
func (l *ListBox) ItemCount() int {
return len(l.items)
}
// MultiColored returns if the listbox checks and applies any
// color related tags inside its title. If MultiColores is
// false then title is displayed as is.
// To read about available color tags, please see ColorParser
func (l *ListBox) MultiColored() bool {
return l.multicolor
}
// SetMultiColored changes how the listbox output its title: as is
// or parse and apply all internal color tags
func (l *ListBox) SetMultiColored(multi bool) {
l.multicolor = multi
}