Skip to content

Commit

Permalink
add embedded fields and view add-fields struct view docs
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoreilly committed Mar 22, 2024
1 parent 8dd0b51 commit 0f63905
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
28 changes: 28 additions & 0 deletions docs/content/3-views/struct-views.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,34 @@ type person struct {
giv.NewStructView(parent).SetStruct(&person{Name: "Go", Age: 35}).SetReadOnly(true)
```

You can use structs with embedded fields:

```Go
type Person struct {
Name string
Age int
}
type employee struct {
Person
Role string
}
giv.NewStructView(parent).SetStruct(&employee{Person{Name: "Go", Age: 35}, "Programmer"})
```

You can expand fields that are themselves structs:

```Go
type person struct {
Name string
Age int
}
type employee struct {
Role string
Manager person `view:"add-fields"`
}
giv.NewStructView(parent).SetStruct(&employee{"Programmer", person{Name: "Go", Age: 35}})
```

You can specify a default value (or list or range of values) for a field, which will be displayed in the tooltip for the field label, make the label highlighted when the value is non-default, and allow the user to reset the value to the default value by double clicking on the label:

```Go
Expand Down
28 changes: 25 additions & 3 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 0f63905

Please sign in to comment.