tui/views/view_constrain.go
2022-04-02 17:16:51 +02:00

30 lines
589 B
Go

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
}