Fix Searcher Layout

This commit is contained in:
2025-08-14 09:08:40 -05:00
parent 566f35e655
commit a74cf9fe61
5 changed files with 27 additions and 15 deletions

2
example/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
# Ignore Binary
example

Binary file not shown.

View File

@@ -22,7 +22,7 @@ THE SOFTWARE.
package main
import (
"fmt"
"math/rand"
w "git.bullercodeworks.com/brian/tcell-widgets"
"github.com/gdamore/tcell"
@@ -48,14 +48,25 @@ func (s *UiScreen) Init(ui *Ui) {
ll.SetTabbable(true)
ll.SetLogger(s.log.Log)
testList := w.NewList("test-list", ui.style)
for i := 0; i < 10; i++ {
testList.Add(fmt.Sprintf("Item %d", i))
searcher := w.NewSearcher("test.searcher", ui.style)
searcher.SetLogger(s.log.Log)
searcher.SetTitle("Test Searcher")
const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
rStr := func(n int) string {
b := make([]byte, n)
for i := range b {
b[i] = letters[rand.Intn(len(letters))]
}
testList.SetLogger(s.log.Log)
ll.Add(testList)
return string(b)
}
var dat []string
for i := 0; i < 1000; i++ {
dat = append(dat, rStr(15))
}
searcher.SetData(dat)
ll.Add(searcher)
btnL := w.NewLinearLayout("btn-ll", ui.style)
btnL := w.NewLinearLayout("test.btnll", ui.style)
btnL.SetTabbable(true)
btnL.SetLogger(s.log.Log)
btnL.SetOrientation(w.LinLayH)

View File

@@ -84,11 +84,10 @@ func (w *Searcher) Init(id string, style tcell.Style) {
func (w *Searcher) Id() string { return w.id }
func (w *Searcher) HandleResize(ev *tcell.EventResize) {
w.w, w.h = ev.Size()
// w.w = wh.Min(w.w, w.WantW())
// w.h = wh.Min(w.h, w.WantH())
// TODO: Verify this is fine:
w.search.HandleResize(ev)
// Remove 2 from each for borders
aW, aH := w.w-2, w.h-2
w.search.SetPos(Coord{X: 1, Y: 1})
w.search.HandleResize(Coord{X: aW, Y: aH}.ResizeEvent())
}
func (w *Searcher) HandleKey(ev *tcell.EventKey) bool {
@@ -173,8 +172,6 @@ func (w *Searcher) Draw(screen tcell.Screen) {
if !w.visible {
return
}
w.search.SetPos(Coord{X: w.x + 1, Y: w.y + 1})
w.search.SetSize(Coord{X: w.w - 2, Y: 1})
dStyle := w.style
if !w.active {
dStyle = dStyle.Dim(true)

View File

@@ -117,7 +117,9 @@ func (w *TopMenuLayout) Draw(screen tcell.Screen) {
func (w *TopMenuLayout) Active() bool { return w.active }
func (w *TopMenuLayout) SetActive(a bool) {
w.active = a
if w.widget != nil {
w.widget.SetActive(a)
}
}
func (w *TopMenuLayout) Visible() bool { return w.visible }
func (w *TopMenuLayout) SetVisible(a bool) { w.visible = a }