From 5bbc0ac046e73f90dc2a873b9236fb340fddbfa1 Mon Sep 17 00:00:00 2001 From: Marcel Otte Date: Wed, 23 Nov 2022 20:33:07 +0100 Subject: [PATCH] POC begins --- .goreleaser.yml | 8 +++---- app.go | 26 ++++++++++++++++++++ cmd/npc/main.go | 9 +++++++ field.go | 14 +++++++++++ fieldadd.go | 16 +++++++++++++ fieldcreator.go | 42 +++++++++++++++++++++++++++++++++ fieldeditor.go | 38 +++++++++++++++++++++++++++++ fieldview.go | 8 +++++++ flowlayout.go | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ go.work | 2 ++ go.work.sum | 1 + 11 files changed, 223 insertions(+), 4 deletions(-) create mode 100644 app.go create mode 100644 cmd/npc/main.go create mode 100644 field.go create mode 100644 fieldadd.go create mode 100644 fieldcreator.go create mode 100644 fieldeditor.go create mode 100644 fieldview.go create mode 100644 flowlayout.go create mode 100644 go.work.sum diff --git a/.goreleaser.yml b/.goreleaser.yml index a8db3b1..f8db096 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -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 diff --git a/app.go b/app.go new file mode 100644 index 0000000..d2aeb39 --- /dev/null +++ b/app.go @@ -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() +} diff --git a/cmd/npc/main.go b/cmd/npc/main.go new file mode 100644 index 0000000..d6e1e0b --- /dev/null +++ b/cmd/npc/main.go @@ -0,0 +1,9 @@ +package main + +import ( + "gitea.mmo.to/NetworkPacketComposer/npc" +) + +func main() { + npc.Appmain() +} diff --git a/field.go b/field.go new file mode 100644 index 0000000..805b890 --- /dev/null +++ b/field.go @@ -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 +} diff --git a/fieldadd.go b/fieldadd.go new file mode 100644 index 0000000..c0319ed --- /dev/null +++ b/fieldadd.go @@ -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 +} diff --git a/fieldcreator.go b/fieldcreator.go new file mode 100644 index 0000000..abc97b5 --- /dev/null +++ b/fieldcreator.go @@ -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 +} diff --git a/fieldeditor.go b/fieldeditor.go new file mode 100644 index 0000000..11e2786 --- /dev/null +++ b/fieldeditor.go @@ -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()) +} diff --git a/fieldview.go b/fieldview.go new file mode 100644 index 0000000..9de3869 --- /dev/null +++ b/fieldview.go @@ -0,0 +1,8 @@ +package npc + +import "fyne.io/fyne/v2/widget" + +func CreateView(field Field) *widget.BaseWidget { + + return nil +} diff --git a/flowlayout.go b/flowlayout.go new file mode 100644 index 0000000..8162bb2 --- /dev/null +++ b/flowlayout.go @@ -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++ + } + } +} diff --git a/go.work b/go.work index c4110bc..52a3b7c 100644 --- a/go.work +++ b/go.work @@ -1 +1,3 @@ go 1.19 + +use . diff --git a/go.work.sum b/go.work.sum new file mode 100644 index 0000000..806de33 --- /dev/null +++ b/go.work.sum @@ -0,0 +1 @@ +github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1 h1:QbL/5oDUmRBzO9/Z7Seo6zf912W/a6Sr4Eu0G/3Jho0=