tui/views/frameview.go
Timon Ringwald b797dc0b2c more views
2022-04-02 15:09:52 +02:00

36 lines
760 B
Go

package views
import "git.tordarus.net/Tordarus/tui"
// FrameView is a tui.Wrapper which draws its view preferably with preferred size on its tui.Anchor point
type FrameView struct {
tui.WrapperTmpl
Anchor tui.Anchor
}
var _ tui.View = &FrameView{}
func NewFrameView(view tui.View) *FrameView {
v := new(FrameView)
v.SetView(view)
v.Anchor = tui.AnchorCenter
return v
}
func (g *FrameView) Draw(buf *tui.ViewBuffer) {
g.ViewTmpl.Draw(buf)
w, h := g.View().Layout()
w = iff(w >= 0, w, buf.Width())
h = iff(h >= 0, h, buf.Height())
g.View().Draw(tui.ConstrainBufferToAnchor(buf, g.Anchor, w, h))
}
func (v *FrameView) Layout() (prefWidth, prefHeight int) {
return -1, -1
}
func (v *FrameView) Style() tui.Style {
return v.ViewTmpl.Style()
}