POC begins

This commit is contained in:
Marcel Otte 2022-11-23 20:33:07 +01:00
parent d3fd8144d6
commit 5bbc0ac046
11 changed files with 223 additions and 4 deletions

View File

@ -11,14 +11,14 @@ builds:
- main: ./cmd/npc/main.go
id: "npc"
binary: npc
env:
- CGO_ENABLED=0
# env:
# - CGO_ENABLED=0
goarch:
- amd64
goos:
- linux
- windows
- darwin
# - windows
# - darwin
archives:
- replacements:
darwin: Darwin

26
app.go Normal file
View File

@ -0,0 +1,26 @@
package npc
import (
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"
)
func Appmain() {
a := app.New()
w := a.NewWindow("Hello")
hello := widget.NewLabel("Hello Fyne!")
w.SetContent(container.NewBorder(
hello,
nil,
nil,
nil,
GetFieldEditor().Representation,
// widget.NewButton("Hi!", func() {
// hello.SetText("Welcome :)")
// }),
))
w.ShowAndRun()
}

9
cmd/npc/main.go Normal file
View File

@ -0,0 +1,9 @@
package main
import (
"gitea.mmo.to/NetworkPacketComposer/npc"
)
func main() {
npc.Appmain()
}

14
field.go Normal file
View File

@ -0,0 +1,14 @@
package npc
type Field struct {
Name string
Desc string
Regex string
ByteSize uint
BitSize uint
}
type FieldValue struct {
FieldRef *Field
Value string
}

16
fieldadd.go Normal file
View File

@ -0,0 +1,16 @@
package npc
import (
"fyne.io/fyne/v2/widget"
)
var fieldAdder *widget.Button
func GetAdder() *widget.Button {
if fieldAdder == nil {
fieldAdder = widget.NewButton("Add Field", func() {
fieldEditor.AddFieldCreator(CreateFieldCreator())
})
}
return fieldAdder
}

42
fieldcreator.go Normal file
View File

@ -0,0 +1,42 @@
package npc
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/widget"
)
type FieldCreator struct {
Representation *fyne.Container
NameValue *widget.Entry
DescValue *widget.Entry
RegExValue *widget.Entry
ByteSizeValue *widget.Entry
BitSizeValue *widget.Entry
// to be filled with needed things
}
func CreateFieldCreator() *FieldCreator {
fc := &FieldCreator{}
fc.Representation = container.New(layout.NewVBoxLayout())
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()
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()
return fc
}

38
fieldeditor.go Normal file
View File

@ -0,0 +1,38 @@
package npc
import (
"fmt"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
)
type FieldEditor struct {
Representation *fyne.Container
Creators []*FieldCreator
}
var fieldEditor *FieldEditor
func GetFieldEditor() *FieldEditor {
if fieldEditor == nil {
container := container.NewGridWrap(fyne.NewSize(200, 150))
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())
}

8
fieldview.go Normal file
View File

@ -0,0 +1,8 @@
package npc
import "fyne.io/fyne/v2/widget"
func CreateView(field Field) *widget.BaseWidget {
return nil
}

63
flowlayout.go Normal file
View File

@ -0,0 +1,63 @@
package npc
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/theme"
)
type FlowLayout struct {
LastKnownParentSize fyne.Size
}
func (fl *FlowLayout) MinSize(objects []fyne.CanvasObject) fyne.Size {
return fyne.NewSize(0, 0)
}
func getMinHeight(objects []fyne.CanvasObject) fyne.Size {
ret := fyne.NewSize(0, 0)
for _, v := range objects {
if v.MinSize().Height > ret.Height {
ret.Height = v.MinSize().Height
}
}
return ret
}
func (fl *FlowLayout) Layout(objects []fyne.CanvasObject, size fyne.Size) {
fl.LastKnownParentSize = size
if fl.LastKnownParentSize.Height > size.Height {
i, x, y := 0, float32(0), float32(0)
lastRowMaxH, lastRowEnd := float32(0), 0
for _, child := range objects {
if !child.Visible() {
continue
}
if i > 1 {
if x+objects[i-1].MinSize().Width > size.Width {
x = 0
y = y + getMinHeight(objects[lastRowEnd:i]).Height
lastRowEnd = i
} else {
x = x + objects[i-1].MinSize().Width
}
}
if i%g.colCount == 0 {
g.rowCount++
}
child.Move(fyne.NewPos(x, y))
child.Resize(g.CellSize)
if (i+1)%g.colCount == 0 {
x = 0
y += g.CellSize.Height + theme.Padding()
} else {
x += g.CellSize.Width + theme.Padding()
}
i++
}
}
}

View File

@ -1 +1,3 @@
go 1.19
use .

1
go.work.sum Normal file
View File

@ -0,0 +1 @@
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1 h1:QbL/5oDUmRBzO9/Z7Seo6zf912W/a6Sr4Eu0G/3Jho0=