Really figuring some things out

This commit is contained in:
2025-08-07 11:18:03 -05:00
parent 7c96fbb187
commit b476c74683
23 changed files with 737 additions and 249 deletions

View File

@@ -26,8 +26,9 @@ import "github.com/gdamore/tcell"
type Widget interface {
Init(string, tcell.Style)
Id() string
// HandleResize sets things up to be drawn based on the width and height
// given to it through SetW & SetH
// HandleResize receives a resize event from the parent with the amount of
// space available to the widget.
// If there is not enough space, the widget is allowed to freak out.
HandleResize(*tcell.EventResize)
HandleKey(*tcell.EventKey) bool
HandleTime(*tcell.EventTime)
@@ -46,20 +47,22 @@ type Widget interface {
GetY() int
GetPos() Coord
SetPos(Coord)
SetSize(Coord)
// Whatever is managing this widget (parent widget, screen, etc) should
// tell it exactly what the Width & Height are.
// It _should_ try to base this off of WantW & WantH
// It _should_ try to base this off of WantW/WantH & MinW/MinH
SetW(int)
SetH(int)
GetW() int
GetH() int
// Given infinite space, WantW & WantH are what this widget wants
// This should reflect the current state of the widget, not potential
WantW() int
WantH() int
// MinW & MinH are what this widget must have to be functional.
// This should reflect the current state of the widget, not potential
MinW() int
MinH() int
SetSize(Coord)
}
func WidgetBottom(w Widget) int {
@@ -81,6 +84,10 @@ func (p *Coord) Add(o Coord) Coord {
}
}
func (p *Coord) ResizeEvent() *tcell.EventResize {
return tcell.NewEventResize(p.X, p.Y)
}
// To validate that a struct satisfies this interface, you can do:
// var _ Widget - (*<struct>)(nil)
// where <struct> is the actual struct that you're validating.