dynamically set the label of a table column
Describe the feature
i want to build multi-language support in my application. Table is one of the widgets that uses the "label" tag of a struct field in the collection element type, which now is a constant. The idea is to have an optional function that can do the lookup ; in the example below it is called "SetLabelFunc"
Relevant code
type language struct {
Name string `label:"lang_name"`
Rating int `display:"-"`
}
tab := core.NewTable(b)
tab.SetLabelFunc(func(columnIndex int, fieldName, labelTag string) string {
// do translation lookup here, might want to use fallback labelTag or fieldName
return "Name"
})
tab.SetSlice(&[]language{{"Go", 10}, {"Python", 5}})
@emicklei Thank you for suggesting this. I will add support for something similar to this when I have the time; it makes sense to have a generic function that gives you the actual header button and allows you set the text, icon, tooltip, etc to whatever you want. I will likely make that an interface similar to the one I will add in #1204, and I will make one for forms as well. I will probably work on this in conjunction with #1204 when I have the time.
Please also note that we will add built-in support for multiple languages in #9, but this is useful functionality regardless.