tui/views/constrainview.go

30 lines
589 B
Go
Raw Normal View History

2022-04-02 13:01:41 +02:00
package views
import (
"git.tordarus.net/Tordarus/tui"
)
// ConstrainView is a tui.Wrapper which constrains the dimensions of its View
type ConstrainView struct {
tui.WrapperTmpl
MaxWidth int
MaxHeight int
}
var _ tui.View = &ConstrainView{}
func NewConstrainView(view tui.View) *ConstrainView {
v := new(ConstrainView)
v.SetView(view)
v.Constrain(-1, -1)
return v
}
func (v *ConstrainView) Constrain(maxWidth, maxHeight int) {
v.MaxWidth, v.MaxHeight = maxWidth, maxHeight
}
func (v *ConstrainView) Layout() (prefWidth, prefHeight int) {
return v.MaxWidth, v.MaxHeight
}