2023-01-03 13:34:32 +01:00
|
|
|
package ui
|
2022-11-24 21:49:10 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fyne.io/fyne/v2"
|
|
|
|
"fyne.io/fyne/v2/container"
|
2023-01-03 15:44:52 +01:00
|
|
|
"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
|
2023-01-03 15:44:52 +01:00
|
|
|
Fields []*FieldEditor
|
2022-11-24 21:49:10 +01:00
|
|
|
|
2023-01-03 15:44:52 +01:00
|
|
|
Reference *protocol.ProtocolStructure
|
|
|
|
}
|
2022-11-24 21:49:10 +01:00
|
|
|
|
|
|
|
func GetProtocolEditor() *ProtocolEditor {
|
2023-01-03 15:44:52 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2023-01-03 15:44:52 +01:00
|
|
|
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()
|
2023-01-03 15:44:52 +01:00
|
|
|
for _, v := range ed.Fields {
|
2022-11-24 21:49:10 +01:00
|
|
|
ed.Representation.Add(v.Representation)
|
|
|
|
}
|
2023-01-03 15:44:52 +01:00
|
|
|
ed.Representation.Add(GetAdder(ed))
|
2022-11-24 21:49:10 +01:00
|
|
|
}
|