(p *tree.Plan)
| 213 | } |
| 214 | |
| 215 | func (tb *Table) makeHeader(p *tree.Plan) { |
| 216 | tree.AddAt(p, "header", func(w *Frame) { |
| 217 | tb.header = w |
| 218 | ToolbarStyles(w) |
| 219 | w.Styler(func(s *styles.Style) { |
| 220 | s.Grow.Set(0, 0) |
| 221 | s.Gap.Set(units.Em(0.5)) // matches grid default |
| 222 | }) |
| 223 | w.Maker(func(p *tree.Plan) { |
| 224 | if tb.ShowIndexes { |
| 225 | tree.AddAt(p, "head-index", func(w *Text) { |
| 226 | w.SetType(TextBodyMedium) |
| 227 | w.Styler(func(s *styles.Style) { |
| 228 | s.Align.Self = styles.Center |
| 229 | }) |
| 230 | w.SetText("Index") |
| 231 | }) |
| 232 | } |
| 233 | for fli := 0; fli < tb.numVisibleFields; fli++ { |
| 234 | field := tb.visibleFields[fli] |
| 235 | tree.AddAt(p, "head-"+field.Name, func(w *Button) { |
| 236 | w.SetType(ButtonMenu) |
| 237 | w.OnClick(func(e events.Event) { |
| 238 | tb.SortColumn(fli) |
| 239 | }) |
| 240 | w.Updater(func() { |
| 241 | htxt := "" |
| 242 | if lbl, ok := field.Tag.Lookup("label"); ok { |
| 243 | htxt = lbl |
| 244 | } else { |
| 245 | htxt = strcase.ToSentence(field.Name) |
| 246 | } |
| 247 | w.SetText(htxt) |
| 248 | w.Tooltip = htxt + " (click to sort by)" |
| 249 | doc, ok := types.GetDoc(reflect.Value{}, tb.elementValue, field, htxt) |
| 250 | if ok && doc != "" { |
| 251 | w.Tooltip += ": " + doc |
| 252 | } |
| 253 | tb.headerWidths[fli] = len(htxt) |
| 254 | if fli == tb.sortIndex { |
| 255 | if tb.sortDescending { |
| 256 | w.SetIcon(icons.KeyboardArrowDown) |
| 257 | } else { |
| 258 | w.SetIcon(icons.KeyboardArrowUp) |
| 259 | } |
| 260 | } |
| 261 | }) |
| 262 | }) |
| 263 | } |
| 264 | }) |
| 265 | }) |
| 266 | } |
| 267 | |
| 268 | // RowWidgetNs returns number of widgets per row and offset for index label |
| 269 | func (tb *Table) RowWidgetNs() (nWidgPerRow, idxOff int) { |
no test coverage detected