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

Method makeHeader

core/table.go:215–266  ·  view source on GitHub ↗
(p *tree.Plan)

Source from the content-addressed store, hash-verified

213}
214
215func (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
269func (tb *Table) RowWidgetNs() (nWidgPerRow, idxOff int) {

Callers 1

InitMethod · 0.95

Implementers 1

_cogentcore_org_core_plot_plots_Tableyaegicore/symbols/cogentcore_org-core-

Calls 15

SortColumnMethod · 0.95
AddAtFunction · 0.92
EmFunction · 0.92
ToSentenceFunction · 0.92
GetDocFunction · 0.92
ToolbarStylesFunction · 0.85
StylerMethod · 0.80
MakerMethod · 0.80
UpdaterMethod · 0.80
SetMethod · 0.65
LookupMethod · 0.65
SetIconMethod · 0.65

Tested by

no test coverage detected