2023-04-11 16:05:24 +02:00
|
|
|
package ui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fyne.io/fyne/v2"
|
|
|
|
"fyne.io/fyne/v2/container"
|
|
|
|
"fyne.io/fyne/v2/widget"
|
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
|
|
|
)
|
|
|
|
|
|
|
|
type PacketFieldEditor struct {
|
|
|
|
Representation *fyne.Container
|
|
|
|
Value *widget.Entry
|
|
|
|
|
|
|
|
Reference *packet.FieldValue
|
|
|
|
|
|
|
|
GlobalIndex int
|
2023-04-12 15:14:19 +02:00
|
|
|
LayerIndex int
|
2023-04-11 16:05:24 +02:00
|
|
|
Index int
|
|
|
|
}
|
|
|
|
|
|
|
|
func CreatePacketFieldEditor(
|
|
|
|
ed *PacketEditor,
|
|
|
|
gblidx int,
|
|
|
|
lyridx int,
|
|
|
|
index int,
|
|
|
|
ref *packet.FieldValue,
|
|
|
|
) *PacketFieldEditor {
|
|
|
|
pfe := &PacketFieldEditor{}
|
|
|
|
pfe.Reference = ref
|
|
|
|
pfe.Index = index
|
2023-04-12 15:14:19 +02:00
|
|
|
pfe.LayerIndex = lyridx
|
2023-04-11 16:05:24 +02:00
|
|
|
pfe.GlobalIndex = gblidx
|
|
|
|
|
|
|
|
setfunc := func(s string) {
|
|
|
|
//todo
|
|
|
|
packetctl.UpdateField(&ed.Reference.Layers[lyridx], index, packetctl.NewFieldValue(s))
|
|
|
|
}
|
|
|
|
|
|
|
|
elements := []fyne.CanvasObject{}
|
|
|
|
|
|
|
|
elements = append(elements, widget.NewLabel(ref.GetProtocolField().Name))
|
|
|
|
if ed.ShowShortHints {
|
|
|
|
elements = append(elements, widget.NewLabel(ref.GetProtocolField().Regex)) // todo: implement real shorthints if feasible
|
|
|
|
}
|
|
|
|
|
|
|
|
// depending on the input stuff, entry for now
|
|
|
|
pfe.Value = widget.NewEntry()
|
|
|
|
pfe.Value.OnChanged = setfunc
|
|
|
|
|
|
|
|
elements = append(elements, pfe.Value)
|
|
|
|
|
|
|
|
pfe.Representation = container.NewHBox(elements...)
|
|
|
|
return pfe
|
|
|
|
}
|