MCPcopy Create free account
hub / github.com/cogentcore/core / getStructFields

Method getStructFields

core/form.go:76–114  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

74func (fm *Form) WidgetValue() any { return &fm.Struct }
75
76func (fm *Form) getStructFields() {
77 var fields []*structField
78
79 shouldShow := func(parent reflect.Value, field reflect.StructField) bool {
80 if field.Tag.Get("display") == "-" {
81 return false
82 }
83 if ss, ok := reflectx.UnderlyingPointer(parent).Interface().(ShouldDisplayer); ok {
84 fm.isShouldDisplayer = true
85 if !ss.ShouldDisplay(field.Name) {
86 return false
87 }
88 }
89 return true
90 }
91
92 reflectx.WalkFields(reflectx.Underlying(reflect.ValueOf(fm.Struct)),
93 func(parent reflect.Value, field reflect.StructField, value reflect.Value) bool {
94 return shouldShow(parent, field)
95 },
96 func(parent reflect.Value, parentField *reflect.StructField, field reflect.StructField, value reflect.Value) {
97 if field.Tag.Get("display") == "add-fields" && field.Type.Kind() == reflect.Struct {
98 reflectx.WalkFields(value,
99 func(parent reflect.Value, sfield reflect.StructField, value reflect.Value) bool {
100 return shouldShow(parent, sfield)
101 },
102 func(parent reflect.Value, parentField *reflect.StructField, sfield reflect.StructField, value reflect.Value) {
103 // if our parent field is read only, we must also be
104 if field.Tag.Get("edit") == "-" && sfield.Tag.Get("edit") == "" {
105 sfield.Tag += ` edit:"-"`
106 }
107 fields = append(fields, &structField{path: field.Name + " • " + sfield.Name, field: sfield, value: value, parent: parent})
108 })
109 } else {
110 fields = append(fields, &structField{path: field.Name, field: field, value: value, parent: parent})
111 }
112 })
113 fm.structFields = fields
114}
115
116func (fm *Form) Init() {
117 fm.Frame.Init()

Callers 1

InitMethod · 0.95

Calls 5

UnderlyingPointerFunction · 0.92
WalkFieldsFunction · 0.92
UnderlyingFunction · 0.92
KindMethod · 0.80
ShouldDisplayMethod · 0.65

Tested by

no test coverage detected