diff --git a/docs/content/3-views/struct-views.md b/docs/content/3-views/struct-views.md index 6089c9cdbc..3e65e6e2e6 100644 --- a/docs/content/3-views/struct-views.md +++ b/docs/content/3-views/struct-views.md @@ -92,3 +92,38 @@ type person struct { //gti:add Name string } ``` + +You can make a struct view that fits in one line: + +```Go +type person struct { + Name string + Age int +} +giv.NewStructViewInline(parent).SetStruct(&person{Name: "Go", Age: 35}) +``` + +Inline struct views support everything that normal struct views do, including everything documented above. + +When you use [[giv.NewValue]] with a struct object, it will create an inline struct view if the struct has four or fewer fields: + +```Go +type person struct { + Name string + Age int +} +giv.NewValue(parent, &person{Name: "Go", Age: 35}) +``` + +Otherwise, it will create a button that opens a dialog with a normal struct view: + +```Go +type person struct { + Name string + Age int + Job string + LikesGo bool + LikesPython bool +} +giv.NewValue(parent, &person{Name: "Go", Age: 35, Job: "Programmer", LikesGo: true}) +``` diff --git a/docs/webcoregen.go b/docs/webcoregen.go index 706b41a1de..24794ab858 100644 --- a/docs/webcoregen.go +++ b/docs/webcoregen.go @@ -597,6 +597,30 @@ var WebcoreExamples = map[string]func(parent gi.Widget){ } giv.NewStructView(parent).SetStruct(&person{Name: "Go", Age: 35, Precision: 50}) }, + "views/struct-views-7": func(parent gi.Widget) { + type person struct { + Name string + Age int + } + giv.NewStructViewInline(parent).SetStruct(&person{Name: "Go", Age: 35}) + }, + "views/struct-views-8": func(parent gi.Widget) { + type person struct { + Name string + Age int + } + giv.NewValue(parent, &person{Name: "Go", Age: 35}) + }, + "views/struct-views-9": func(parent gi.Widget) { + type person struct { + Name string + Age int + Job string + LikesGo bool + LikesPython bool + } + giv.NewValue(parent, &person{Name: "Go", Age: 35, Job: "Programmer", LikesGo: true}) + }, "advanced/styling-0": func(parent gi.Widget) { parent.OnWidgetAdded(func(w gi.Widget) { w.Style(func(s *styles.Style) {