tui/tmpl_wrapper.go

58 lines
1019 B
Go
Raw Permalink Normal View History

2022-04-01 20:10:51 +02:00
package tui
type WrapperTmpl struct {
ViewTmpl
view View
}
var _ Wrapper = &WrapperTmpl{}
func (v *WrapperTmpl) Draw(buf *ViewBuffer) {
if v.view != nil {
v.view.Draw(buf)
} else {
v.ViewTmpl.Draw(buf)
}
}
2022-04-02 13:01:41 +02:00
func (v *WrapperTmpl) Layout() (prefWidth, prefHeight int) {
2022-04-01 20:10:51 +02:00
if v.view != nil {
2022-04-02 13:01:41 +02:00
return v.view.Layout()
2022-04-01 20:10:51 +02:00
}
2022-04-02 13:01:41 +02:00
return v.ViewTmpl.Layout()
2022-04-01 20:10:51 +02:00
}
2022-04-02 13:01:41 +02:00
func (v *WrapperTmpl) OnKeyPressed(event *KeyEvent) (consumed bool) {
2022-04-01 20:10:51 +02:00
if v.view != nil {
2022-04-02 13:01:41 +02:00
return v.view.OnKeyPressed(event)
2022-04-01 20:10:51 +02:00
}
2022-04-02 13:01:41 +02:00
return v.ViewTmpl.OnKeyPressed(event)
2022-04-01 20:10:51 +02:00
}
2022-05-04 14:16:08 +02:00
func (v *WrapperTmpl) OnMouseEvent(event *MouseEvent) (consumed bool) {
if v.view != nil {
return v.view.OnMouseEvent(event)
}
return v.ViewTmpl.OnMouseEvent(event)
}
2022-04-02 13:01:41 +02:00
func (v *WrapperTmpl) SetStyle(s Style) {
v.ViewTmpl.SetStyle(s)
2022-04-01 20:10:51 +02:00
}
2022-04-02 13:01:41 +02:00
func (v *WrapperTmpl) Style() Style {
return v.ViewTmpl.Style()
2022-04-01 20:10:51 +02:00
}
2022-04-02 13:01:41 +02:00
func (v *WrapperTmpl) Views() []View {
2022-04-01 20:10:51 +02:00
return []View{v.view}
}
func (v *WrapperTmpl) View() View {
return v.view
}
func (v *WrapperTmpl) SetView(view View) {
v.view = view
}