Some work
This commit is contained in:
@@ -130,7 +130,6 @@ func (w *LinearLayout) HandleKey(ev *tcell.EventKey) bool {
|
|||||||
}
|
}
|
||||||
active := w.findActive()
|
active := w.findActive()
|
||||||
if active != nil {
|
if active != nil {
|
||||||
w.Log("LL(%s) Active(%s) Handlekey", w.Id(), active.Id())
|
|
||||||
if active.HandleKey(ev) {
|
if active.HandleKey(ev) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -504,6 +503,7 @@ func (w *LinearLayout) updateLLHWidgetSize(wd Widget) {
|
|||||||
if w.stacked {
|
if w.stacked {
|
||||||
rH = wd.MinH()
|
rH = wd.MinH()
|
||||||
}
|
}
|
||||||
|
w.Log("(%s) Resize (%s): X:%d, Y:%d", w.Id(), wd.Id(), w.getWeightedW(wd), rH)
|
||||||
wd.HandleResize((&Coord{X: w.getWeightedW(wd), Y: rH}).ResizeEvent())
|
wd.HandleResize((&Coord{X: w.getWeightedW(wd), Y: rH}).ResizeEvent())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -562,6 +562,11 @@ func (w *LinearLayout) updateLLVWidgetPos(wd Widget) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *LinearLayout) updateLLHWidgetPos(wd Widget) {
|
func (w *LinearLayout) updateLLHWidgetPos(wd Widget) {
|
||||||
|
debug := func(wd Widget, txt string, args ...any) {
|
||||||
|
if wd.Id() == "mngenc.selectadversary" {
|
||||||
|
w.Log(txt, args...)
|
||||||
|
}
|
||||||
|
}
|
||||||
c := Coord{}
|
c := Coord{}
|
||||||
for i := range w.widgets {
|
for i := range w.widgets {
|
||||||
if w.widgets[i] == wd {
|
if w.widgets[i] == wd {
|
||||||
@@ -572,6 +577,7 @@ func (w *LinearLayout) updateLLHWidgetPos(wd Widget) {
|
|||||||
}
|
}
|
||||||
if w.widgets[i].Visible() {
|
if w.widgets[i].Visible() {
|
||||||
c.X = w.widgets[i].GetX() + w.widgets[i].GetW()
|
c.X = w.widgets[i].GetX() + w.widgets[i].GetW()
|
||||||
|
debug(wd, "Bumping X: %d + %d = %d", w.widgets[i].GetX(), w.widgets[i].GetW(), c.X)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -608,6 +614,7 @@ func (w *LinearLayout) updateLLHWidgetPos(wd Widget) {
|
|||||||
c.X += 1
|
c.X += 1
|
||||||
c.Y += 1
|
c.Y += 1
|
||||||
}
|
}
|
||||||
|
w.Log("(%s) SetPos (%s): X:%d, Y:%d", w.Id(), wd.Id(), c.X, c.Y)
|
||||||
wd.SetPos(c)
|
wd.SetPos(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,12 +41,13 @@ type Searcher struct {
|
|||||||
visible bool
|
visible bool
|
||||||
focusable bool
|
focusable bool
|
||||||
|
|
||||||
title string
|
title string
|
||||||
search *Field
|
search *Field
|
||||||
data []string
|
data []string
|
||||||
filteredData []string
|
filteredData []string
|
||||||
cursor int
|
filteredToTrue map[int]int
|
||||||
disableBorder bool
|
cursor int
|
||||||
|
disableBorder bool
|
||||||
|
|
||||||
selectFunc func(idx int, s string) bool
|
selectFunc func(idx int, s string) bool
|
||||||
onChange func(idx int, s string) bool
|
onChange func(idx int, s string) bool
|
||||||
@@ -84,6 +85,7 @@ func (w *Searcher) Init(id string, style tcell.Style) {
|
|||||||
})
|
})
|
||||||
w.customKeyMap = BlankKeyMap()
|
w.customKeyMap = BlankKeyMap()
|
||||||
w.focusable = true
|
w.focusable = true
|
||||||
|
w.filteredToTrue = make(map[int]int)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Searcher) Id() string { return w.id }
|
func (w *Searcher) Id() string { return w.id }
|
||||||
@@ -332,6 +334,7 @@ func (w *Searcher) SetData(data []string) {
|
|||||||
func (w *Searcher) updateFilter() {
|
func (w *Searcher) updateFilter() {
|
||||||
var selVal string
|
var selVal string
|
||||||
data := []string{}
|
data := []string{}
|
||||||
|
w.filteredToTrue = make(map[int]int)
|
||||||
copy(data, w.filteredData)
|
copy(data, w.filteredData)
|
||||||
if len(data) > 0 && len(data) > w.cursor {
|
if len(data) > 0 && len(data) > w.cursor {
|
||||||
selVal = data[w.cursor]
|
selVal = data[w.cursor]
|
||||||
@@ -342,10 +345,12 @@ func (w *Searcher) updateFilter() {
|
|||||||
for i := range w.data {
|
for i := range w.data {
|
||||||
if cS {
|
if cS {
|
||||||
if strings.Contains(w.data[i], filter) {
|
if strings.Contains(w.data[i], filter) {
|
||||||
|
w.filteredToTrue[len(w.filteredData)] = i
|
||||||
w.filteredData = append(w.filteredData, w.data[i])
|
w.filteredData = append(w.filteredData, w.data[i])
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if strings.Contains(strings.ToLower(w.data[i]), filter) {
|
if strings.Contains(strings.ToLower(w.data[i]), filter) {
|
||||||
|
w.filteredToTrue[len(w.filteredData)] = i
|
||||||
w.filteredData = append(w.filteredData, w.data[i])
|
w.filteredData = append(w.filteredData, w.data[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -379,7 +384,12 @@ func (w *Searcher) doChange() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if w.cursor < l {
|
if w.cursor < l {
|
||||||
w.onChange(w.cursor, w.filteredData[w.cursor])
|
tr, ok := w.filteredToTrue[w.cursor]
|
||||||
|
if !ok {
|
||||||
|
// How did we get here?
|
||||||
|
return
|
||||||
|
}
|
||||||
|
w.onChange(tr, w.data[tr])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ THE SOFTWARE.
|
|||||||
package widgets
|
package widgets
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
h "git.bullercodeworks.com/brian/tcell-widgets/helpers"
|
||||||
wh "git.bullercodeworks.com/brian/tcell-widgets/helpers"
|
wh "git.bullercodeworks.com/brian/tcell-widgets/helpers"
|
||||||
"github.com/gdamore/tcell"
|
"github.com/gdamore/tcell"
|
||||||
)
|
)
|
||||||
@@ -235,9 +236,7 @@ func (w *SimpleList) WantH() int {
|
|||||||
|
|
||||||
func (w *SimpleList) MinW() int {
|
func (w *SimpleList) MinW() int {
|
||||||
lng := wh.Longest(w.list)
|
lng := wh.Longest(w.list)
|
||||||
if lng > 80 {
|
lng = h.Min(lng, 80)
|
||||||
lng = 80
|
|
||||||
}
|
|
||||||
return 2 + lng
|
return 2 + lng
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -252,6 +251,9 @@ func (w *SimpleList) MoveUp() bool {
|
|||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
} else if w.cursorWrap {
|
} else if w.cursorWrap {
|
||||||
|
if w.cursor <= 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
w.cursor = len(w.list) - 1
|
w.cursor = len(w.list) - 1
|
||||||
if w.onChange != nil {
|
if w.onChange != nil {
|
||||||
w.onChange(w.cursor, w.list[w.cursor])
|
w.onChange(w.cursor, w.list[w.cursor])
|
||||||
@@ -270,7 +272,7 @@ func (w *SimpleList) MoveDown() bool {
|
|||||||
return true
|
return true
|
||||||
} else if w.cursorWrap {
|
} else if w.cursorWrap {
|
||||||
w.cursor = 0
|
w.cursor = 0
|
||||||
if w.onChange != nil {
|
if len(w.list) > w.cursor && w.onChange != nil {
|
||||||
w.onChange(w.cursor, w.list[w.cursor])
|
w.onChange(w.cursor, w.list[w.cursor])
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
|||||||
Reference in New Issue
Block a user