30 lines
589 B
Go
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
|
||
|
}
|