Skip to content

Commit

Permalink
Fix the Go code generation for pseudo-containers
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Jul 31, 2024
1 parent 81997a5 commit a4b7550
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions pkg/gui/go.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,6 @@ func (g *gui) makeUI() fyne.CanvasObject {
}

func packagesRequired(obj fyne.CanvasObject, meta map[fyne.CanvasObject]map[string]string) []string {
if w, ok := obj.(fyne.Widget); ok {
return packagesRequiredForWidget(w)
}

ret := []string{"container"}
var objs []fyne.CanvasObject
if c, ok := obj.(*fyne.Container); ok {
Expand All @@ -111,9 +107,19 @@ func packagesRequired(obj fyne.CanvasObject, meta map[fyne.CanvasObject]map[stri
if ok && layout == "Form" {
ret = append(ret, "layout")
}
} else if c, ok := obj.(*fyne.Container); ok {
objs = c.Objects
} else {
class := reflect.TypeOf(obj).String()
info, ok := guidefs.Widgets[class]

if ok && info.IsContainer() {
objs = info.Children(obj)
} else {
if w, ok := obj.(fyne.Widget); ok {
return packagesRequiredForWidget(w)
}
}
}

for _, w := range objs {
for _, p := range packagesRequired(w, meta) {
added := false
Expand Down Expand Up @@ -142,14 +148,6 @@ func packagesRequiredForWidget(w fyne.Widget) []string {

func varsRequired(obj fyne.CanvasObject, props map[fyne.CanvasObject]map[string]string) []string {
name := props[obj]["name"]
if w, ok := obj.(fyne.Widget); ok {
if name == "" {
return []string{}
}

_, class := getTypeOf(w)
return []string{name + " " + class}
}

var ret []string
if c, ok := obj.(*fyne.Container); ok {
Expand All @@ -160,6 +158,22 @@ func varsRequired(obj fyne.CanvasObject, props map[fyne.CanvasObject]map[string]
for _, w := range c.Objects {
ret = append(ret, varsRequired(w, props)...)
}
} else {
class := reflect.TypeOf(obj).String()
info, ok := guidefs.Widgets[class]

if ok && info.IsContainer() {
for _, child := range info.Children(obj) {
ret = append(ret, varsRequired(child, props)...)
}
}
}

if w, ok := obj.(fyne.Widget); ok {
if name != "" {
_, class := getTypeOf(w)
ret = append(ret, name+" "+class)
}
}
return ret
}

0 comments on commit a4b7550

Please sign in to comment.