ppforge/internal/ui/fieldeditor.go

60 lines
1.5 KiB
Go
Raw Normal View History

package ui
2022-11-23 20:33:07 +01:00
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/widget"
"gitea.mmo.to/ProtocolPacketForger/ppf/protocol"
2022-11-23 20:33:07 +01:00
)
type FieldEditor struct {
2022-11-23 20:33:07 +01:00
Representation *fyne.Container
NameValue *widget.Entry
DescValue *widget.Entry
RegExValue *widget.Entry
2022-11-24 21:49:10 +01:00
SizeLabel *widget.Label
SizeValue *widget.Entry
SizeInBits bool
2022-11-23 20:33:07 +01:00
// to be filled with needed things
Reference *protocol.Field
2022-11-23 20:33:07 +01:00
}
func CreateFieldEditor() *FieldEditor {
fc := &FieldEditor{}
2022-11-24 21:49:10 +01:00
fc.Representation = container.New(layout.NewFormLayout())
fc.Representation.Add(widget.NewLabel(""))
fc.Representation.Add(widget.NewLabel("Field Values"))
2022-11-23 20:33:07 +01:00
fc.Representation.Add(widget.NewLabel("Name"))
fc.NameValue = widget.NewEntry()
fc.Representation.Add(fc.NameValue)
fc.Representation.Add(widget.NewLabel("Description"))
fc.DescValue = widget.NewEntry()
2022-11-24 21:49:10 +01:00
fc.DescValue.MultiLine = true
fc.DescValue.SetMinRowsVisible(3)
2022-11-23 20:33:07 +01:00
fc.Representation.Add(fc.DescValue)
fc.Representation.Add(widget.NewLabel("RegEx"))
fc.RegExValue = widget.NewEntry()
fc.Representation.Add(fc.RegExValue)
2022-11-24 21:49:10 +01:00
fc.SizeLabel = widget.NewLabel("Bytes")
toggleBtn := widget.NewButton("T", func() {
if fc.SizeInBits {
fc.SizeLabel.SetText("Bytes")
} else {
fc.SizeLabel.SetText("Bits")
}
fc.SizeInBits = !fc.SizeInBits
})
fc.Representation.Add(container.NewHBox(toggleBtn, fc.SizeLabel))
fc.SizeValue = widget.NewEntry()
fc.Representation.Add(fc.SizeValue)
2022-11-23 20:33:07 +01:00
return fc
}