func EnumIfaceFromInt64(ival int64, typ reflect.Type) interface{} {
	evn := reflect.New(typ)
	SetEnumValueFromInt64(evn, ival)
	return evn.Elem().Interface()
}
EnumIfaceFromInt64 returns an interface{} value which is an enum value of
given type (not a pointer to it), set to given integer value
package kit
import (
	"bytes"
	"fmt"
	"log"
	"reflect"
	"strings"
	"github.com/goki/ki/bitflag"
)
type EnumRegistry struct {
	Enums map[string]reflect.Type
	Props map[string]map[string]interface{}
	Vals map[string][]EnumValue
}
var Enums EnumRegistry
const (
	BitFlag = true
	NotBitFlag = false
)
func (tr *EnumRegistry) AddEnum(en interface{}, bitFlag bool, props map[string]interface{}) reflect.Type {
	if tr.Enums == nil {
		tr.Enums = make(map[string]reflect.Type)
		tr.Props = make(map[string]map[string]interface{})
		tr.Vals = make(map[string][]EnumValue)
	}
	typ := PtrType(reflect.TypeOf(en)).Elem()
	n := EnumIfaceToInt64(en)
	snm := ShortTypeName(typ)
	tr.Enums[snm] = typ
	if props != nil {
		nwprops := make(map[string]interface{}, len(props))
		for key, val := range props {
			nwprops[key] = val
		}
		tr.Props[snm] = nwprops
	}
	tp := tr.Properties(snm)
	tp["N"] = n
	if bitFlag {
		tp := tr.Properties(snm)
		tp["BitFlag"] = true
		EnumBitDepthCheck(typ, n)
	}
	return typ
}
func EnumBitDepthCheck(typ reflect.Type, n int64) error {
	cp := typ.Size() * 8
	if n > int64(cp) {
		err := fmt.Errorf("kit.EnumBitDepthCheck ERROR: enum: %v is a bitflag of kind: %v with capacity of: %d bits, but more flags were defined: %d", ShortTypeName(typ), typ.Kind(), cp, n)
		log.Println(err)
		return err
	}
	return nil
}
func (tr *EnumRegistry) AddEnumAltLower(en interface{}, bitFlag bool, props map[string]interface{}, prefix string) reflect.Type {
	typ := tr.AddEnum(en, bitFlag, props)
	n := EnumIfaceToInt64(en)
	snm := ShortTypeName(typ)
	alts := make(map[int64]string)
	tp := tr.Properties(snm)
	for i := int64(0); i < n; i++ {
		str := EnumInt64ToString(i, typ)
		str = strings.ToLower(strings.TrimPrefix(str, prefix))
		alts[i] = str
	}
	tp["AltStrings"] = alts
	return typ
}
func (tr *EnumRegistry) AddEnumExt(parTyp reflect.Type, en interface{}, bitFlag bool, props map[string]interface{}) reflect.Type {
	typ := tr.AddEnum(en, bitFlag, props)
	snm := ShortTypeName(typ)
	if parTyp == typ {
		log.Printf("kit.Enums.AddEnumExt: parent type: %v is same as type being defined -- must be different!\n", parTyp.String())
	} else {
		tr.SetProp(snm, "ParType", parTyp)
	}
	return typ
}
func (tr *EnumRegistry) AddEnumExtAltLower(parTyp reflect.Type, en interface{}, bitFlag bool, props map[string]interface{}, prefix string) reflect.Type {
	typ := tr.AddEnumExt(parTyp, en, bitFlag, props)
	n := EnumIfaceToInt64(en)
	snm := ShortTypeName(typ)
	alts := make(map[int64]string)
	tp := tr.Properties(snm)
	pnm := ShortTypeName(parTyp)
	pp := tr.Properties(pnm)
	pn, _ := ToInt(pp["N"])
	if palti, ok := pp["AltStrings"]; ok {
		palt := palti.(map[int64]string)
		for k, v := range palt {
			alts[k] = v
		}
	}
	for i := int64(pn); i < n; i++ {
		str := EnumInt64ToString(i, typ)
		str = strings.ToLower(strings.TrimPrefix(str, prefix))
		alts[i] = str
	}
	tp["AltStrings"] = alts
	return typ
}
func (tr *EnumRegistry) Enum(name string) reflect.Type {
	return tr.Enums[name]
}
func (tr *EnumRegistry) TypeRegistered(typ reflect.Type) bool {
	enumName := ShortTypeName(typ)
	_, ok := tr.Enums[enumName]
	return ok
}
func (tr *EnumRegistry) Properties(enumName string) map[string]interface{} {
	tp, ok := tr.Props[enumName]
	if !ok {
		tp = make(map[string]interface{})
		tr.Props[enumName] = tp
	}
	return tp
}
func (tr *EnumRegistry) Prop(enumName, propKey string) interface{} {
	tp, ok := tr.Props[enumName]
	if !ok {
		return nil
	}
	p, ok := tp[propKey]
	if !ok {
		return nil
	}
	return p
}
func (tr *EnumRegistry) SetProp(enumName, propKey string, val interface{}) {
	tp := tr.Properties(enumName)
	tp[propKey] = val
}
func (tr *EnumRegistry) AltStrings(enumName string) map[int64]string {
	ps := tr.Prop(enumName, "AltStrings")
	if ps == nil {
		return nil
	}
	m, ok := ps.(map[int64]string)
	if !ok {
		log.Printf("kit.EnumRegistry AltStrings error: AltStrings property must be a map[int64]string type, is not -- is instead: %T\n", m)
		return nil
	}
	return m
}
func (tr *EnumRegistry) ParType(enumName string) reflect.Type {
	pti := tr.Prop(enumName, "ParType")
	if pti == nil {
		return nil
	}
	pt, ok := pti.(reflect.Type)
	if !ok {
		log.Printf("kit.EnumRegistry ParType error: ParType property must be a reflect.Type, is not -- is instead: %T\n", pt)
		return nil
	}
	return pt
}
func (tr *EnumRegistry) NVals(eval interface{}) int64 {
	typ := reflect.TypeOf(eval)
	nm := ShortTypeName(typ)
	n := tr.Prop(nm, "N")
	if n != nil {
		return n.(int64)
	}
	log.Printf("kit.EnumRegistry: no N registered for type: %v\n", nm)
	return 0
}
func (tr *EnumRegistry) IsBitFlag(typ reflect.Type) bool {
	b, _ := ToBool(tr.Prop(ShortTypeName(typ), "BitFlag"))
	return b
}
func EnumIfaceToInt64(eval interface{}) int64 {
	ev := NonPtrValue(reflect.ValueOf(eval))
	var ival int64
	reflect.ValueOf(&ival).Elem().Set(ev.Convert(reflect.TypeOf(ival)))
	return ival
}
func SetEnumIfaceFromInt64(eval interface{}, ival int64, typ reflect.Type) error {
	if reflect.TypeOf(eval).Kind() != reflect.Ptr {
		err := fmt.Errorf("kit.SetEnumFromInt64: must pass a pointer to the enum: Type: %v, Kind: %v\n", reflect.TypeOf(eval).Name(), reflect.TypeOf(eval).Kind())
		log.Printf("%v", err)
		return err
	}
	reflect.ValueOf(eval).Elem().Set(reflect.ValueOf(ival).Convert(typ))
	return nil
}
func SetEnumValueFromInt64(eval reflect.Value, ival int64) error {
	if eval.Kind() != reflect.Ptr {
		err := fmt.Errorf("kit.SetEnumValueFromInt64: must pass a pointer value to the enum: Type: %v, Kind: %v\n", eval.Type().String(), eval.Kind())
		log.Printf("%v", err)
		return err
	}
	npt := NonPtrType(eval.Type())
	eval.Elem().Set(reflect.ValueOf(ival).Convert(npt))
	return nil
}