ppforge/internal/ui/protocoleditor.go

36 lines
895 B
Go

package ui
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"gitea.mmo.to/ProtocolPacketForger/ppf/protocol"
"gitea.mmo.to/ProtocolPacketForger/ppf/protocolctl"
)
type ProtocolEditor struct {
Representation *fyne.Container
Fields []*FieldEditor
Reference *protocol.ProtocolStructure
}
func GetProtocolEditor() *ProtocolEditor {
container := container.NewGridWrap(fyne.NewSize(300, 300))
protocolEditor := &ProtocolEditor{container, []*FieldEditor{}, protocolctl.NewProtocolStructure()}
container.Add(GetAdder(protocolEditor))
return protocolEditor
}
func (ed *ProtocolEditor) AddFieldCreator(fieldCreator *FieldEditor) {
ed.Fields = append(ed.Fields, fieldCreator)
ed.Redraw()
}
func (ed *ProtocolEditor) Redraw() {
ed.Representation.RemoveAll()
for _, v := range ed.Fields {
ed.Representation.Add(v.Representation)
}
ed.Representation.Add(GetAdder(ed))
}