package tk
import (
)
type ComboBox interface {
Widget
CodeArea() CodeArea
ListBox() ListBox
Refilter()
}
type ComboBoxSpec struct {
CodeArea CodeAreaSpec
ListBox ListBoxSpec
OnFilter func(ComboBox, string)
}
type comboBox struct {
codeArea CodeArea
listBox ListBox
OnFilter func(ComboBox, string)
lastFilter string
}
func ( ComboBoxSpec) ComboBox {
if .OnFilter == nil {
.OnFilter = func(ComboBox, string) {}
}
:= &comboBox{
codeArea: NewCodeArea(.CodeArea),
listBox: NewListBox(.ListBox),
OnFilter: .OnFilter,
}
.OnFilter(, "")
return
}
func ( *comboBox) (, int) *term.Buffer {
:= .codeArea.Render(, )
:= .listBox.Render(, -len(.Lines))
.Extend(, false)
return
}
func ( *comboBox) ( term.Event) bool {
if .listBox.Handle() {
return true
}
if .codeArea.Handle() {
:= .codeArea.CopyState().Buffer.Content
if != .lastFilter {
.OnFilter(, )
.lastFilter =
}
return true
}
return false
}
func ( *comboBox) () {
.OnFilter(, .codeArea.CopyState().Buffer.Content)
}
func ( *comboBox) () CodeArea { return .codeArea }
func ( *comboBox) () ListBox { return .listBox }