2022-10-18 16:58:12 +02:00
|
|
|
package screen
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fyne.io/fyne/v2"
|
2022-10-24 15:57:55 +02:00
|
|
|
"fyne.io/fyne/v2/container"
|
2022-10-18 16:58:12 +02:00
|
|
|
"fyne.io/fyne/v2/data/binding"
|
|
|
|
"fyne.io/fyne/v2/widget"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Log struct {
|
|
|
|
lines binding.StringList
|
2022-10-24 15:57:55 +02:00
|
|
|
root *fyne.Container
|
2022-10-18 16:58:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewLog() *Log {
|
2022-10-24 15:57:55 +02:00
|
|
|
logs := &Log{
|
2022-10-18 16:58:12 +02:00
|
|
|
lines: binding.NewStringList(),
|
|
|
|
}
|
2022-10-24 15:57:55 +02:00
|
|
|
logs.Init()
|
|
|
|
|
|
|
|
return logs
|
2022-10-18 16:58:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (l *Log) Refresh(state State) {
|
2022-10-23 10:25:11 +02:00
|
|
|
l.lines.Set(state.Logs)
|
2022-10-18 16:58:12 +02:00
|
|
|
}
|
|
|
|
|
2022-10-24 15:57:55 +02:00
|
|
|
func (l *Log) Init() {
|
2022-10-18 16:58:12 +02:00
|
|
|
list := widget.NewListWithData(
|
|
|
|
l.lines,
|
|
|
|
func() fyne.CanvasObject {
|
|
|
|
return widget.NewLabel("template")
|
|
|
|
},
|
|
|
|
func(i binding.DataItem, o fyne.CanvasObject) {
|
|
|
|
o.(*widget.Label).Bind(i.(binding.String))
|
|
|
|
},
|
|
|
|
)
|
2022-10-24 15:57:55 +02:00
|
|
|
l.root = container.NewBorder(
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
list,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *Log) Content() *fyne.Container {
|
|
|
|
return l.root
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *Log) Hide() {
|
|
|
|
l.root.Hide()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *Log) Show() {
|
|
|
|
l.root.Show()
|
2022-10-18 16:58:12 +02:00
|
|
|
}
|