Skip to content

Commit

Permalink
add docs for inline struct view and struct value
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoreilly committed Mar 22, 2024
1 parent 06811d6 commit 8dd0b51
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
35 changes: 35 additions & 0 deletions docs/content/3-views/struct-views.md
Original file line number Diff line number Diff line change
Expand Up @@ -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})
```
24 changes: 24 additions & 0 deletions docs/webcoregen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8dd0b51

Please sign in to comment.