So much work

This commit is contained in:
2025-08-06 16:15:08 -05:00
parent 1474caffaa
commit 81c7ec8324
20 changed files with 1386 additions and 376 deletions

View File

@@ -36,6 +36,7 @@ type FilePicker struct {
active bool
visible bool
focusable bool
tabbable bool
x, y int
w, h int
@@ -44,6 +45,8 @@ type FilePicker struct {
path string
wrkDir *os.File
layout *RelativeLayout
fileList *List
btnSelect, btnCancel *Button
}
@@ -59,13 +62,21 @@ func NewFilePicker(id string, style tcell.Style) *FilePicker {
func (w *FilePicker) Init(id string, style tcell.Style) {
w.id = id
w.style = style
w.layout = NewRelativeLayout(fmt.Sprintf("%s-layout", id), style)
w.btnSelect = NewButton(fmt.Sprintf("%s-select", id), style)
w.btnSelect.SetLabel("Select")
w.layout.Add(w.btnSelect, nil, RelAncBR)
w.btnCancel = NewButton(fmt.Sprintf("%s-cancel", id), style)
w.btnCancel.SetLabel("Cancel")
w.layout.Add(w.btnCancel, nil, RelAncBL)
w.tabbable = true
}
func (w *FilePicker) Id() string { return w.id }
func (w *FilePicker) HandleResize(ev *tcell.EventResize) {
w.w, w.h = ev.Size()
// ww, wh := w.w-2, w.h-2 // Trim border space
w.btnSelect.SetPos(Coord{X: w.x + w.w - w.btnSelect.WantW(), Y: w.y + w.h - 1})
w.btnCancel.SetPos(Coord{X: w.x + 1, Y: w.y + w.h - 1})
}
@@ -91,21 +102,24 @@ func (w *FilePicker) Draw(screen tcell.Screen) {
w.btnSelect.Draw(screen)
w.btnCancel.Draw(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) 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) 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) 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
@@ -116,6 +130,14 @@ func (w *FilePicker) WantH() int {
return 2 + w.fileList.WantH() + w.btnSelect.WantH()
}
func (w *FilePicker) MinW() int {
return 2 + w.fileList.MinW() + w.btnSelect.MinW() + w.btnCancel.MinW()
}
func (w *FilePicker) MinH() int {
return 2 + w.fileList.MinH() + w.btnSelect.MinH()
}
func (w *FilePicker) SetTitle(ttl string) { w.title = ttl }
func (w *FilePicker) SetPath(path string) error {
var err error