cacheVisibleFields caches the visible struct fields.
()
| 156 | |
| 157 | // cacheVisibleFields caches the visible struct fields. |
| 158 | func (tb *Table) cacheVisibleFields() { |
| 159 | tb.visibleFields = make([]reflect.StructField, 0) |
| 160 | shouldShow := func(field reflect.StructField) bool { |
| 161 | tvtag := field.Tag.Get("table") |
| 162 | switch { |
| 163 | case tvtag == "+": |
| 164 | return true |
| 165 | case tvtag == "-": |
| 166 | return false |
| 167 | case tvtag == "-select" && tb.IsReadOnly(): |
| 168 | return false |
| 169 | case tvtag == "-edit" && !tb.IsReadOnly(): |
| 170 | return false |
| 171 | default: |
| 172 | return field.Tag.Get("display") != "-" |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | reflectx.WalkFields(tb.elementValue, |
| 177 | func(parent reflect.Value, field reflect.StructField, value reflect.Value) bool { |
| 178 | return shouldShow(field) |
| 179 | }, |
| 180 | func(parent reflect.Value, parentField *reflect.StructField, field reflect.StructField, value reflect.Value) { |
| 181 | if parentField != nil { |
| 182 | field.Index = append(parentField.Index, field.Index...) |
| 183 | } |
| 184 | tb.visibleFields = append(tb.visibleFields, field) |
| 185 | }) |
| 186 | tb.numVisibleFields = len(tb.visibleFields) |
| 187 | tb.headerWidths = make([]int, tb.numVisibleFields) |
| 188 | tb.colMaxWidths = make([]int, tb.numVisibleFields) |
| 189 | } |
| 190 | |
| 191 | func (tb *Table) UpdateMaxWidths() { |
| 192 | if tb.SliceSize == 0 { |
no test coverage detected