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/ppForge/ppforge/protocol"
|
|
"gitea.mmo.to/ppForge/ppforge/protocolctl"
|
|
)
|
|
|
|
type ProtocolEditor struct {
|
|
Representation *fyne.Container
|
|
FieldContainer *fyne.Container
|
|
Metadata *ProtocolMetadata
|
|
Fields []*FieldEditor
|
|
|
|
Reference *protocol.ProtocolStructure
|
|
}
|
|
|
|
func NewProtocolEditor(ref *protocol.ProtocolStructure) *ProtocolEditor {
|
|
metadata := NewMetadataProtocol()
|
|
fields := container.NewGridWrap(fyne.NewSize(300, 400))
|
|
container := container.NewBorder(nil, nil, metadata.Representation, nil, container.NewVScroll(fields))
|
|
protocolEditor := &ProtocolEditor{container, fields, metadata, []*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.FieldContainer.RemoveAll()
|
|
// existing fields
|
|
for i, v := range ed.Reference.Structure {
|
|
ed.FieldContainer.Add(CreateFieldEditor(ed, i, v).Representation)
|
|
}
|
|
if len(ed.Reference.Structure) == 0 {
|
|
ed.FieldContainer.Add(GetAdder(ed))
|
|
}
|
|
// Metadata
|
|
ed.Metadata.SetProtocol(ed.Reference)
|
|
}
|