go-qml / qml

QML support for the Go language
Other
1.96k stars 187 forks source link

[wishlist] qml.Changed function "update all fields" #23

Closed fedesog closed 10 years ago

fedesog commented 10 years ago

Is it possible to expand qml.Changed to notify QML that all fields of a value has been changed. So far calling qml.Changed passing the address of the value is equivalent to notify that the first field of the struct has been changed (unplanned behaviour?).

Example:

[...]
mytext.Color = color.RGBA{n(), n(), n(), 0xff}
mytext.Text = "new text"
qml.Changed(mytext, &mytext.Text)
qml.Changed(mytext, &mytext.Color)
// instead of calling qml.Changed for each field it would be faster to
// just call qml.Changed(mytext, &mytext) or a function with a variadic
// parameter qml.Changed(mytext, &mytext.Text, &mytext.Color)
[...]

type Mytext struct {
    Text string
    Color color.RGBA
}
niemeyer commented 10 years ago

It is technically doable, but it doesn't look like a good idea as it'll encourage people to flag as changed more than has actually changed, leading to perhaps significant unnecessary churn.

The side effect you see is simply because &value and &value.FirstField will necessary point to the same address.

fedesog commented 10 years ago

What about using a variadic parameter instead? Users would have to specify each modified field with the only difference that qml.Changed could be called just once instead of once per field. The function signature would be similar and backward compatible: func Changed(value interface{}, fieldAddrs ...interface{}) In any case the function should be probably be fixed to panic if erroneously called with qml.Changed(value, &value).