2022-04-02 15:09:52 +02:00
|
|
|
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
|
2023-04-24 11:41:38 +02:00
|
|
|
|
|
|
|
DontClearBuffer bool
|
2022-04-02 15:09:52 +02:00
|
|
|
}
|
|
|
|
|
2022-04-03 16:29:01 +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
|
|
|
|
}
|