73 lines
1.4 KiB
Go
73 lines
1.4 KiB
Go
package layout
|
|
|
|
import (
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"github.com/BeatGlow/beatglow/app"
|
|
)
|
|
|
|
type base struct {
|
|
name string
|
|
widgets []app.Widget
|
|
visible bool
|
|
onButtonPress func(app.Context)
|
|
onButtonLongPress func(app.Context)
|
|
}
|
|
|
|
func (l *base) log() *logrus.Entry {
|
|
return logrus.WithField("layout", l.name)
|
|
}
|
|
|
|
func (l *base) String() string {
|
|
return l.name
|
|
}
|
|
|
|
func (l *base) Widgets() []app.Widget {
|
|
return l.widgets
|
|
}
|
|
|
|
func (l *base) IsVisible() bool {
|
|
return l.visible
|
|
}
|
|
|
|
func (l *base) Hide(ctx app.Context) {
|
|
log := l.log()
|
|
log.Debug("hide")
|
|
for _, widget := range l.widgets {
|
|
log.WithField("widget", widget.String()).Debug("hide widget")
|
|
_ = widget.Hide(ctx)
|
|
}
|
|
l.visible = false
|
|
}
|
|
|
|
func (l *base) Show(ctx app.Context) {
|
|
log := l.log()
|
|
log.Debug("show")
|
|
ctx.Display().Clear()
|
|
for _, widget := range l.widgets {
|
|
log.WithField("widget", widget.String()).Debug("show widget")
|
|
_ = widget.Show(ctx)
|
|
}
|
|
l.visible = true
|
|
}
|
|
|
|
func (i *base) OnButtonPress(action func(app.Context)) {
|
|
i.onButtonPress = action
|
|
}
|
|
|
|
func (i *base) OnButtonLongPress(action func(app.Context)) {
|
|
i.onButtonLongPress = action
|
|
}
|
|
|
|
func (l *base) HandleButtonPress(ctx app.Context) {
|
|
if l.onButtonPress != nil {
|
|
l.onButtonPress(ctx)
|
|
}
|
|
}
|
|
|
|
func (l *base) HandleButtonLongPress(ctx app.Context) {
|
|
if l.onButtonLongPress != nil {
|
|
l.onButtonLongPress(ctx)
|
|
}
|
|
}
|