ppforge/internal/ui/protocoleditor.go

36 lines
790 B
Go
Raw Normal View History

package ui
2022-11-24 21:49:10 +01:00
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
)
type ProtocolEditor struct {
Representation *fyne.Container
Creators []*FieldCreator
}
var protocolEditor *ProtocolEditor
func GetProtocolEditor() *ProtocolEditor {
if protocolEditor == nil {
container := container.NewGridWrap(fyne.NewSize(300, 300))
protocolEditor = &ProtocolEditor{container, []*FieldCreator{}}
container.Add(GetAdder())
}
return protocolEditor
}
func (ed *ProtocolEditor) AddFieldCreator(fieldCreator *FieldCreator) {
ed.Creators = append(protocolEditor.Creators, fieldCreator)
ed.Redraw()
}
func (ed *ProtocolEditor) Redraw() {
ed.Representation.RemoveAll()
for _, v := range ed.Creators {
ed.Representation.Add(v.Representation)
}
ed.Representation.Add(GetAdder())
}