ppforge/internal/ui/packetfieldeditor.go

56 lines
1.2 KiB
Go

package ui
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"
"gitea.mmo.to/ppForge/ppforge/packet"
"gitea.mmo.to/ppForge/ppforge/packetctl"
)
type PacketFieldEditor struct {
Representation *fyne.Container
Value *widget.Entry
Reference *packet.FieldValue
GlobalIndex int
LayerIndex int
Index int
}
func CreatePacketFieldEditor(
ed *PacketEditor,
gblidx int,
lyridx int,
index int,
ref *packet.FieldValue,
) *PacketFieldEditor {
pfe := &PacketFieldEditor{}
pfe.Reference = ref
pfe.Index = index
pfe.LayerIndex = lyridx
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
}