tui/views/view_frame.go

36 lines
740 B
Go
Raw Permalink Normal View History

2022-04-02 15:09:52 +02:00
package views
2023-04-24 11:55:04 +02:00
import "git.milar.in/milarin/tui"
2022-04-02 15:09:52 +02:00
// 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
2023-04-24 11:41:38 +02:00
DontClearBuffer bool
2022-04-02 15:09:52 +02:00
}
var _ tui.Wrapper = &FrameView{}
2022-04-02 15:09:52 +02:00
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) {
2023-04-24 11:41:38 +02:00
if !g.DontClearBuffer {
g.ViewTmpl.Draw(buf)
}
2022-04-02 15:09:52 +02:00
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
}