ppforge/internal/ui/packeteditor.go

48 lines
1.1 KiB
Go
Raw Normal View History

package ui
2023-04-11 16:05:24 +02:00
import (
"fmt"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
2023-05-12 09:10:24 +02:00
"gitea.mmo.to/ppForge/ppforge/packet"
"gitea.mmo.to/ppForge/ppforge/packetctl"
2023-04-11 16:05:24 +02:00
)
2022-11-25 11:36:29 +01:00
type PacketEditor struct {
Representation *fyne.Container
2023-04-11 16:05:24 +02:00
FieldContainer *fyne.Container
Metadata *PacketMetadata
Fields []*PacketFieldEditor
ShowShortHints bool
2023-04-12 15:14:19 +02:00
Reference *packet.Structure
2023-04-11 16:05:24 +02:00
}
2023-04-12 15:14:19 +02:00
func NewPacketEditor(ref *packet.Structure) *PacketEditor {
2023-04-11 16:05:24 +02:00
metadata := NewMetadataPacket()
fields := container.NewGridWrap(fyne.NewSize(300, 200))
container := container.NewBorder(nil, nil, metadata.Representation, nil, container.NewVScroll(fields))
packetEditor := &PacketEditor{container, fields, metadata, []*PacketFieldEditor{}, false, ref}
packetEditor.Redraw()
return packetEditor
}
func (ed *PacketEditor) Redraw() {
json := packetctl.ToJson(ed.Reference)
fmt.Printf("%s\n", json)
ed.FieldContainer.RemoveAll()
// existing fields
k := 0
for i, v := range ed.Reference.Layers {
for j, vv := range v.Values {
ed.FieldContainer.Add(CreatePacketFieldEditor(ed, k, i, j, &vv).Representation)
k++
}
}
// metadata
//ed.Metadata.SetPacket(ed.Reference)
}