ppforge/internal/ui/protocoleditor.go

42 lines
1.0 KiB
Go
Raw Normal View History

package ui
2022-11-24 21:49:10 +01:00
import (
"fmt"
2022-11-24 21:49:10 +01:00
"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, 400))
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() {
json := protocolctl.ToJson(ed.Reference)
fmt.Printf("%s", json)
2022-11-24 21:49:10 +01:00
ed.Representation.RemoveAll()
for i, v := range ed.Reference.Structure {
ed.Representation.Add(CreateFieldEditor(ed, i, v).Representation)
}
if len(ed.Reference.Structure) == 0 {
ed.Representation.Add(GetAdder(ed))
2022-11-24 21:49:10 +01:00
}
}