diff --git a/example/.gitignore b/example/.gitignore new file mode 100644 index 0000000..93755b6 --- /dev/null +++ b/example/.gitignore @@ -0,0 +1,2 @@ +# Ignore Binary +example diff --git a/example/example b/example/example deleted file mode 100755 index d249333..0000000 Binary files a/example/example and /dev/null differ diff --git a/example/ui_screen.go b/example/ui_screen.go index 70f33b6..ae54592 100644 --- a/example/ui_screen.go +++ b/example/ui_screen.go @@ -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))] + } + return string(b) } - testList.SetLogger(s.log.Log) - ll.Add(testList) + 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) diff --git a/wdgt_searcher.go b/wdgt_searcher.go index 033319d..bd18948 100644 --- a/wdgt_searcher.go +++ b/wdgt_searcher.go @@ -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) diff --git a/wdgt_top_menu_layout.go b/wdgt_top_menu_layout.go index fe32038..f8ba452 100644 --- a/wdgt_top_menu_layout.go +++ b/wdgt_top_menu_layout.go @@ -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 - w.widget.SetActive(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 }