49 lines
1.3 KiB
Go
49 lines
1.3 KiB
Go
package ui
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"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, 400))
|
|
protocolEditor := &ProtocolEditor{container, []*FieldEditor{}, protocolctl.NewProtocolStructure()}
|
|
container.Add(GetAdder(protocolEditor))
|
|
return protocolEditor
|
|
}
|
|
|
|
func NewProtocolEditor(ref *protocol.ProtocolStructure) *ProtocolEditor {
|
|
container := container.NewGridWrap(fyne.NewSize(300, 400))
|
|
protocolEditor := &ProtocolEditor{container, []*FieldEditor{}, ref}
|
|
protocolEditor.Redraw()
|
|
return protocolEditor
|
|
}
|
|
|
|
func (ed *ProtocolEditor) AddFieldCreator(fieldCreator *FieldEditor) {
|
|
ed.Fields = append(ed.Fields, fieldCreator)
|
|
ed.Redraw()
|
|
}
|
|
|
|
func (ed *ProtocolEditor) Redraw() {
|
|
json := protocolctl.ToJson(ed.Reference)
|
|
fmt.Printf("%s", json)
|
|
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))
|
|
}
|
|
}
|