Documentation ¶
Overview ¶
Package styled implements styling via generic walking of reflect type info. It is somewhat slower than the explicit manual code which is after all not that hard to write -- maintenance may be more of an issue, but given how time-critical styling is, it is worth it overall.
So basically this is legacy code here, maintained for future reference given that it took a bit of work.
Index ¶
- Variables
- func StyleEffTag(tag, outerTag string) string
- func WalkStyleStruct(obj interface{}, outerTag string, baseoff uintptr, fun WalkStyleFieldFunc)
- type Field
- type Fields
- func (sf *Fields) AddField(df interface{}, fieldName string) error
- func (sf *Fields) CompileFields(df interface{})
- func (sf *Fields) Inherit(obj, par interface{}, vp *gi.Viewport2D)
- func (sf *Fields) Init(df interface{})
- func (sf *Fields) Style(obj, par interface{}, props ki.Props, vp *gi.Viewport2D)
- func (sf *Fields) ToDots(obj interface{}, uc *units.Context)
- type WalkStyleFieldFunc
Constants ¶
This section is empty.
Variables ¶
var StyleValueTypes = map[reflect.Type]struct{}{ units.KiT_Value: {}, gi.KiT_Color: {}, gi.KiT_ColorSpec: {}, }
StyleValueTypes is a map of types that are used as value types in style structures
Functions ¶
func StyleEffTag ¶
get the full effective tag based on outer tag plus given tag
func WalkStyleStruct ¶
func WalkStyleStruct(obj interface{}, outerTag string, baseoff uintptr, fun WalkStyleFieldFunc)
WalkStyleStruct walks through a struct, calling a function on fields with xml tags that are not "-", recursively through all the fields
Types ¶
type Field ¶
type Field struct { Field reflect.StructField NetOff uintptr `desc:"net accumulated offset from the overall main type, e.g., Style"` Default reflect.Value `desc:"value of default value of this field"` }
Field contains the relevant data for a given stylable field in a struct
func (*Field) FieldIface ¶
FieldIface returns an interface{} for a given object, computed from NetOff -- much faster -- use this
func (*Field) FieldValue ¶
FieldValue returns a reflect.Value for a given object, computed from NetOff -- this is VERY expensive time-wise -- need to figure out a better solution..
type Fields ¶
type Fields struct { Fields map[string]*Field `desc:"the compiled stylable fields, mapped for the xml and alt tags for the field"` Inherits []*Field `desc:"the compiled stylable fields that have inherit:true tags and should thus be inherited from parent objects"` Units []*Field `desc:"the compiled stylable fields of the unit.Value type, which should have ToDots run on them"` Default interface{} `desc:"points to the Default instance of this type, initialized with the default values used for 'initial' keyword"` }
Fields contains fields of a struct that are styled -- create one instance of this for each type that has styled fields (Style, Paint, and a few with ad-hoc styled fields)
func (*Fields) AddField ¶
AddField adds a single field -- must be a direct field on the object and not a field on an embedded type -- used for Widget objects where only one or a few fields are styled
func (*Fields) CompileFields ¶
func (sf *Fields) CompileFields(df interface{})
CompileFields gathers all the fields with xml tag != "-", plus those that are units.Value's for later optimized processing of styles
func (*Fields) Inherit ¶
func (sf *Fields) Inherit(obj, par interface{}, vp *gi.Viewport2D)
Inherit copies all the values from par to obj for fields marked as "inherit" -- inherited by default. NOTE: No longer using this -- doing it manually -- much faster
type WalkStyleFieldFunc ¶
type WalkStyleFieldFunc func(struf reflect.StructField, vf reflect.Value, tag string, baseoff uintptr)
this is the function to process a given field when walking the style