diff --git a/app.go b/app.go index 8509d45..d10de80 100644 --- a/app.go +++ b/app.go @@ -1,6 +1,7 @@ package npc import ( + "fyne.io/fyne/v2" "fyne.io/fyne/v2/app" "fyne.io/fyne/v2/container" "fyne.io/fyne/v2/widget" @@ -9,6 +10,7 @@ import ( func Appmain() { a := app.New() w := a.NewWindow("Hello") + w.Resize(fyne.NewSize(800, 600)) hello := widget.NewLabel("Hello Fyne!") w.SetContent(container.NewBorder( @@ -16,7 +18,7 @@ func Appmain() { nil, nil, nil, - container.NewVScroll(GetFieldEditor().Representation), + container.NewVScroll(GetProtocolEditor().Representation), // widget.NewButton("Hi!", func() { // hello.SetText("Welcome :)") // }), diff --git a/controller.go b/controller.go new file mode 100644 index 0000000..548fb8c --- /dev/null +++ b/controller.go @@ -0,0 +1,27 @@ +package npc + +func NewDataModel(name string) *DataModel { + return &DataModel{ + Name: name, + } +} + +func (dm *DataModel) AddProtocol(name string) { + +} + +func (dm *DataModel) RemoveProtocolByName(name string) { + +} + +func (dm *DataModel) RemoveProtocolElement(id uint) { + +} + +func (dm *DataModel) NewProtocol(name string) { + +} + +func (dm *DataModel) SaveNewProtocol(editorContent ProtocolEditor) { + +} diff --git a/field.go b/field.go deleted file mode 100644 index 805b890..0000000 --- a/field.go +++ /dev/null @@ -1,14 +0,0 @@ -package npc - -type Field struct { - Name string - Desc string - Regex string - ByteSize uint - BitSize uint -} - -type FieldValue struct { - FieldRef *Field - Value string -} diff --git a/fieldadd.go b/fieldadd.go index c0319ed..a4e7c99 100644 --- a/fieldadd.go +++ b/fieldadd.go @@ -9,7 +9,7 @@ var fieldAdder *widget.Button func GetAdder() *widget.Button { if fieldAdder == nil { fieldAdder = widget.NewButton("Add Field", func() { - fieldEditor.AddFieldCreator(CreateFieldCreator()) + protocolEditor.AddFieldCreator(CreateFieldCreator()) }) } return fieldAdder diff --git a/fieldcreator.go b/fieldcreator.go index abc97b5..05b4873 100644 --- a/fieldcreator.go +++ b/fieldcreator.go @@ -12,14 +12,18 @@ type FieldCreator struct { NameValue *widget.Entry DescValue *widget.Entry RegExValue *widget.Entry - ByteSizeValue *widget.Entry - BitSizeValue *widget.Entry + SizeLabel *widget.Label + SizeValue *widget.Entry + SizeInBits bool // to be filled with needed things } func CreateFieldCreator() *FieldCreator { fc := &FieldCreator{} - fc.Representation = container.New(layout.NewVBoxLayout()) + fc.Representation = container.New(layout.NewFormLayout()) + + fc.Representation.Add(widget.NewLabel("")) + fc.Representation.Add(widget.NewLabel("Field Values")) fc.Representation.Add(widget.NewLabel("Name")) fc.NameValue = widget.NewEntry() @@ -27,16 +31,26 @@ func CreateFieldCreator() *FieldCreator { fc.Representation.Add(widget.NewLabel("Description")) fc.DescValue = widget.NewEntry() + fc.DescValue.MultiLine = true + fc.DescValue.SetMinRowsVisible(3) fc.Representation.Add(fc.DescValue) fc.Representation.Add(widget.NewLabel("RegEx")) fc.RegExValue = widget.NewEntry() fc.Representation.Add(fc.RegExValue) - fc.Representation.Add(widget.NewLabel("ByteSize")) - fc.ByteSizeValue = widget.NewEntry() - fc.Representation.Add(fc.ByteSizeValue) - // add that later - fc.BitSizeValue = widget.NewEntry() + 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) return fc } diff --git a/fieldeditor.go b/fieldeditor.go deleted file mode 100644 index 1a80036..0000000 --- a/fieldeditor.go +++ /dev/null @@ -1,37 +0,0 @@ -package npc - -import ( - "fmt" - - "fyne.io/fyne/v2" -) - -type FieldEditor struct { - Representation *fyne.Container - Creators []*FieldCreator -} - -var fieldEditor *FieldEditor - -func GetFieldEditor() *FieldEditor { - if fieldEditor == nil { - container := NewFlowLayout() - fieldEditor = &FieldEditor{container, []*FieldCreator{}} - container.Add(GetAdder()) - } - return fieldEditor -} - -func (ed *FieldEditor) AddFieldCreator(fieldCreator *FieldCreator) { - ed.Creators = append(fieldEditor.Creators, fieldCreator) - ed.Redraw() -} - -func (ed *FieldEditor) Redraw() { - ed.Representation.RemoveAll() - for _, v := range ed.Creators { - ed.Representation.Add(v.Representation) - fmt.Printf("Minsize: %f, %f", v.Representation.MinSize().Height, v.Representation.MinSize().Width) - } - ed.Representation.Add(GetAdder()) -} diff --git a/flowlayout.go b/flowlayout.go index aa89c5e..4e63168 100644 --- a/flowlayout.go +++ b/flowlayout.go @@ -2,7 +2,6 @@ package npc import ( "fyne.io/fyne/v2" - "fyne.io/fyne/v2/container" "fyne.io/fyne/v2/theme" ) @@ -11,9 +10,9 @@ type FlowLayout struct { LastMinDimensions fyne.Size } -func NewFlowLayout(o ...fyne.CanvasObject) *fyne.Container { +func NewFlowLayout(o ...fyne.CanvasObject) fyne.Layout { f := &FlowLayout{} - return container.New(f, o...) + return f } // MinSize is a kind of boogie function for the flow layout. diff --git a/go.mod b/go.mod index 49e1a7c..b04f4c0 100644 --- a/go.mod +++ b/go.mod @@ -2,10 +2,7 @@ module gitea.mmo.to/NetworkPacketComposer/npc go 1.19 -require ( - fyne.io/fyne/v2 v2.2.4 - github.com/magiconair/properties v1.8.5 -) +require fyne.io/fyne/v2 v2.2.4 require ( fyne.io/systray v1.10.1-0.20220621085403-9a2652634e93 // indirect @@ -21,6 +18,7 @@ require ( github.com/goki/freetype v0.0.0-20181231101311-fa8a33aabaff // indirect github.com/gopherjs/gopherjs v1.17.2 // indirect github.com/jsummers/gobmp v0.0.0-20151104160322-e2ba15ffa76e // indirect + github.com/lucasb-eyer/go-colorful v1.2.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/srwiley/oksvg v0.0.0-20200311192757-870daf9aa564 // indirect github.com/srwiley/rasterx v0.0.0-20200120212402-85cb7272f5e9 // indirect diff --git a/go.sum b/go.sum index 84daf77..bd9bc42 100644 --- a/go.sum +++ b/go.sum @@ -207,8 +207,9 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= +github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/lucor/goinfo v0.0.0-20210802170112-c078a2b0f08b/go.mod h1:PRq09yoB+Q2OJReAmwzKivcYyremnibWGbK7WfftHzc= -github.com/magiconair/properties v1.8.5 h1:b6kJs+EmPFMYGkow9GiUyCyOvIwYetYJ3fSaWak/Gls= github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= diff --git a/protocoleditor.go b/protocoleditor.go new file mode 100644 index 0000000..885faf2 --- /dev/null +++ b/protocoleditor.go @@ -0,0 +1,35 @@ +package npc + +import ( + "fyne.io/fyne/v2" + "fyne.io/fyne/v2/container" +) + +type ProtocolEditor struct { + Representation *fyne.Container + Creators []*FieldCreator +} + +var protocolEditor *ProtocolEditor + +func GetProtocolEditor() *ProtocolEditor { + if protocolEditor == nil { + container := container.NewGridWrap(fyne.NewSize(300, 300)) + protocolEditor = &ProtocolEditor{container, []*FieldCreator{}} + container.Add(GetAdder()) + } + return protocolEditor +} + +func (ed *ProtocolEditor) AddFieldCreator(fieldCreator *FieldCreator) { + ed.Creators = append(protocolEditor.Creators, fieldCreator) + ed.Redraw() +} + +func (ed *ProtocolEditor) Redraw() { + ed.Representation.RemoveAll() + for _, v := range ed.Creators { + ed.Representation.Add(v.Representation) + } + ed.Representation.Add(GetAdder()) +} diff --git a/structure.go b/structure.go new file mode 100644 index 0000000..bec90eb --- /dev/null +++ b/structure.go @@ -0,0 +1,45 @@ +package npc + +type Field struct { + Name string // Name of the Field + Desc string // Lengthy description + Regex string // Regex to recognize values + Size uint // Size in bits! + SubFields []Field // Possible sub-fields + Optional bool // Is this field required? + Payload bool // Is this field the payload or next protocol level? + PredefinedValues []PredefinedFieldValue // Collection of predefined field values +} + +type PredefinedFieldValue struct { + Desc string + FieldValues []FieldValue +} + +type FieldValue struct { + FieldRef *Field + Value string +} + +type ProtocolStructure struct { + Metadata DOPMetadata + Structure []Field +} + +type DOPMetadata struct { + DOPVersion string + Name string + Version string + TCPIPLayer uint + OSILayer uint + ExtensionTo string + Description string + RequiredJSFunctions []string + LowerLayerIdentification map[string]string +} + +type DataModel struct { + Name string // User defined name of his current work (filename later) + Protocols []ProtocolStructure // List of protocols in order of the stack + Data []FieldValue // Data of the fields of all protocols +}