Checkpoint
This commit is contained in:
223 files changed
+14770
-18352
No files matched your search
@@ -0,0 +1,72 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user