Much Work
- Definable KeyMaps - Change 'Tabbable' to just use 'Focusable'
This commit is contained in:
@@ -37,7 +37,6 @@ type FilePicker struct {
|
||||
active bool
|
||||
visible bool
|
||||
focusable bool
|
||||
tabbable bool
|
||||
|
||||
x, y int
|
||||
w, h int
|
||||
@@ -50,6 +49,8 @@ type FilePicker struct {
|
||||
|
||||
fileList *List
|
||||
btnSelect, btnCancel *Button
|
||||
|
||||
keyMap KeyMap
|
||||
}
|
||||
|
||||
var _ Widget = (*FilePicker)(nil)
|
||||
@@ -72,7 +73,8 @@ func (w *FilePicker) Init(id string, style tcell.Style) {
|
||||
w.btnCancel = NewButton(fmt.Sprintf("%s-cancel", id), style)
|
||||
w.btnCancel.SetLabel("Cancel")
|
||||
w.layout.Add(w.btnCancel, nil, RelAncBL)
|
||||
w.tabbable = true
|
||||
w.focusable = true
|
||||
w.keyMap = BlankKeyMap()
|
||||
}
|
||||
func (w *FilePicker) Id() string { return w.id }
|
||||
func (w *FilePicker) HandleResize(ev *tcell.EventResize) {
|
||||
@@ -82,21 +84,29 @@ func (w *FilePicker) HandleResize(ev *tcell.EventResize) {
|
||||
w.btnCancel.SetPos(Coord{X: w.x + 1, Y: w.y + w.h - 1})
|
||||
}
|
||||
|
||||
func (w *FilePicker) SetKeyMap(km KeyMap) { w.keyMap = km }
|
||||
func (w *FilePicker) AddToKeyMap(km KeyMap) { w.keyMap.Merge(km) }
|
||||
func (w *FilePicker) RemoveFromKeyMap(km KeyMap) {
|
||||
for k := range km.Keys {
|
||||
w.keyMap.Remove(k)
|
||||
}
|
||||
for r := range km.Runes {
|
||||
w.keyMap.RemoveRune(r)
|
||||
}
|
||||
}
|
||||
|
||||
func (w *FilePicker) HandleKey(ev *tcell.EventKey) bool {
|
||||
if !w.active {
|
||||
return false
|
||||
}
|
||||
return false
|
||||
return w.keyMap.Handle(ev)
|
||||
}
|
||||
func (w *FilePicker) HandleTime(ev *tcell.EventTime) {}
|
||||
func (w *FilePicker) Draw(screen tcell.Screen) {
|
||||
if !w.visible {
|
||||
return
|
||||
}
|
||||
ds := w.style
|
||||
if !w.active {
|
||||
ds = ds.Dim(true)
|
||||
}
|
||||
ds := w.style.Dim(!w.active)
|
||||
wh.TitledBorderFilled(w.x, w.y, w.x+w.w, w.y+w.h, w.title, wh.BRD_SIMPLE, ds, screen)
|
||||
// TODO: Draw the file picker
|
||||
wh.DrawText(w.x+1, w.y+1, "TODO: Draw Filepicker", ds, screen)
|
||||
@@ -104,24 +114,23 @@ func (w *FilePicker) Draw(screen tcell.Screen) {
|
||||
w.GetPos().DrawOffset(w.btnCancel, screen)
|
||||
}
|
||||
|
||||
func (w *FilePicker) Active() bool { return w.active }
|
||||
func (w *FilePicker) SetActive(a bool) { w.active = a }
|
||||
func (w *FilePicker) Visible() bool { return w.visible }
|
||||
func (w *FilePicker) SetVisible(a bool) { w.visible = a }
|
||||
func (w *FilePicker) SetX(x int) { w.x = x }
|
||||
func (w *FilePicker) SetY(y int) { w.y = y }
|
||||
func (w *FilePicker) GetX() int { return w.x }
|
||||
func (w *FilePicker) GetY() int { return w.y }
|
||||
func (w *FilePicker) GetPos() Coord { return Coord{X: w.x, Y: w.y} }
|
||||
func (w *FilePicker) SetPos(c Coord) { w.x, w.y = c.X, c.Y }
|
||||
func (w *FilePicker) SetW(x int) { w.w = x }
|
||||
func (w *FilePicker) SetH(y int) { w.h = y }
|
||||
func (w *FilePicker) GetW() int { return w.w }
|
||||
func (w *FilePicker) GetH() int { return w.y }
|
||||
func (w *FilePicker) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
|
||||
func (w *FilePicker) Focusable() bool { return w.focusable }
|
||||
func (w *FilePicker) SetTabbable(b bool) { w.tabbable = b }
|
||||
func (w *FilePicker) Tabbable() bool { return w.tabbable }
|
||||
func (w *FilePicker) Active() bool { return w.active }
|
||||
func (w *FilePicker) SetActive(a bool) { w.active = a }
|
||||
func (w *FilePicker) Visible() bool { return w.visible }
|
||||
func (w *FilePicker) SetVisible(a bool) { w.visible = a }
|
||||
func (w *FilePicker) SetX(x int) { w.x = x }
|
||||
func (w *FilePicker) SetY(y int) { w.y = y }
|
||||
func (w *FilePicker) GetX() int { return w.x }
|
||||
func (w *FilePicker) GetY() int { return w.y }
|
||||
func (w *FilePicker) GetPos() Coord { return Coord{X: w.x, Y: w.y} }
|
||||
func (w *FilePicker) SetPos(c Coord) { w.x, w.y = c.X, c.Y }
|
||||
func (w *FilePicker) SetW(x int) { w.w = x }
|
||||
func (w *FilePicker) SetH(y int) { w.h = y }
|
||||
func (w *FilePicker) GetW() int { return w.w }
|
||||
func (w *FilePicker) GetH() int { return w.y }
|
||||
func (w *FilePicker) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
|
||||
func (w *FilePicker) Focusable() bool { return w.focusable }
|
||||
func (w *FilePicker) SetFocusable(b bool) { w.focusable = b }
|
||||
func (w *FilePicker) WantW() int {
|
||||
// borders + the greater of the buttons next to each other or the list width
|
||||
return wh.Max((w.btnSelect.WantW()+w.btnCancel.WantW()), w.fileList.WantW()) + 2
|
||||
|
||||
Reference in New Issue
Block a user