ppforge/internal/ui/protocoleditor.go

36 lines
895 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"
"gitea.mmo.to/ProtocolPacketForger/ppf/protocol"
"gitea.mmo.to/ProtocolPacketForger/ppf/protocolctl"
2022-11-24 21:49:10 +01:00
)
type ProtocolEditor struct {
Representation *fyne.Container
Fields []*FieldEditor
2022-11-24 21:49:10 +01:00
Reference *protocol.ProtocolStructure
}
2022-11-24 21:49:10 +01:00
func GetProtocolEditor() *ProtocolEditor {
container := container.NewGridWrap(fyne.NewSize(300, 300))
protocolEditor := &ProtocolEditor{container, []*FieldEditor{}, protocolctl.NewProtocolStructure()}
container.Add(GetAdder(protocolEditor))
2022-11-24 21:49:10 +01:00
return protocolEditor
}
func (ed *ProtocolEditor) AddFieldCreator(fieldCreator *FieldEditor) {
ed.Fields = append(ed.Fields, fieldCreator)
2022-11-24 21:49:10 +01:00
ed.Redraw()
}
func (ed *ProtocolEditor) Redraw() {
ed.Representation.RemoveAll()
for _, v := range ed.Fields {
2022-11-24 21:49:10 +01:00
ed.Representation.Add(v.Representation)
}
ed.Representation.Add(GetAdder(ed))
2022-11-24 21:49:10 +01:00
}