Skip to content

Commit

Permalink
Fix Go/JSON serialising
Browse files Browse the repository at this point in the history
We need to find a better approach to the 100ms delay to un-swizzle the icon/button icon resources
  • Loading branch information
andydotxyz committed Nov 7, 2023
1 parent 77a40cd commit 64b0bf0
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 85 deletions.
20 changes: 11 additions & 9 deletions internal/guibuilder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,29 +101,31 @@ func (b *Builder) Run() {

// Save will trigger the current state to be written out to the file this was opened from.
func (b *Builder) Save() error {
w, err := storage.Writer(b.uri)
goFile := strings.ReplaceAll(b.uri.Name(), ".gui.json", ".gui.go")
dir, _ := storage.Parent(b.uri)

goURI, err := storage.Child(dir, goFile)
if err != nil {
return err
}
err = b.save(w)

w, err := storage.Writer(goURI)
if err != nil {
return err
}
err = gui.ExportGo(b.root, b.meta, w)

goFile := strings.ReplaceAll(w.URI().Name(), ".gui.json", ".gui.go")
dir, _ := storage.Parent(w.URI())
goURI, err := storage.Child(dir, goFile)
_ = w.Close()

w, err = storage.Writer(b.uri)
if err != nil {
return err
}

w, err = storage.Writer(goURI)
err = b.save(w)
if err != nil {
return err
}
err = gui.ExportGo(b.root, b.meta, w)

_ = w.Close()
return err
}

Expand Down
15 changes: 8 additions & 7 deletions internal/guidefs/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
type layoutInfo struct {
Create func(*fyne.Container, map[string]string) fyne.Layout
Edit func(*fyne.Container, map[string]string) []*widget.FormItem
goText func(*fyne.Container, map[fyne.CanvasObject]map[string]string) string
goText func(*fyne.Container, map[fyne.CanvasObject]map[string]string, map[string]string) string
}

var (
Expand Down Expand Up @@ -139,7 +139,7 @@ var (
widget.NewFormItem("Right", right),
}
},
func(c *fyne.Container, props map[fyne.CanvasObject]map[string]string) string {
func(c *fyne.Container, props map[fyne.CanvasObject]map[string]string, defs map[string]string) string {
topNum := props[c]["top"]
topID, _ := strconv.Atoi(topNum)
bottomNum := props[c]["bottom"]
Expand Down Expand Up @@ -180,7 +180,7 @@ var (
goStringOrNil(t), goStringOrNil(b), goStringOrNil(l), goStringOrNil(r)))
writeGoString(str, func(o fyne.CanvasObject) bool {
return o == t || o == b || o == l || o == r
}, props, c.Objects...)
}, props, defs, c.Objects...)
str.WriteString(")")
return str.String()
},
Expand Down Expand Up @@ -259,7 +259,7 @@ var (
widget.NewFormItem("Arrange in", vert),
}
},
func(c *fyne.Container, props map[fyne.CanvasObject]map[string]string) string {
func(c *fyne.Container, props map[fyne.CanvasObject]map[string]string, defs map[string]string) string {
rowCol := props[c]["grid_type"]
if rowCol == "" {
rowCol = "Columns"
Expand All @@ -280,7 +280,7 @@ var (
} else {
str.WriteString(fmt.Sprintf("container.NewGridWithColumns(%d, ", num))
}
writeGoString(str, nil, props, c.Objects...)
writeGoString(str, nil, props, defs, c.Objects...)
str.WriteString(")")
return str.String()
},
Expand Down Expand Up @@ -411,7 +411,8 @@ func goStringOrNil(o fyne.CanvasObject) string {
return fmt.Sprintf("%#v", o)
}

func writeGoString(str *strings.Builder, skip func(object fyne.CanvasObject) bool, props map[fyne.CanvasObject]map[string]string, objs ...fyne.CanvasObject) {
func writeGoString(str *strings.Builder, skip func(object fyne.CanvasObject) bool, props map[fyne.CanvasObject]map[string]string,
defs map[string]string, objs ...fyne.CanvasObject) {
for i, o := range objs {
if skip != nil && skip(o) {
continue
Expand All @@ -420,7 +421,7 @@ func writeGoString(str *strings.Builder, skip func(object fyne.CanvasObject) boo
clazz := reflect.TypeOf(o).String()

if match, ok := Widgets[clazz]; ok {
code := match.Gostring(o, props)
code := match.Gostring(o, props, defs)
str.WriteString(fmt.Sprintf("\n\t\t%s", code))
if i < len(objs)-1 {
str.WriteRune(',')
Expand Down
Loading

0 comments on commit 64b0bf0

Please sign in to comment.