Fix Searcher Layout
This commit is contained in:
2
example/.gitignore
vendored
Normal file
2
example/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
# Ignore Binary
|
||||||
|
example
|
||||||
BIN
example/example
BIN
example/example
Binary file not shown.
@@ -22,7 +22,7 @@ THE SOFTWARE.
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"math/rand"
|
||||||
|
|
||||||
w "git.bullercodeworks.com/brian/tcell-widgets"
|
w "git.bullercodeworks.com/brian/tcell-widgets"
|
||||||
"github.com/gdamore/tcell"
|
"github.com/gdamore/tcell"
|
||||||
@@ -48,14 +48,25 @@ func (s *UiScreen) Init(ui *Ui) {
|
|||||||
ll.SetTabbable(true)
|
ll.SetTabbable(true)
|
||||||
ll.SetLogger(s.log.Log)
|
ll.SetLogger(s.log.Log)
|
||||||
|
|
||||||
testList := w.NewList("test-list", ui.style)
|
searcher := w.NewSearcher("test.searcher", ui.style)
|
||||||
for i := 0; i < 10; i++ {
|
searcher.SetLogger(s.log.Log)
|
||||||
testList.Add(fmt.Sprintf("Item %d", i))
|
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)
|
var dat []string
|
||||||
ll.Add(testList)
|
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.SetTabbable(true)
|
||||||
btnL.SetLogger(s.log.Log)
|
btnL.SetLogger(s.log.Log)
|
||||||
btnL.SetOrientation(w.LinLayH)
|
btnL.SetOrientation(w.LinLayH)
|
||||||
|
|||||||
@@ -84,11 +84,10 @@ func (w *Searcher) Init(id string, style tcell.Style) {
|
|||||||
func (w *Searcher) Id() string { return w.id }
|
func (w *Searcher) Id() string { return w.id }
|
||||||
func (w *Searcher) HandleResize(ev *tcell.EventResize) {
|
func (w *Searcher) HandleResize(ev *tcell.EventResize) {
|
||||||
w.w, w.h = ev.Size()
|
w.w, w.h = ev.Size()
|
||||||
|
// Remove 2 from each for borders
|
||||||
// w.w = wh.Min(w.w, w.WantW())
|
aW, aH := w.w-2, w.h-2
|
||||||
// w.h = wh.Min(w.h, w.WantH())
|
w.search.SetPos(Coord{X: 1, Y: 1})
|
||||||
// TODO: Verify this is fine:
|
w.search.HandleResize(Coord{X: aW, Y: aH}.ResizeEvent())
|
||||||
w.search.HandleResize(ev)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Searcher) HandleKey(ev *tcell.EventKey) bool {
|
func (w *Searcher) HandleKey(ev *tcell.EventKey) bool {
|
||||||
@@ -173,8 +172,6 @@ func (w *Searcher) Draw(screen tcell.Screen) {
|
|||||||
if !w.visible {
|
if !w.visible {
|
||||||
return
|
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
|
dStyle := w.style
|
||||||
if !w.active {
|
if !w.active {
|
||||||
dStyle = dStyle.Dim(true)
|
dStyle = dStyle.Dim(true)
|
||||||
|
|||||||
@@ -117,7 +117,9 @@ func (w *TopMenuLayout) Draw(screen tcell.Screen) {
|
|||||||
func (w *TopMenuLayout) Active() bool { return w.active }
|
func (w *TopMenuLayout) Active() bool { return w.active }
|
||||||
func (w *TopMenuLayout) SetActive(a bool) {
|
func (w *TopMenuLayout) SetActive(a bool) {
|
||||||
w.active = a
|
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) Visible() bool { return w.visible }
|
||||||
func (w *TopMenuLayout) SetVisible(a bool) { w.visible = a }
|
func (w *TopMenuLayout) SetVisible(a bool) { w.visible = a }
|
||||||
|
|||||||
Reference in New Issue
Block a user