Only the computation of the model needs to be done in the evaluation scope for it

Otherwise any change in any of the properties of the delegate will cause
the model to be reset.
This commit is contained in:
Olivier Goffart 2020-09-04 15:35:49 +02:00
parent c8fa3354be
commit f5aeb9ba60
4 changed files with 44 additions and 42 deletions

View file

@ -124,7 +124,7 @@ struct PropertyTracker
}
template<typename F>
void evaluate(const F &f) const {
auto evaluate(const F &f) const -> std::enable_if_t<std::is_same_v<decltype(f()), void>> {
cbindgen_private::sixtyfps_property_tracker_evaluate(
&inner,
[](void *f){ (*reinterpret_cast<const F*>(f))(); },
@ -132,6 +132,13 @@ struct PropertyTracker
);
}
template<typename F>
auto evaluate(const F &f) const -> std::enable_if_t<!std::is_same_v<decltype(f()), void>, decltype(f())> {
decltype(f()) result;
this->evaluate([&] { result = f(); } );
return result;
}
private:
cbindgen_private::PropertyTrackerOpaque inner;
};