A few tweaks
This commit is contained in:
@@ -39,11 +39,12 @@ type Searcher struct {
|
||||
visible bool
|
||||
tabbable bool
|
||||
|
||||
title string
|
||||
search *Field
|
||||
data []string
|
||||
filteredData []string
|
||||
cursor int
|
||||
title string
|
||||
search *Field
|
||||
data []string
|
||||
filteredData []string
|
||||
cursor int
|
||||
disableBorder bool
|
||||
|
||||
selectFunc func(idx int, s string) bool
|
||||
hideOnSelect bool
|
||||
@@ -87,6 +88,9 @@ func (w *Searcher) HandleResize(ev *tcell.EventResize) {
|
||||
w.Log("Searcher<%s>.HandleResize: %d,%d", w.Id(), w.w, w.h)
|
||||
// Remove 2 from each for borders
|
||||
aW, aH := w.w-2, w.h-2
|
||||
if !w.disableBorder {
|
||||
aW, aH = aW-2, aH-2
|
||||
}
|
||||
w.search.SetPos(Coord{X: 1, Y: 1})
|
||||
w.search.HandleResize(Coord{X: aW, Y: aH}.ResizeEvent())
|
||||
}
|
||||
@@ -174,11 +178,15 @@ func (w *Searcher) Draw(screen tcell.Screen) {
|
||||
return
|
||||
}
|
||||
dStyle := w.style.Dim(!w.active)
|
||||
if len(w.title) > 0 {
|
||||
wh.TitledBorderFilled(w.x, w.y, w.x+w.w, w.y+w.h-1, w.title, wh.BRD_CSIMPLE, dStyle, screen)
|
||||
// w.Log("Searcher<%s> Bounds: %d,%d -> %d,%d", w.Id(), w.x, w.y, w.x+w.w, w.y+w.h)
|
||||
} else {
|
||||
wh.BorderFilled(w.x, w.y, w.x+w.w, w.y+w.h, wh.BRD_CSIMPLE, dStyle, screen)
|
||||
if !w.disableBorder {
|
||||
if len(w.title) > 0 {
|
||||
wh.TitledBorderFilled(w.x, w.y, w.x+w.w, w.y+w.h-1, w.title, wh.BRD_CSIMPLE, dStyle, screen)
|
||||
// w.Log("Searcher<%s> Bounds: %d,%d -> %d,%d", w.Id(), w.x, w.y, w.x+w.w, w.y+w.h)
|
||||
} else {
|
||||
wh.BorderFilled(w.x, w.y, w.x+w.w, w.y+w.h, wh.BRD_CSIMPLE, dStyle, screen)
|
||||
}
|
||||
} else if len(w.title) > 0 {
|
||||
// TODO: Output the label
|
||||
}
|
||||
w.GetPos().DrawOffset(w.search, screen)
|
||||
x, y := w.x+1, w.y+2
|
||||
@@ -226,7 +234,11 @@ func (w *Searcher) WantW() int {
|
||||
}
|
||||
|
||||
func (w *Searcher) WantH() int {
|
||||
return 2 + w.search.WantH() + len(w.filteredData) // Border + Field + Data
|
||||
ret := w.search.WantH() + len(w.filteredData)
|
||||
if !w.disableBorder {
|
||||
return ret + 2
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (w *Searcher) GetPos() Coord { return Coord{X: w.x, Y: w.y} }
|
||||
@@ -288,9 +300,8 @@ func (w *Searcher) updateFilter() {
|
||||
w.cursor = 0
|
||||
}
|
||||
|
||||
func (w *Searcher) SelectedValue() string {
|
||||
return w.filteredData[w.cursor]
|
||||
}
|
||||
func (w *Searcher) SelectedValue() string { return w.filteredData[w.cursor] }
|
||||
func (w *Searcher) SelectedIndex() int { return w.cursor }
|
||||
|
||||
func (w *Searcher) SetSearchValue(val string) {
|
||||
w.search.SetValue(val)
|
||||
@@ -312,3 +323,5 @@ func (w *Searcher) Log(txt string, args ...any) {
|
||||
w.logger(txt, args...)
|
||||
}
|
||||
}
|
||||
|
||||
func (w *Searcher) DisableBorder(b bool) { w.disableBorder = b }
|
||||
|
||||
Reference in New Issue
Block a user