styled

package
v1.0.17 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2020 License: BSD-3-Clause Imports: 10 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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

func StyleEffTag(tag, outerTag string) string

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

func (sf *Field) FieldIface(objptr uintptr) interface{}

FieldIface returns an interface{} for a given object, computed from NetOff -- much faster -- use this

func (*Field) FieldValue

func (sf *Field) FieldValue(objptr uintptr) reflect.Value

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..

func (*Field) FromProps

func (fld *Field) FromProps(fields map[string]*Field, objptr, parptr uintptr, val interface{}, hasPar bool, vp *gi.Viewport2D)

FromProps styles given field from property value val, with optional parent object obj

func (*Field) UnitsValue

func (sf *Field) UnitsValue(objptr uintptr) *units.Value

UnitsValue returns a units.Value for a field, which must be of that type..

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

func (sf *Fields) AddField(df interface{}, fieldName string) error

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

func (*Fields) Init

func (sf *Fields) Init(df interface{})

func (*Fields) Style

func (sf *Fields) Style(obj, par interface{}, props ki.Props, vp *gi.Viewport2D)

Style applies styles to the fields from given properties for given object

func (*Fields) ToDots

func (sf *Fields) ToDots(obj interface{}, uc *units.Context)

ToDots runs ToDots on unit values, to compile down to raw pixels

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL