Skip to content

Commit

Permalink
Fixed a couple of bugs on color.RGBA handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
niemeyer committed Nov 5, 2013
1 parent 1cf114b commit 1d08b56
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
13 changes: 11 additions & 2 deletions all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ type TestType struct {
Float32Value float32
AnyValue interface{}
ObjectValue qml.Object
ColorValue color.RGBA
}

func (ts *TestType) StringMethod() string {
Expand Down Expand Up @@ -334,6 +335,14 @@ var tests = []struct {
d.Assert(d.root.Call("hasColor", color.RGBA{256 / 2, 256 / 4, 256 / 8, 256 / 16}), Equals, true)
},
},
{
Summary: "Reading and setting of a QColor property from a Go field",
Init: func(d *TestData) { d.value.ColorValue = color.RGBA{256 / 16, 256 / 8, 256 / 4, 256 / 2} },
QML: `Text{ property var c: value.colorValue; Component.onCompleted: { console.log(value.colorValue); } }`,
Done: func(d *TestData) {
d.Assert(d.root.Color("c"), Equals, color.RGBA{256 / 16, 256 / 8, 256 / 4, 256 / 2})
},
},
{
Summary: "Identical values remain identical when possible",
Init: func(d *TestData) {
Expand Down Expand Up @@ -578,7 +587,7 @@ var tests = []struct {
{
Summary: "Call a non-existent QML method",
QML: `Item {}`,
Done: func(d *TestData) {
Done: func(d *TestData) {
d.Check(func() { d.root.Call("add", 1, 2) }, Panics, `object does not expose a method "add"`)
},
},
Expand Down Expand Up @@ -720,7 +729,7 @@ var tests = []struct {
return image.NewRGBA(image.Rect(0, 0, 200, 100))
})
},
QML: `
QML: `
Image {
source: "image://myprov/myid.png"
Component.onCompleted: console.log("Size:", width, height)
Expand Down
2 changes: 1 addition & 1 deletion bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ func hookGoValueReadField(enginep, foldp unsafe.Pointer, reflectIndex C.int, res
field = field.Elem()
fieldk = field.Kind()
}
if fieldk == reflect.Struct {
if fieldk == reflect.Struct && field.Type() != typeRGBA {
if field.CanAddr() {
field = field.Addr()
} else if !hashable(field.Interface()) {
Expand Down
2 changes: 1 addition & 1 deletion cpp/capi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ void unpackDataValue(DataValue *value, QVariant_ *var)
*qvar = *(float*)(value->data);
break;
case DTColor:
*qvar = QColor(*(QRgb*)(value->data));
*qvar = QColor::fromRgba(*(QRgb*)(value->data));
break;
case DTList:
*qvar = **(QVariantList**)(value->data);
Expand Down
4 changes: 3 additions & 1 deletion datatype.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var (
typeFloat64 = reflect.TypeOf(float64(0))
typeFloat32 = reflect.TypeOf(float32(0))
typeIface = reflect.TypeOf(new(interface{})).Elem()
typeRGBA = reflect.TypeOf(color.RGBA{})
)

func init() {
Expand Down Expand Up @@ -166,6 +167,8 @@ func dataTypeOf(typ reflect.Type) C.DataType {
return C.DTFloat64
case typeIface:
return C.DTAny
case typeRGBA:
return C.DTColor
}
return C.DTObject
}
Expand Down Expand Up @@ -275,7 +278,6 @@ func typeInfo(v interface{}) *C.GoTypeInfo {
memberInfo.methodSignature = C.CString(signature)
memberInfo.resultSignature = C.CString(result)
// TODO Sort out methods with a variable number of arguments.
// TODO Sort out methods with more than one result.
// It's called while bound, so drop the receiver.
memberInfo.numIn = C.int(method.Type.NumIn() - 1)
memberInfo.numOut = C.int(method.Type.NumOut())
Expand Down

0 comments on commit 1d08b56

Please sign in to comment.