Exemple #1
0
func (e *Element) SetStyle(key string, value interface{}) {
	szKey := C.CString(key)
	defer C.free(unsafe.Pointer(szKey))
	var valuePtr *uint16 = nil

	switch v := value.(type) {
	case string:
		valuePtr = stringToUtf16Ptr(v)
	case float32:
		valuePtr = stringToUtf16Ptr(strconv.FormatFloat(float64(v), 'g', -1, 64))
	case float64:
		valuePtr = stringToUtf16Ptr(strconv.FormatFloat(float64(v), 'g', -1, 64))
	case int:
		valuePtr = stringToUtf16Ptr(strconv.Itoa(v))
	case int32:
		valuePtr = stringToUtf16Ptr(strconv.FormatInt(int64(v), 10))
	case int64:
		valuePtr = stringToUtf16Ptr(strconv.FormatInt(v, 10))
	case nil:
		valuePtr = nil
	default:
		panic(fmt.Sprintf("Don't know how to format this argument type: %s", reflect.TypeOf(v)))
	}

	if ret := C.HTMLayoutSetStyleAttribute(e.handle, (*C.CHAR)(szKey), (*C.WCHAR)(valuePtr)); ret != HLDOM_OK {
		domPanic(ret, "Failed to set style: "+key)
	}
}
Exemple #2
0
func (e *Element) ClearStyles(key string) {
	if ret := C.HTMLayoutSetStyleAttribute(e.handle, nil, nil); ret != HLDOM_OK {
		domPanic(ret, "Failed to clear all styles")
	}
}