Commit graph

477 commits

Author SHA1 Message Date
Olivier Goffart
8df1217261 Fix slint compiler panic in chiptrack
If a branch that always return has a "void value" and the side that
doesn't return has a value, we need to synthetize a default value
so the struct is complete, even if that value is not used.
2023-11-01 09:51:33 +01:00
Olivier Goffart
9ffe26459f Layout: when using a fixed window size, dissociate the WiondowItem's size with the slint size
If you have a window like so:
```
component W inherits Window {
   width: 200px; // or some other bindings
}
```

Before this patch, it will be converted by the compiler to something like

```
component W inherits Window {
   width: 200px; // or some other bindings
   min-width: width; // (not actual property, but part of the layout_info)
   max-width: width;
}
```

When the window is on the screen, the platform backend will set the max
with and min width on the window manager window to the value from the
layout info.
But slint will also set the width and the height of the WindowItem to
the actual value.  This will break the binding for width if any, and
will also cause the min and max with do be updated, which is wrong.

We haven't had much problem with that before, but with the
ComponentContainer, this becomes a problem as we want to set the width
and height of the inner from the outer by adding a two way binding,
which cause a binding loop at runtime.

The behavior change is that if you have a fixed window size and use that
on a MCU or platform that has a different size, the window will be
cropped or padded but will no longer be resized
2023-10-27 17:45:46 +02:00
Olivier Goffart
db0eb6efbe Fix drop shadow
commit 975abf3c42 introduced a regression.
Two problem:
 - we were taking the geometry from the parent instead of the element
   that need the shadow
 - Element::make_rc override the geometry with its own properties

Unfortunately annot be tested as this only visual, and the software
renderer don't support shadow yet

Fixes #3743
2023-10-24 16:01:33 +02:00
Olivier Goffart
3b7c2d0c5e compiler: Add layout information the the Element 2023-10-24 15:49:12 +02:00
Olivier Goffart
ae4debafe2 Compiler: Don't panic when a Row is repeated in a GridLayout
Fixes #3729
2023-10-23 19:43:46 +02:00
Olivier Goffart
975abf3c42 Don't steal the x and y properties for dummy parents
Parents surch as Opacity, Clip, and co, used to steal the x and y
property of their children, making the property not what they ought to
be.

Now that we refactored recently the code so that geometry need not to be
always linked to a property of the same name, we can dissociate the x
and y property of these generated elements and their content so that the
actual "x" property of the former elementstay some value, despite its
relative item property is now 0.

Had to change a bit of code that was still assuming a literal "height"
or "width" or "y" or "x" property that no longer worked when the
geometry is dissociated from its property

Fix #1072
2023-10-21 07:30:46 +02:00
Tobias Hunger
c1456e5153 component_container: Add background rectangle 2023-10-19 13:22:39 +02:00
Olivier Goffart
166f19aeff
Fix compiler panic when trying to resolve aliases in invalid import
Fixes #3674
2023-10-16 16:37:49 +02:00
Tobias Hunger
caee0b2f9d janitor: Fix a semi-random selection of clippy warnings
Nothing serious in there.
2023-10-16 13:44:37 +02:00
Tobias Hunger
b12575a4c4 janitor: Go over our spell checking setup
* Extend the cspell word list
* Remove those extensions from individual source files
* white-list licenses and such as we should not meddle with those
* Fix spelling
2023-10-16 09:01:51 +02:00
Tobias Hunger
283ef4b461 compiler: Implement resource URL remapping
This is used in slintpad to map relative image URLs to their real
download locations.

This has the side-effect of removing the service worker.

Fixes: #2905
2023-10-12 21:41:26 +02:00
Tobias Hunger
20908dacb8 compiler: Fix image resolution for WASM
Resolve an image path to soemthing relative to the syntax node that
pulls it in if the path can not get resolved.

This typically happens in WASM as file existence is checked during image
resolution, which is not possible there.
2023-10-12 19:15:53 +02:00
Olivier Goffart
6f61a45bec compiler: Simplify struct access expression of constants after struct-cast
We see that a lot in the fluent style. For example:
```
   font-size: Typography.body.font-size;
```

Where Typography.body is a contant expression define as
```
    out property <TextStyle> body: {
        font-size: 14 * 0.0769rem,
        font-weight: regular-font-weight
    };
```

But because this first converts from an annonymous tuple struct to a
named struct, the const propagation used to be confused. Now with this
patch it is properly simplified

Before this change

cargo run -p slint-compiler -- examples/printerdemo_mcu/ui/printerdemo.slint -f rust | rustfmt | wc
  38643   84506 1925846
cargo run -p slint-compiler -- examples/gallery/gallery.slint -f rust | rustfmt | wc
 103210  224427 5291034

After this change

cargo run -p slint-compiler -- examples/printerdemo_mcu/ui/printerdemo.slint -f rust | rustfmt | wc
  38629   84473 1924995
cargo run -p slint-compiler -- examples/gallery/gallery.slint -f rust | rustfmt | wc
  102628  222423 5261760
2023-10-12 14:21:08 +02:00
Olivier Goffart
762c21890c Compiler: be more granular for checking for explicit layout constraint
Layout code generates a lot of code and it may be beneficial not to
generate constraints if there is no constraints in that direction

Before the change:

cargo run -p slint-compiler -- examples/printerdemo_mcu/ui/printerdemo.slint -f rust | rustfmt | wc
  40014   86643 2010535
cargo run -p slint-compiler -- examples/gallery/gallery.slint -f rust | rustfmt | wc
  105715  229009 5434115

After this change:

cargo run -p slint-compiler -- examples/printerdemo_mcu/ui/printerdemo.slint -f rust | rustfmt | wc
  38873   83654 1925830
cargo run -p slint-compiler -- examples/gallery/gallery.slint -f rust | rustfmt | wc
  103817  224874 5316553

No measurable changes in compilation time.
2023-10-12 12:55:00 +02:00
Olivier Goffart
8f001ac490 Add support for protected functions
Protected function can only be called from the direct base

Issue #3636
2023-10-11 10:50:50 +02:00
Tobias Hunger
0ff8e2cdb6 compiler: Rework path handling
Add some code to do platform-independent path processing.

This is necessary aas WASM does e.g. not have any absolute paths and
such and the compiler tended to produce wrong results in that case.

Side-effect: We no longer need to depend on `dunce`
2023-10-10 20:04:47 +02:00
J-P Nurmi
8dd51f76f1
Fix named exports in native code (#3602) 2023-10-05 16:41:10 +02:00
Olivier Goffart
661080676a Compiler: fix conversion of array of array of structs
When finding the common types for array of array, we must recurse in the
inner type

Fixes: #3574
2023-10-02 19:00:21 +02:00
Guiguiprim
05cdf88871
Add spacing-horizontal and spacing-vertical to layout (#3532) 2023-09-28 13:49:28 +02:00
Olivier Goffart
a128f57c31 Fix setting default geometry on Rectangle
Since they no longer have a builtin width/height property, the test
that checked the type was wrong. But since we can't override the width
or height property with another type, this should not be relevant
2023-09-13 16:08:37 +02:00
Olivier Goffart
2e5b98ba88 Fix optimization pass removing rectangle that have a x and y set 2023-09-13 16:08:37 +02:00
Olivier Goffart
40a549d6f0 Revert "WIP Take new geometry into account in useless_rectangle"
This doesn't work yet as we need to do more "patching" of anything that
uses the x and y properties

This reverts commit 2d6fec78f9ff01c8b4904685fae0ce587a3c8e9a and
036ddfe23aa5f5b63778b8056d58c30c08f942fe.
2023-09-13 16:08:37 +02:00
Guilhem Vallat
942190e29d WIP Take new geometry into account in useless_rectangle 2023-09-13 16:08:37 +02:00
Guilhem Vallat
5388e01d0d WIP Take new geometry into account in useless_rectangle 2023-09-13 16:08:37 +02:00
Guilhem Vallat
d3a2fc4cd5 fix lower_shadow: correctly create ElementRc
I would love to add a clippy disallowed method for this, but it's a
generic type alias.
2023-09-13 16:08:37 +02:00
Guilhem Vallat
7410d16380 fix resolve_native_classes pass 2023-09-13 16:08:37 +02:00
Olivier Goffart
2b44ed47a2 Fix PopupWindow positioning
The WindowItem did not have a x or y before, so these property
were unused for it's geometry(), but now it is used in the new
item_geometry on the ComponentVTable.
So make sure we don't initialize them
2023-09-13 16:08:37 +02:00
Olivier Goffart
31252547e0 Fix generation of geometry prop for some primitives 2023-09-13 16:08:37 +02:00
Olivier Goffart
e0fd9a6105 WIP: Add item_geometry to the ComponentVTable
(unused yet)
2023-09-13 16:08:37 +02:00
Olivier Goffart
2a8ebb9752 Flickable: don't make the viewport special
Instead: add the viewport propety directly in the Flickable

Simplifies the compiler's code generation a bit
2023-09-13 16:08:37 +02:00
Simon Hausmann
3652f58a3f Change item indices from usize to u32
So that the compiler and run-time can never disagree on the
number of bytes the item index can use.
2023-09-12 08:53:58 +02:00
Olivier Goffart
cf19749943
Make a pass to remove the Expression::Return instruction
So it doesn't appear in the LLR and the C++ codegen can be simplified.
In particular, this removes the need to throw/catch exception to handle return
across generated lambdas
2023-09-06 14:10:26 +02:00
Olivier Goffart
dac5016771 Warn when using a Path with the software renderer
CC: #2026
2023-08-31 12:37:48 +02:00
Olivier Goffart
ff3ca79258
Software renderer: fix the rendering of svg with transparency
resvg renders the svg with premultiplied alpha. So we need to take that
into account when pre-rendering images
2023-08-24 09:39:07 +02:00
Olivier Goffart
f100ee48ff Fix alias to externaly modified property not being marked as such
In the case of bug #3318, the implicit alias to the window's height or
width was removed but the propery was not marked as externaly modified,
causing later pass to optimize and inline things that shouldn't

Fixes #3318
2023-08-22 16:20:13 +02:00
Olivier Goffart
a310fdc912 Fix panic when parsing invalid gradiant
Fixes #3241
2023-08-09 21:20:54 +02:00
Tobias Hunger
5db78b6dd2 Implement LLR code lowering for ComponentContainer 2023-07-27 12:04:16 +02:00
Tobias Hunger
689238a3af Lower ComponentContainer into two objects
... so that we have one that controls the embedding operation and one
that we can turn into a dynamic tree node where the actual embedding
happens.

Mark the placeholder Element as `is_component_placeholder` and make sure to not
optimize out that object in a later pass.

Adapt Element creation to account for the new
`is_component_placeholder`.
2023-07-27 12:04:16 +02:00
Tobias Hunger
eb84994e7a Add lower_component_container pass
Do some diagnostics in that pass.
2023-07-27 12:04:16 +02:00
Olivier Goffart
5dea1f1d29 compiler: Fix loading relative path to the workdir
This should in principle not be allowed, it should be relative to the
file itself.
Make it a warning, and at least, don't duplicate the globals

Fixes #2719
2023-07-24 18:21:53 +02:00
Guiguiprim
ef8ddaaa1d
Add native support for min/max 2023-07-21 16:26:41 +02:00
Olivier Goffart
d5d772dcbd
Compiler: Visit the model and other "side" named reference in binding_analysis (#3109)
This is necessary for the `is_used` to be set properly

Fixes #3107
2023-07-19 09:53:38 +02:00
Olivier Goffart
c990660500 Run the import pass even when building the object tree fails.
This improve the code coverage of syntax_text, so some adjustment had to
be made.
This may add more error in the main file, but this make it the same
behavior as for imported files and lsp who were already running these
passes all the time
2023-07-14 14:13:48 +02:00
Olivier Goffart
81e5d3bb36 Fix setting rotation-angle and opacity from a callback
... if they are not set as actual binding before

As reported in #3068

The problem is that the pass will properly create the Rotation or
Opacity item, but will not create the two way binding if there is no
existing binding. This causes code like `img.rotation-angle = ...` to
change the rotation angle of the image, but not its parent Rotation
item.
Fix it by making sure there is always a binding.

Since the change only affect visual representation, I abused one of the
screenshot test to test this feature. And I also patched another bug
that some #[allow(unused_parens)] was not set in the 'init' callback and
would cause a warning in the test
2023-07-11 20:07:49 +02:00
Aurindam Jana
5a4a7fee63
Update royalty free license to 1.1 (#2994) 2023-07-10 10:12:11 +02:00
Olivier Goffart
03bed94072 Fix default geometry of items with inject_element_as_repeated_element
Fixes #3027
2023-06-30 17:35:29 +02:00
Tobias Hunger
e02c360000 Clippy polish 2023-06-28 14:22:30 +02:00
Simon Hausmann
016d776b7d Simplify implementation of absolute-position
Since we materialize only one point property, we don't need to cache the
parent position in a separate property, but we can just store that in
the binding.
2023-06-21 10:02:04 +02:00
Simon Hausmann
ab0e38c76d
Merge absolute-x and absolute-y "virtual" properties into absolute-position (#2942)
The type of thep property is `Point`, which existed before. It was
mapped to `slint::private_unstable_api::re_exports::Point` (euclid) and
is now mapped to slint::LogicalPosition (also in C++).
2023-06-21 08:17:57 +02:00
Simon Hausmann
653b63a35e Port to resvg 0.34 2023-06-18 08:58:09 +02:00