Really figuring some things out
This commit is contained in:
15
widget.go
15
widget.go
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user