func MakeGui(bar *tw.Bar, options interface{}) { elem := reflect.ValueOf(options).Elem() typ := reflect.TypeOf(options).Elem() if elem.Kind() != reflect.Struct { panic("wrong arguments need struct pointer") } for i := 0; i < elem.NumField(); i++ { field := elem.Field(i) structField := typ.Field(i) if field.Kind() == reflect.Bool { dataPtr := unsafe.Pointer(field.Pointer()) Name := structField.Name bar.AddVarRW(Name, tw.TYPE_BOOL8, dataPtr, "") } } }
func (this *BoolOptions) CreateGui(bar *tw.Bar) { v := reflect.ValueOf(this).Elem() t := v.Type() N := v.NumField() for i := 0; i < N; i++ { field := t.Field(i) fieldValue := v.Field(i) switch field.Type.Kind() { case reflect.Bool: bar.AddVarRW(field.Name, tw.TYPE_BOOL8, unsafe.Pointer(fieldValue.Addr().Pointer()), "") case reflect.Float32: bar.AddVarRW(field.Name, tw.TYPE_FLOAT, unsafe.Pointer(fieldValue.Addr().Pointer()), "") case reflect.Float64: bar.AddVarRW(field.Name, tw.TYPE_DOUBLE, unsafe.Pointer(fieldValue.Addr().Pointer()), "") } } }