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
|
|
|
|
}
|
|
|
|
|
2022-04-03 16:29:01 +02:00
|
|
|
var _ tui.Wrapper = &ConstrainView{}
|
2022-04-02 13:01:41 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|