Commit graph

67 commits

Author SHA1 Message Date
Olivier Goffart
dd3fa1c221 Make the BindingMap hold RefCell of the BindingExpression
This will allow later to be able to operate on the binding despite the
element is borrowed.

Since the Binding itself is in a RefCell, the analysis don't need to
be anymore.
To do this change, a small change in the binding_analysis logic was required
which means that we will now detect binding loop if a binding was causing
two binding loop. (before, only one binding loop was detected)
2021-11-11 11:14:59 +01:00
Olivier Goffart
a5e1f35f7b Make sure that the BindingExpression with animation always has a binding
Consider this code:
```60
Foo := Rectangle {
   animate y { /*...*/ }
   x: some_binding;
}

Bar := Rectangle {
   foo_instance := Foo {
      y: some_binding;
      animate x { /*...*/ }
   }
}
```
We need to make sure that the binding are set with the right animation.

FIXME: the generator should actually handle this case without needing for inlining.
Also, this currently do not work if there is several level of "inheritence"
2021-11-09 10:22:11 +01:00
Olivier Goffart
3a27a18188 Fix detection of is_set_externally
Otherwise aliases can be optimized when they shouldn't
2021-11-02 11:14:20 +01:00
Olivier Goffart
ab772828e9 Don't try to keep the used_component while doing the inline pass
Because some Component might be inlined, and some other not.
Instead, just call the collect_subcomponents pass.
2021-11-01 13:47:09 +01:00
Simon Hausmann
3987eafa5a Fix child count in item tree when using sub-components
Inline sub-components that are used along with children, similar to @children. This way
we don't need to jump through hoops for the correct children
count in the item tree (or their placement/offset).
2021-10-28 15:52:29 +02:00
Simon Hausmann
c2d757013e Revert "Fix assert in code generator when using sub-components as repeated elements"
This reverts commit 6e8d463d4bb88720a9682c839c5754959dd57c20.

It's better if the generated code for sub-components implements a
root_item function, instead of blowing up the generated code.
2021-10-28 15:52:29 +02:00
Simon Hausmann
0898248044 Fix assert in code generator when using sub-components as repeated elements
We need to inline those because the generator asserts that it's
a built-in element in order to implement `root_item`.
2021-10-28 15:52:29 +02:00
Simon Hausmann
98f6cab553 Make it easier to distinguish between the component types in the generators
Besides `is_global()` add `is_root_component` to Rc<Component>, so that
we can distinguish between the main component (that should have the full
API, etc.) and supplementary components.

This also avoids the generation of unnecessary members when inlining is
disabled.
2021-10-28 15:52:29 +02:00
Simon Hausmann
370e2ca14b Make the inlining pass remove inlined componts from used_types.sub_components
It seems cleaner to do this in the inlining pass, as we initially selectively inline.
2021-10-28 15:52:29 +02:00
Olivier Goffart
32668eed9c Fix a bunch of panic that might occur later as the optimizations happen per component 2021-10-28 15:52:29 +02:00
Olivier Goffart
8622dcb910 Do the default_geometry pass without inlining 2021-10-28 15:52:29 +02:00
Olivier Goffart
67dd409f87 Move a few more passes before inlining 2021-10-28 15:52:29 +02:00
Olivier Goffart
567c644a5f Fix PopupWindow position when all elements are not inlined
Pass a reference to the parent item in the show_popup function
so we can compute the exact location at runtime.
2021-10-28 15:52:29 +02:00
Olivier Goffart
5f07678478 Make the layout pass work on non-inlined tree 2021-10-28 15:52:29 +02:00
Olivier Goffart
7b41f8a4bc Do the popup window pass before inlining 2021-10-28 15:52:29 +02:00
Olivier Goffart
6e5596cdfc Make the repeater pass work on the non-inlined object tree 2021-10-28 15:52:29 +02:00
Olivier Goffart
171a23d7d1 Do the flickable and states passes before inlining 2021-10-28 15:52:29 +02:00
Olivier Goffart
fff6f04be0 Progressively work on pass so they work without inlining
Revert part of the previous commit that tries to do all the pass without inlining

Fixup the few first passes so they work without inlining, but still do a full
inlining for most passes

The goal is to make it work pass by pass until we can have everything without
requiring full inlining
2021-10-28 15:52:29 +02:00
Simon Hausmann
a318df522b Prepare for optional inlining
Even if we make inlining optional, there are *some* situations where we just
need to do the inlining anyway to avoid
needless complexity.
2021-10-28 15:52:29 +02:00
Olivier Goffart
b42c187ed1 Refactor the way the two-ways biding are represented internaly
Don't put them in a fake expression.
This simplifies a bit the expression handling, and will make
possible to fix analysis that needs a vew into the aliases
2021-08-20 18:26:36 +02:00
Olivier Goffart
2c1e39f00e Fix priority when merging two_way_binding
We should not increase the priority when merging two way binding, only when
inlining.

This fixes the iot-dashboard's devices widget which were sometimes not
transparent as they should have been.
This was not deterministic because the order in which the two way binding are
merged is not deterministic because of hash table, and sometimes one binding
ended up having a higher priority as it should have had.
2021-08-17 11:57:35 +02:00
Olivier Goffart
01f11695a7 Properly merge the animation when inlining and removing aliases
Fix #193
Fix #345
2021-07-23 15:25:53 +02:00
Olivier Goffart
ba32777cab Refactoring: move the animation in the PropertyBinding struct
Since they always belong together.

This will help for issue #193
2021-07-23 15:25:53 +02:00
Tobias Hunger
e5bdeaa804 Janitor: Remove unnecessary & 2021-07-07 08:42:28 +02:00
Olivier Goffart
13bd828b96 Update license date 2021-07-02 15:55:54 +02:00
Olivier Goffart
9d2bd11098 Error when having an animation in a transition on a property which is not part of the state
Fixes #255
2021-06-23 13:05:25 +02:00
Olivier Goffart
a97bcd5ae1 Use BTreeMap unstead of HashMap to store the bindings
Because the order is important to keep deterministic error and output
2021-06-18 21:47:00 +02:00
Olivier Goffart
6fae458c2d Properly merge analysis of base component 2021-05-20 13:40:51 +02:00
Olivier Goffart
54be5f3a84 Some ground work to make more binding analysis
- Mark builtin properties that are modified by the native code as output
 - Record wether the property is set by code in the .60
 - Add a field that will tell us if a property binding is constant
2021-05-20 13:40:51 +02:00
Olivier Goffart
21a80f4562 WIP: Layout refactoring
Instead of using a solve_layout function in the component, use property to hold
a layout cache.

This commit only implement the GridLayout and only the interpreter part
2021-05-11 14:59:57 +02:00
Olivier Goffart
a712f515fa Make the viewport element of the flickable a real Element in the object_tree 2021-04-09 19:14:48 +02:00
Olivier Goffart
5dfa2549c8 Put the named reference in a Rc so it will be easier to compute the use count and suck 2021-03-29 15:16:41 +02:00
Olivier Goffart
a8475d062c Fix the priority when inlining and improve debug output
This is just an improvement on 55726cc10d
but is not yet a complete fix for #161, because we do not merge all
bindings that still need to be merged
2021-02-08 10:17:35 +01:00
Olivier Goffart
55726cc10d fix two way binding when they are declared twice
Fix the galery's disable button not disabling most widgets
2021-02-05 18:33:28 +01:00
Olivier Goffart
c479fd132d Fix panic when @children is in the last component
Throw an error instead

Fixes #148
2021-02-02 16:44:09 +01:00
Olivier Goffart
7f78bea8b5 Fix a bunch of cargo clippy warnings in the compiler 2020-12-07 12:54:38 +01:00
Olivier Goffart
4fc2880b98 Fix inlining::fixup_element_references
We need to recurse in the expression
2020-11-27 15:01:51 +01:00
Olivier Goffart
f8f02a13eb Refactor the helper to visit all named reference to take a component
If we want to add more expression or named reference in the component,
we then can just update that function
2020-11-25 17:15:27 +01:00
Olivier Goffart
df318d9104 Fix states in the root of other components 2020-11-20 17:14:04 +01:00
Simon Hausmann
89e0b57627 Rework and simplify the focus handling
Instead of determining the focus item through item tree traversal and
pointer comparison and storing the intermediate indices in the
components in the tree, remember the focus item by a pair of
VWeak<ComponentVTable, Dyn> and item_index: usize.

This speeds up determining the focus item as well as delivering events,
which can now be done directly after retrieving an ItemRef with
get_item_ref.

This also fixes the duplicate line edit focus in the 7gui cells
test case.
2020-11-20 15:33:15 +01:00
Olivier Goffart
88ceeeb3e6 Error when a transition reffers to a state that does not exist 2020-11-20 09:39:06 +01:00
Olivier Goffart
4d4c73925c Some refactoring to prepare for transitions on properties 2020-11-20 09:39:06 +01:00
Olivier Goffart
27a6ff1227 Move Type and related concepts in a different module
Leaving only the TypeRegister in the typeregister module
2020-10-23 11:17:14 +02:00
Olivier Goffart
4fb87f401e Some fixes for the initializations of two way bindings within sub components
There are still more issues
2020-10-20 14:33:06 +02:00
Olivier Goffart
73ccdec73e Fix overwriting value from a component to the other 2020-10-19 20:32:16 +02:00
Simon Hausmann
cf87ac804b Add support for relative lengths
Typically `some_length_prop: 40%` produces an error, but if there's a
matching property in the parent, then it will be allowed and interpreted
as relative value and creates a dynamically updated binding.
2020-10-16 18:54:04 +02:00
Simon Hausmann
9ad8968529 Add support for the initial_focus synthetic property
Setting it will translate to a set_focus_item call in the constructor.

This implements parts of #55
2020-09-30 15:11:01 +02:00
Olivier Goffart
8561106a15 Fix $children when there are two levels of insertion 2020-09-22 17:39:51 +02:00
Simon Hausmann
7976a4057f Improve handling of nested layouts
We support directly nested layouts, but we did not support indirect
nesting:

    GridLayout {
        Rectangle {
            l2 := GridLayout { ... }
        }
    }

This patch fixes that by detecting this scenario and merging the layout
info of the element (Rectangle) and the layout inside (l2). This makes
it much easier to create re-usable components that use layouts
themselves and allows placing them in layouts.
2020-08-28 15:06:14 +02:00
Simon Hausmann
c1aa4b28c6 Add support for children insertion points for components
Sometimes re-usable components need to act as containers that allow the
user to place other items inside. The component needs to be able to
control the placement of these user-provided elements. That is what the
new

    $children

expression inside elements does.
2020-08-28 15:05:21 +02:00