Commit graph

685 commits

Author SHA1 Message Date
Simon Hausmann
45de3d832e Minor cleanup in the interpreter animation handling
Expose the fields of the PropertyAnimation through the rtti module
instead of hard-coding them in the interpreter.
2020-06-26 20:33:55 +02:00
Olivier Goffart
d267039fa8 Put a pointer to the parent component in the component
This means we must use Rc for the component so we can use Weak for the parent pointer.

The idea is to get rid later of the context
2020-06-26 19:26:55 +02:00
Olivier Goffart
f8a63b1b76 Add a weak-pin crate that can be used to create Weak pointr from Pin<Rc> 2020-06-26 17:30:40 +02:00
Simon Hausmann
fe64712582 Fix rectangle rendering
Use the width for the width instead of x :-)
2020-06-26 17:19:02 +02:00
Olivier Goffart
2d22bac451 Use Pin<&Self> for Property::get 2020-06-26 13:18:04 +02:00
Olivier Goffart
0029921f1a Pin the items in the interpreter 2020-06-26 11:55:05 +02:00
Olivier Goffart
f80addb6a3 Make the viewer's animation work 2020-06-26 11:07:18 +02:00
Simon Hausmann
36bd645e09 First stab at supporting animations in the interpreter.
The sub-optimal RTTI bits are replaced with a superior solution in the
follow-up commit :-)
2020-06-26 11:07:18 +02:00
Olivier Goffart
1b748792ad Visit the item as Pin
A preparation to have Property::get to take Pin<Self>
2020-06-25 18:50:20 +02:00
Olivier Goffart
40f4265071 Some improvement in ConstFieldOffset trait 2020-06-25 18:23:08 +02:00
Olivier Goffart
812b08b50c const_field_offset: Add compile type type for the offset
WIP
2020-06-25 17:46:29 +02:00
Simon Hausmann
c18861125d Small typo fix :-) 2020-06-25 14:22:10 +02:00
Simon Hausmann
bcaaa126da Beef up the hello.60 test case a litte with an animation
Enlarge the buttons when they're pressed.
2020-06-25 14:18:32 +02:00
Simon Hausmann
d5c4955500 Fix running this hello.60 copy in the viewer
The relative path to the image was wrong.
2020-06-25 13:49:23 +02:00
Simon Hausmann
e6b386ab53 Implement property animations for C++ 2020-06-25 13:38:51 +02:00
Olivier Goffart
f50a705e00 Add the #[pin] attribute to be able to project to the pinned item 2020-06-25 12:18:09 +02:00
Olivier Goffart
9ed660926c Added a #[pin] attribute in the FieldOffsets macro 2020-06-25 12:18:09 +02:00
Olivier Goffart
23e9397578 Add a Pinned flag to FieldOffset
So we can have Pinned projection
2020-06-25 12:18:09 +02:00
Simon Hausmann
a19c9619fa Prepare PropertyAnimationBinding for use with C++
Don't take the binding as a Rust function, take a ready-to-set Rc<dyn
Binding> trait object.
2020-06-25 11:55:24 +02:00
Simon Hausmann
c40840baf9 Property animation binding cleanups for upcoming C++ support
Remove Property::set_binding_object and instead have an associated
helper method on PropertyImpl, as in C++ only we have the inner impl.

Also removed set_notifier_callback() from the Binding trait, as it's not
needed there anymore - we can set up the callback right away at property
animation construction time, so that it also works without a Property<T>
but just an inner.
2020-06-25 11:42:30 +02:00
Simon Hausmann
9bd6fd0808 Naming cleanups in preparation for C++ support
Rename properties::PropertyAnimation to PropertyAnimationBinding -- it's
mostly an internal type anyway. This way
abi::primitives::PropertyAnimation remains the only type with that name
and exposing it to C++ is straight-forward.
2020-06-25 11:41:42 +02:00
Simon Hausmann
fb74a8ddd4 Fix animations for the wasm build
Use the instant crate that has a transparent fall-back to performance.now().
2020-06-25 09:07:04 +02:00
Simon Hausmann
ee4b78a132 Delete value animations when they are done
We don't need the binding and animation objects anymore upon completion.
2020-06-25 09:01:26 +02:00
Simon Hausmann
8675cfb183 Fix animation driver to deal with freed animations
Just skip over those entries.
2020-06-25 08:58:13 +02:00
Simon Hausmann
459a8e3b25 Clean up property and animation associated
Set up everything in the construction function of property animation
instead of constructing it and setting up stuff afterwards in Property.
2020-06-25 08:42:27 +02:00
Simon Hausmann
8be058d563 Clean up property binding interface
The trait functions that allowing a binding (animation) to intercept a
new value or binding is not needed anymore since the generated code is
supposed to cover all call sites and pass the appropriate animation at
that point.
2020-06-25 08:26:14 +02:00
Simon Hausmann
e7ba02c85a Fix animation of properties by value in the Rust generator
Don't require an evaluation context when setting up an animated value.
We can find out what the current value is inside evaluate.
2020-06-25 08:20:37 +02:00
Olivier Goffart
d4e68971ef Make FieldOffset contra-variant in U 2020-06-24 18:53:53 +02:00
Olivier Goffart
4960cee542 const-field-offset: some documentation fixup 2020-06-24 18:20:14 +02:00
Olivier Goffart
b6705c6c69 const_field_offset: ensure that the structure is not repr(packed) 2020-06-24 18:20:14 +02:00
Simon Hausmann
f14eb956bf Silly tweak to example for animations
Move the minus button a little to the right when pressing. This isn't
great useabilty, but it demonstrates the concept easily for a moment ;-)
2020-06-24 17:54:25 +02:00
Simon Hausmann
3d85cb7f23 Add basic support for property animations to the rust generator
Setting values on animated properties now results in set_animated_value
being called on the property instead of set, and the animation data is
passed on the spot.
2020-06-24 17:54:25 +02:00
Simon Hausmann
3a5ebd86e0 Prepare to connect Property with PropertyAnimation
This patch replaces the 'install()' approach for property animations
with explicit set_animated_value() and set_animated_binding() functions
in Property -- to be called from generated code.

This requires a little dance-around for the time being that
PropertyAnimation is designed to act automatically on value transitions,
but that can be removed later without changing the interface.

Also the animation details are copied right away. This is sub-optimal,
we should somehow keep a reference to the properties or get notified
when they change, for example perhaps through a simple property binding.
2020-06-24 17:54:25 +02:00
Simon Hausmann
ab697ab71d Parse animation declarations into the object tree
So

    animate x { ... }

is basically a short-hand for

    PropertyAnimation {
        ...
    }

    <magically associated that animation with x whenever x is changed>

We could also support a shared animation syntax in the future:

    blah := PropertyAnimation { ... }

    animate x with blah;
    animate y with blah;

This patch also adds a primitive PropertyAnimation struct, which will be
used by the generated code to collect the values specified in the .60
markup.
2020-06-24 17:43:48 +02:00
Simon Hausmann
388c98bba5 Parse animate someProperty { ... } declarations 2020-06-24 17:43:48 +02:00
Olivier Goffart
caca0d0ba4 Put the component in a Pin<>
Removed the drop and create from the ComponentVTable:
since we are not using VBox<ComponentVTable>, this simplifies a bit
the code of the interpreter and everything else.

But there is still a lot of changes everywhere to support that the Component
is pinned.
This is just for the component. Which would be required if later we want
to access the properties as Pin<Property<_>>. But we have not yet ability
to do projections
2020-06-24 14:13:27 +02:00
Simon Hausmann
de74ae4534 Fix warrning warnings in C++ code when using array models with integer literals
For the generated

   std::make_shared<sixtyfps::ArrayModel<3,float>>(1, 3, 2);

gcc would complain

    non-constant-expression cannot be narrowed from type 'int' to 'float' in initializer list [-Wc++11-narrowing]

So this patch casts the individual elements to the target (float) type.
2020-06-24 10:47:00 +02:00
Simon Hausmann
197a900331 Fix drop for PropertyAnimation
Get rid of the constructor function, stick to Default and provide a
setter for the duration instead.
2020-06-23 13:56:10 +02:00
Simon Hausmann
90766f0f82 Simplify PropertyAnimation
Remove the animation_driver member and fetch it on-demand instead.
2020-06-23 13:51:26 +02:00
Simon Hausmann
4f761960f0 Remove stray debug output 2020-06-23 13:40:52 +02:00
Simon Hausmann
688f111563 Added simple linear property animation class 2020-06-23 13:27:09 +02:00
Simon Hausmann
d99972a77a Simplify animation driver handling
Instead of passing it through the event loop, make it accessible as a
thread local variable.
2020-06-23 13:03:35 +02:00
Olivier Goffart
32c230e840 Property: small refactor to improve reasoning about the safety
Improve the safety by explicitly borrowing both inner and the value
and putting all the (non-ffi) unsafe in only two functions
2020-06-23 11:41:41 +02:00
Olivier Goffart
4ee86a9bef Add a generic T to Binding and PropertyImpl
(This also removes one heap allocation per binding)
2020-06-23 11:16:11 +02:00
Simon Hausmann
264dfa3148 Add support for animations to Property<T>
This is done by extending the Binding trait to allow intercepting any
newly set values or bindings and reporting back to the property.
2020-06-22 20:01:07 +02:00
Simon Hausmann
5762f5b065 Small naming cleanups
* Renamed PropertyNotify::notify to register_current_binding_as_dependency
  as the implementor doesn't actively notify anybody, it merely results
  in registering the currently evaluating binding as a dependency.
  Also fixed the docs that I added a short while ago -- I got it the
  wrong way around :)

* Renamed CURRENT_PROPERTY to CURRENT_BINDING to reflect that this is
  about the currently evaluating binding (that'll become a dependency to
  notify)
2020-06-22 19:27:15 +02:00
Simon Hausmann
7694337181 Simplify the animation driver API
By making the duration a "property" of the Animated trait, we can reduce
the API surface.
2020-06-22 19:27:15 +02:00
Olivier Goffart
85b06c3342 Interpreter: support for Object as Value 2020-06-22 19:03:54 +02:00
Olivier Goffart
c682d14e0b C++: Object literal and ObjectAccess 2020-06-22 18:30:40 +02:00
Olivier Goffart
6133e35df8 Rust: Object literal and ObjectAccess 2020-06-22 18:10:32 +02:00