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

67
text.go
View File

@@ -22,17 +22,20 @@ THE SOFTWARE.
package widgets
import (
"strings"
h "git.bullercodeworks.com/brian/tcell-widgets/helpers"
"github.com/gdamore/tcell"
)
type Text struct {
id string
text string
style tcell.Style
x, y int
w, h int
visible bool
id string
text string
style tcell.Style
x, y int
w, h int
visible bool
tabbable bool
}
var _ Widget = (*Text)(nil)
@@ -47,6 +50,7 @@ func (w *Text) Init(id string, style tcell.Style) {
w.id = id
w.style = style
w.visible = true
w.tabbable = false
}
func (w *Text) Id() string { return w.id }
func (w *Text) HandleResize(ev *tcell.EventResize) {}
@@ -56,25 +60,40 @@ func (w *Text) Draw(screen tcell.Screen) {
if !w.visible {
return
}
h.DrawText(w.x, w.y, w.text, w.style, screen)
var pts []string
if w.w < len(w.text) {
pts = strings.Split(h.WrapText(w.text, w.w), "\n")
} else {
pts = []string{w.text}
}
y := w.y
for i := range pts {
h.DrawText(w.x, y, pts[i], w.style, screen)
y++
}
}
func (w *Text) Active() bool { return false }
func (w *Text) SetActive(a bool) {}
func (w *Text) Visible() bool { return w.visible }
func (w *Text) SetVisible(a bool) { w.visible = a }
func (w *Text) SetX(x int) { w.x = x }
func (w *Text) SetY(y int) { w.y = y }
func (w *Text) GetX() int { return w.x }
func (w *Text) GetY() int { return w.y }
func (w *Text) SetPos(c Coord) { w.x, w.y = c.X, c.Y }
func (w *Text) SetW(x int) { w.w = x }
func (w *Text) SetH(y int) { w.h = y }
func (w *Text) GetW() int { return w.w }
func (w *Text) GetH() int { return w.y }
func (w *Text) WantW() int { return h.Max(w.w, len(w.text)) }
func (w *Text) WantH() int { return h.Max(w.h, 1) }
func (w *Text) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
func (w *Text) Focusable() bool { return false }
func (w *Text) Active() bool { return false }
func (w *Text) SetActive(a bool) {}
func (w *Text) Visible() bool { return w.visible }
func (w *Text) SetVisible(a bool) { w.visible = a }
func (w *Text) SetX(x int) { w.x = x }
func (w *Text) SetY(y int) { w.y = y }
func (w *Text) GetX() int { return w.x }
func (w *Text) GetY() int { return w.y }
func (w *Text) GetPos() Coord { return Coord{X: w.x, Y: w.y} }
func (w *Text) SetPos(c Coord) { w.x, w.y = c.X, c.Y }
func (w *Text) SetW(x int) { w.w = x }
func (w *Text) SetH(y int) { w.h = y }
func (w *Text) GetW() int { return w.w }
func (w *Text) GetH() int { return w.y }
func (w *Text) WantW() int { return h.Max(w.w, len(w.text)) }
func (w *Text) WantH() int { return h.Max(w.h, 1) }
func (w *Text) SetSize(c Coord) { w.w, w.h = c.X, c.Y }
func (w *Text) Focusable() bool { return false }
func (w *Text) SetTabbable(b bool) { w.tabbable = b }
func (w *Text) Tabbable() bool { return w.tabbable }
func (w *Text) MinW() int { return len(w.text) }
func (w *Text) MinH() int { return 1 }
func (w *Text) SetText(txt string) { w.text = txt }
func (w *Text) GetText() string { return w.text }