ppforge/protocoleditor.go

36 lines
791 B
Go
Raw Normal View History

2022-11-24 21:49:10 +01:00
package npc
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())
}