Commit graph

685 commits

Author SHA1 Message Date
Simon Hausmann
271f52b9c9 Fix rectangle rendering with alpha
Lyon generates triangles, not a triangle strip. For a triangle strip
we'd end up drawing too many triangles, messing
up the alpha on overdraw.
2020-06-16 13:46:25 +02:00
Simon Hausmann
2fba097e81 Clean up window registration
Automatically register the weak ref in the "constructor" of the main
window and de-register on drop.
2020-06-16 13:33:16 +02:00
Simon Hausmann
0e0ace8591 Separate window from the event loop
Remove the window parameter from the run_event_loop function. Instead
the windows are kept in a global hash map, keyed and retrieved by window
id.
2020-06-16 13:06:56 +02:00
Simon Hausmann
0dd1d953aa Prepare for cleaner separation between window and event loop, part 5
Make the main window a reference counted type. That'll allow keeping
track of all windows safely in the future.
2020-06-16 13:04:43 +02:00
Simon Hausmann
3451048842 Prepare for cleaner separation between window and event loop, part 4
Make run_event_loop operate on a GenericWindow trait. It's still an impl
right now (so static dispatch), but that's just cosmetic.
2020-06-16 11:34:21 +02:00
Simon Hausmann
d3c6ae5c81 Prepare for cleaner separation between window and event loop, part 3
Make run_event_loop a standalone function that takes a mainwindow
parameter. This is in preparation for running with multiple windows.
2020-06-16 11:06:45 +02:00
Simon Hausmann
4b1f50a452 Prepare for cleaner separation between window and event loop, part 2
Move the event loop member out of MainWindow.
2020-06-16 11:03:52 +02:00
Simon Hausmann
91e7107f9e Prepare for cleaner separation between window and event loop, part 1
Move the rendering preparation, actual rendering and input processing
callbacks into standalone functions. They don't
really need to be variable parameters.
2020-06-16 11:03:49 +02:00
Simon Hausmann
0aa4d85c92 Start with data structures for animations, with a duration and basic controls 2020-06-15 18:02:23 +02:00
Simon Hausmann
2f7b46fb90 Improve Rust API
run() on the component can now take a reference instead of consuming the
component.
2020-06-15 18:02:23 +02:00
Olivier Goffart
2fa7005c9a Interpreter: Int32 is a i32, so it can represent the negative numbers 2020-06-15 16:46:27 +02:00
Olivier Goffart
81ce11ee8b Add a reference to the enclosing component in the element itself 2020-06-15 16:40:55 +02:00
Olivier Goffart
58ac9e964c Visit the model expression in the passes that visit the expressions 2020-06-15 14:00:39 +02:00
Olivier Goffart
9adc55cd70 Partially revert the refactoring that changed the Element::children list
Put the information about RepeatedElement in an Option within the normlal Element
2020-06-15 13:42:11 +02:00
Olivier Goffart
c956fb94f0 Put the RepeatedElement in the object_tree 2020-06-15 10:09:32 +02:00
Olivier Goffart
195a5d0e84 Syntax tests: do not try to generate a document tree if the parser did not succeed 2020-06-15 09:37:56 +02:00
Olivier Goffart
f71b778e76 Syntax tests: Log which file is causing a panic 2020-06-15 09:34:41 +02:00
Olivier Goffart
136a90907b Refactor the element children to account for RepeatedElements 2020-06-12 22:24:50 +02:00
Olivier Goffart
e9b75d30b7 Add a bunch of deny(unsafe_code) 2020-06-12 21:04:27 +02:00
Olivier Goffart
95f63795d5 Gate the corelib::rtti module on the rtti feature 2020-06-12 21:04:27 +02:00
Olivier Goffart
7c5ce4fea5 Add missing file 2020-06-12 21:04:27 +02:00
Olivier Goffart
30b201d946 Reduce the use of unsafe in corelib and in the rust backend 2020-06-12 19:03:15 +02:00
Olivier Goffart
bbb2b487b9 Implement a way to create a VRef for non static vtable 2020-06-12 17:09:51 +02:00
Olivier Goffart
e7644eba94 Fix C++ compilation with the new item visitor 2020-06-12 17:09:51 +02:00
Olivier Goffart
66dc643bf9 WIP: refactor the item visitor
The C++ part hasn't been ported yet and some things still need polish

Introduce a visitor to not rely on the unsafe ItemTreeNode array.
2020-06-12 13:32:40 +02:00
Olivier Goffart
58b450b7de Supress warning about unused variable and add a small test
No need to chack that the signal exist since `emit_signal` will
actually return an error in that case already, and this is not
possible to call emit_signal on a invalid signal from the public
API

The test is unrelated
2020-06-12 11:11:45 +02:00
Simon Hausmann
84d8eaa130 Add support for emitting signals for nodejs and the interpreter
This also enables the property and signal accessor test case for js.
2020-06-12 10:38:01 +02:00
Olivier Goffart
ef9d3963e4 Fix casting of conditional operator 2020-06-12 10:32:56 +02:00
Simon Hausmann
9a935bdd0f Provide convenience accessors for public signals in C++ and Rust
Typically their emission requires an evaluation context parameter.
Similar to properties, provide a public emitter function that takes care
of the context.

This also required two fixes in the compiler, in order to make the
following (as part of the test case) work:

    signal foo;
    foo => { ... }

    (1) Register declared signals before attempting to implement the
    connection handlers.
    (2) When looking up the signal property, not only look in the base
    type but also in the current type.
2020-06-11 21:05:52 +02:00
Olivier Goffart
8713c10d48 Color literals 2020-06-11 19:26:41 +02:00
Olivier Goffart
e95d7da888 Parser: typed syntax node accessor 2020-06-11 17:50:28 +02:00
Olivier Goffart
d4594cff97 Introduce a new DeclaredIdentifier syntax kind to disambiguiate identifiers when there are several 2020-06-11 16:55:38 +02:00
Olivier Goffart
788137e3d5 Parser: allow to specify an index token in bracket in the for loop 2020-06-11 16:55:22 +02:00
Simon Hausmann
d0b1f83297 Fix warning in Rust generated code
Allow the property accessors to be unused code
2020-06-11 16:23:53 +02:00
Simon Hausmann
ee1c879071 Extend the conditional expression test case to also test JS/interpreter
The property accessors already work nicely :-)
2020-06-11 15:52:44 +02:00
Simon Hausmann
0cf86dced2 Provide convenience accessors for public properties in C++
See parent commit for the rationale :-)
2020-06-11 15:45:16 +02:00
Simon Hausmann
be3d0ab369 Provide convenience accessors for public properties in C++
While properties declared in the root component are named as-is and
exposed as Property<T>, their get() function in particular is hard to
use because it requires an EvaluationContext as a parameter.

This patch adds get_foo() and set_foo() accessors for each public
property and hides the evaluation context business for the getter.

The added test uses this right away and adds missing test coverage for
the conditional expression.
2020-06-11 15:45:16 +02:00
Olivier Goffart
8b6bb47af8 Create a type alias for Rc<RefCell<Element>> 2020-06-11 15:28:51 +02:00
Olivier Goffart
708e62800d Test that the tree is well formed for what we expect 2020-06-11 15:01:09 +02:00
Simon Hausmann
03bef6dba3 Fix casting with conditional expressions
The following scenario would fail compiling to C++ because we failed to
determine the return type of the conditional expression:

    Test := Rectangle {
        property<bool> condition;
        property<color> extra_color;
        color: condition ? root.extra_color : 4289374890;
    }

The type of the true branch would be color and the false branch would be
a float. Since they "disagree", ty() on the expression would return
Type::Invalid. This was temporarily worked around in the C++ generator
by always returning the type of the true branch, but that's wrong.

Instead this patch changes maybe_convert_to to apply the Cast expression
to the individual branches, placing the cast only to the numberic
literal and correcting the return value of ty() on the conditional
expression.
2020-06-11 13:38:24 +02:00
Olivier Goffart
0d4f370e95 Fix linking error in the tests
We also need to link against corelib
2020-06-10 19:53:06 +02:00
Olivier Goffart
9c23326c60 Layout for the C++ as well 2020-06-10 19:41:24 +02:00
Olivier Goffart
907bea3d3b Layout for rust 2020-06-10 19:41:24 +02:00
Olivier Goffart
96a372e45d Grid layout in the interpreter
current imploementation is just a prototype
2020-06-10 19:40:47 +02:00
Olivier Goffart
ed69f4c432 WIP layouts 2020-06-10 19:40:47 +02:00
Simon Hausmann
26561beea4 Fix wasm build 2020-06-10 19:36:12 +02:00
Simon Hausmann
1a7a95a890 Reformat to pass CI 2020-06-10 18:53:57 +02:00
Simon Hausmann
63f81e1991 Add basic support for conditional expressions
Todo are automated tests and cleaning up the C++ implementation.
2020-06-10 16:04:15 +02:00
Simon Hausmann
fdbef8c3c4 Add support for parsing conditional expression syntax 2020-06-10 15:40:27 +02:00
Olivier Goffart
89968e0722 Add a Slice type which can be used in FFI 2020-06-10 14:23:57 +02:00