cogentcore / core

A free and open source framework for building powerful, fast, and elegant 2D and 3D apps that run on macOS, Windows, Linux, iOS, Android, and the Web with a single pure Go codebase, allowing you to Code Once, Run Everywhere.
http://cogentcore.org/core
BSD 3-Clause "New" or "Revised" License
1.31k stars 71 forks source link

core.Table visibleFields cache doesn't work for embedded fields #986

Closed rcoreilly closed 1 week ago

rcoreilly commented 1 week ago

Describe the bug

// cacheVisibleFields caches the visible struct fields.
func (tb *Table) cacheVisibleFields() {
    tb.visibleFields = make([]reflect.StructField, 0)
...
    reflectx.WalkFields(tb.ElementValue,
        func(parent reflect.Value, field reflect.StructField, value reflect.Value) bool {
            return shouldShow(field)
        },
        func(parent reflect.Value, field reflect.StructField, value reflect.Value) {
            tb.visibleFields = append(tb.visibleFields, field)
        })
...
    for fli := 0; fli < tb.numVisibleFields; fli++ {
        field := tb.visibleFields[fli]
        uvp := reflectx.UnderlyingPointer(val.FieldByIndex(field.Index))
...

The field.Index is relative to its direct parent, not the final parent which embeds others. need to also add a test for this presumably.

How to reproduce

emer/axon/ view recv prjns for example.

Example code

No response

Relevant output

No response

Platform

macOS

rcoreilly commented 1 week ago

fixed in ba92f2403a8b63b2542354fead7ae16b0b017c8b