Commit graph

255 commits

Author SHA1 Message Date
Simon Hausmann
3d5fbc76fe Prospective fix for the printer demo not loading in the online editor
Commit fa1ac9884d introduced an early check for the existence
of the specified font files. However we should only do that for local files for now.
2022-01-20 10:37:29 +01:00
Simon Hausmann
fa1ac9884d Verify the existence of imported custom fonts
... and produce diagnostics.

That way in later phases we don't need to check again.

As an unfortunately side-effect, we need to skip one of the examples in
the language reference from the doc test, as the compilation fails
because the font does not exist.
2022-01-19 16:24:22 +01:00
Olivier Goffart
bfa344415a LLR: Add back the index of first children in the runtime sub component
Using #component_id::item_tree for it does not work because the
public component id is not the right one, we need the one from
the current item tree which is not known at compile time
(could be several if the component is re-used accross item trees)

Also disable the code that sets the focus to the focued element for anything
but the window component: before, the setup code was only run for the
non-sub component, but now it is run for every sub component, and we
don't want to set the focus to anything that has a forward focus property
2022-01-12 16:22:35 +01:00
Tobias Hunger
4c331f1ac2
janitor: More clippy fixes
None of these should be controversial: It is all similar to quick fixes
I pushed before.
2022-01-09 14:50:58 +01:00
Tobias Hunger
3e448f75eb
janitor: Remove some unnecessary references
These are immediently dereferenced by the compiler according to clippy.

Remove some now unnecessary muts to make things build again.
2022-01-04 18:22:15 +01:00
Tobias Hunger
c89fa46b2c
janitor: Remove some redundent clone() calls 2022-01-04 18:20:24 +01:00
Tobias Hunger
75e97a43fa
janitor: Fix clippy::to_string_in_format_args warning
Do not use to_string() when formating something that has the `Display`
trait.
2022-01-03 21:35:21 +01:00
Tobias Hunger
bfca0e3573 Mass update copyright messages to be more REUSE compliant 2021-12-22 10:06:12 +01:00
Simon Hausmann
ffd651d04c Fix rendering of opacity when used on repeated elements
Opacity, visible and shadows on repeated elements work by replacing the
root element with a new element (opacity, visible clip, etc.) and making
the old one a child.

A tree like this

```
l := VerticalLayout {
    for i in 1: Rectangle {
        background: green;
        opacity: 0.2;
    }
}
```

is lowered like so (pseudo):

```
l := VerticalLayout {
    for i in 1: Opacity {
        opacity <=> r.opacity;
        r := Rectangle {
            background: green;
            opacity: 0.2;
            y: layout_cache[i].y;
            width: l.width;
            height: layout_cache[i].height;
        }
    }
}
```

and when rendering, it's important that the opacity of the Opacity
element is applied on the item renderer before rendering the Rectangle
r.

The Opacity element has no width/height because the default geometry
pass won't apply that to children of a layout.

Without a geometry, the item rendere will not call render() (no
intersection with the current clip), and thus the opacity is not
applied.

The shadow lowering pass handles this correctly, by moving the geometry
property bindings to the new root and letting the default geometry pass
apply 100% defaults (in the above "r" is not a layout child).

This patch moves this logic into the common
inject_element_as_repeated_element, so that we end up with a lowering
like this (after the default geometry pass):

```
l := VerticalLayout {
    for i in 1: op := Opacity {
        opacity <=> r.opacity;
        width: l.width;
        height: layout_cache[i].height;
        y: layout_cache[i].y;
        r := Rectangle {
            background: green;
            opacity: 0.2;
            width: op.width;
            height: op.height;
        }
    }
}
```
2021-12-14 14:32:46 +01:00
Olivier Goffart
d1cae710df preprocess the images at compile time
For the MCU port, we need to proccess the image to save them in the binary
in a convenient format.
This patch start this work by trying to anaylyze what format should an image
be using, and saving it as a texture in the binary.

The current graphical backend and the C++ frontend are not yet supported
2021-11-19 15:54:45 +01:00
Olivier Goffart
125ab12816 Don't take the binding when calling visit_element_expressions
So that we can visit the expression and the property reference
still have a meaning
2021-11-11 11:14:59 +01:00
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
a3bafb59f0 Don't mark the internal components as pub 2021-11-08 16:46:13 +01:00
Simon Hausmann
e0f3e6b782 Fix the C++ printer demo with disabled inline
For the following reduced test-case the order in how the dynamic nodes
in the item tree were generated (and dyn indices assigned) differed from
the way the visit_dynamic_children slots were generated:

```
Blah := Rectangle {
    for x in 1: Text {
        text: "Should be on the right";
    }
}

MainWindow := Window {
    width: 772px;
    height: 504px;
    Text {
        if (false): TouchArea {
        }
    }
    Blah {
        x: 200px;
    }
}
```

The item tree node was constructed using build_item_tree, which
basically assigned dyn index 0 to the "repater" for the touch area
and "1" to the one for the repeater inside the sub-component.

Afterwards we traversed the element tree - without descending into the
sub-components - to generate the fields and the dispatch in in the
dynamic visitor. Here a subtle order would result in a mismatch of
indices:

recurse_elem_level_order would end up visiting Text, Blah and then
Text's children, assigning the first dynamic index to Blah.

This is now fixed by merging the two iterations into one.
2021-11-04 11:03:44 +01:00
Simon Hausmann
2a8c004a7e Fix repeated elements in C++ sub-components
Delegate the visitation of dynamic children. Fixes test_cpp_models_for.
2021-11-03 12:35:32 +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
Simon Hausmann
ae25dd3d07 Fix calls to BuiltinFunction::ImplicitLayoutInfo for sub-components in C++
Provide a layout_info implementation for sub-components and call it. This
disables the lowering the implicit_layout_info call again,
also to ensure that when this
is installed from the use-site of the sub-component, the self can be used to obtain
the info (by calling the new generated function).
2021-10-28 21:49:07 +02:00
Simon Hausmann
cebb415b08 Replace two uses of build_array_helper with a new recurse_elem variant
For the item index generation and the member population for the C++
structs, a level-order variant of `recurse_elem` is sufficient - as also
indicate by the unused item index parameters.
2021-10-28 15:52:29 +02:00
Olivier Goffart
f833c944de Make sure we do not optimize away properties used from other components 2021-10-28 15:52:29 +02:00
Olivier Goffart
c823b41942 Rename is_set_derived by is_set_externally
Because this hasn"t much to do with derived
2021-10-28 15:52:29 +02:00
Simon Hausmann
82b5c3bcce Fix the item index generation to take sub-components into account
A regular element where the base type is a built-in item uses one slot,
while a sub-component expands to multiple nested built-in items.
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
Olivier Goffart
9c6bc6afc7 Do the property analysis accounting for several component 2021-10-28 15:52:29 +02:00
Simon Hausmann
9028f69f27 C++ generator cleanup: Remove supplementary_components field again
This amends the parent commit, we don't need a separate vec, after
inlining the sub_components should simply be empty.
2021-10-28 15:52:29 +02:00
Simon Hausmann
b5f4a2c27c C++ generator: begin generating code for supplementary components
The generation is still incomplete, but this change passes them to the C++ generator
when not inlining.

Another option would've been a "inline: bool", but that won't suffice in
the future when we may want to use heuristics to selectively inline some
and others not. And always taking used_types.sub_components is wrong
when inlining as those are ... inlined.
2021-10-28 15:52:29 +02:00
Olivier Goffart
2767ceb10b Make the visible pass work on the non-inlined tree 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
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
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
b99ff1b766 Put filename in quote in import errors
So that the `debug_assert!` that fires when a error message ends with a
period does not crash the LSP when typing an incomplete filename that ends
with a '.'
2021-10-07 14:44:12 +02:00
Olivier Goffart
72d556113f Visit globals when finding usages of structs
Otherwise some used struct might not be found, and they can cause
compilation failure in the generated C++ or Rust code

Fixes #549
2021-10-06 18:48:06 +02:00
Olivier Goffart
fd435ec270 Fix the default Text color overriding a color specified in a two way binding
We just need to adjust the priority of the default binding to be a high value
(eg, less priority) since the other values must always win.

This fixes the placeholder text color
2021-09-30 12:48:19 +02:00
Simon Hausmann
5ee005c972 Fix panic in LSP when declaring animation on layout controlled property
When an animate foo {} declaration ends up creating an synthetic, invalid BindingExpression,
we still need to give it a span, to ensure that the diagnostics
produced later have *some* location set.

Fixes #515
2021-09-22 16:01:29 +02:00
Simon Hausmann
70581ccb37 Internal cleanup: simplify string comparison 2021-09-15 07:56:28 +02:00
Simon Hausmann
a855d868fc Add support for introspecting globals in the interpreter Rust API
Add three straight-forward functions:

    * pub fn globals(&self) -> impl Iterator<Item = String> + '_
    * pub fn global_properties( &self,
          global_name: &str,
      ) -> Option<impl Iterator<Item = (String, ValueType)> + '_>
    * pub fn global_callbacks(&self, global_name: &str
      ) -> Option<impl Iterator<Item = String> + '_>

Implementation wise this requires passing along a way to get the
non-normalized (original) export name, as globals() should return the
names as the developer/designer specified them, and
global_properties()/global_callbacks() normalizes.
2021-09-15 07:56:28 +02:00
Simon Hausmann
4d3f08d954 Allow global singletons to have default callback handlers
It's already working, we just need to remove the error handling :-)

Fixes #467
2021-09-06 13:56:27 +02:00
Simon Hausmann
ffc2c81bd0 Fix code comment about names of exported global 2021-08-31 17:09:11 +02:00
Simon Hausmann
ee8e5699e5 Clean up global alias handling
Remove the internal name again and pick the first exported one when
assigning ids. This avoids internal names showing up in code completion
or the internal types leaking into generated code.
2021-08-31 17:09:11 +02:00
Simon Hausmann
0d19e2d9b9 Add support for global aliases
When exporting an global multiple times under different names, make sure
that they alias in the generated code.

As a consequence, the compiler maintains the original unique name and in
Rust and C++ makes only the exported names public. In the interpreter
the internal name is theoretically still accessible from the outside.
2021-08-31 17:09:11 +02:00
Simon Hausmann
ab522eb147 Produce errors when exporting a name multiple times 2021-08-31 10:19:50 +02:00
Simon Hausmann
9868b693e2 Only publish exported globals in C++ and Rust 2021-08-27 13:36:48 +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
Tobias Hunger
c7d27d5ace Janitor: Fix clippy::redundant_clone 2021-08-18 00:24:51 +02:00
Olivier Goffart
143510b593 Set the width of items in a ListView
Fixes #408
2021-08-13 11:57:56 +02:00
Olivier Goffart
7859e2f06e Fix opacity property at the root of a repeated element in layout
This fix the layout of the printing-queue in the printer demo
2021-08-12 20:10:21 +02:00
Simon Hausmann
144d1bed36 internal cleanup: replace use of imported function with qualified use 2021-08-12 18:07:58 +02:00
Olivier Goffart
c25538c982 Normalize identifiers to - instead of _
As a result
 - The error messages will now show the error with `-` instead of `_`
 - The LSP will auto-complete with -
 - The interpreter's list of properties will list the property with '-'
   (but we made the change so that set_property, get_property, and so on
   work also if passed a '-')
2021-08-10 22:21:01 +02:00
Olivier Goffart
b6137ecbc4 Error when trying to use internal builtin items 2021-08-09 17:43:22 +02:00
Tobias Hunger
58fa485b56 Janitor: Fix clippy::into_iter_on_ref 2021-08-09 13:19:34 +02:00