bunch of sceleton stuff

This commit is contained in:
Marcel Otte 2022-11-24 21:49:10 +01:00
parent a1defca772
commit d029df645e
11 changed files with 139 additions and 69 deletions

4
app.go
View File

@ -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 :)")
// }),

27
controller.go Normal file
View File

@ -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) {
}

View File

@ -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
}

View File

@ -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

View File

@ -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
}

View File

@ -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())
}

View File

@ -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.

6
go.mod
View File

@ -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

3
go.sum
View File

@ -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=

35
protocoleditor.go Normal file
View File

@ -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())
}

45
structure.go Normal file
View File

@ -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
}