tui/view.go

41 lines
1.3 KiB
Go
Raw Permalink Normal View History

2021-01-10 21:52:29 +01:00
package tui
2022-04-02 13:01:41 +02:00
// View defines the behavior of any element displayable on screen.
2022-04-01 20:10:51 +02:00
// To define custom Views, it is recommended to add ViewTmpl
// as the promoted anonymous field for your custom View struct.
// It implements the View interface with useful default behavior
2021-01-10 21:52:29 +01:00
type View interface {
Events
2022-04-02 13:01:41 +02:00
SetStyle(s Style)
2022-04-01 20:10:51 +02:00
Style() Style
2022-04-02 15:09:52 +02:00
// Layout is usually called by the parent view to ask the view's preferred size.
// If the parent view does not care about its preferred size, it might not be called at all.
// Negative values indicate as much space as possible.
2022-04-02 13:01:41 +02:00
Layout() (prefWidth, prefHeight int)
2022-04-02 15:09:52 +02:00
// Draw is called for each view when it should print itself onto the screen.
// The parent view has full control of the ViewBuffer size
// and may or may not use the values returned from Layout() to set the size.
2022-04-02 13:01:41 +02:00
Draw(buf *ViewBuffer)
2022-04-01 20:10:51 +02:00
}
// Group defines the behavior of a View which can hold multiple sub views
type Group interface {
View
2022-04-02 13:01:41 +02:00
Views() []View
2022-04-01 20:10:51 +02:00
}
2021-01-10 21:52:29 +01:00
2022-04-02 13:01:41 +02:00
// Wrapper defines the behavior of a GroupView which can hold exactly one sub view.
2022-04-01 20:10:51 +02:00
// To define custom Wrappers, it is recommended to add WrapperTmpl
// as the promoted anonymous field for your custom Wrapper struct.
// It implements the Wrapper interface with useful default behavior
type Wrapper interface {
Group
2021-01-10 21:52:29 +01:00
2022-04-01 20:10:51 +02:00
SetView(View)
View() View
2021-01-10 21:52:29 +01:00
}