Commit graph

177 commits

Author SHA1 Message Date
Olivier Goffart
66370b6bda
Add export { ... } from "....slint"; syntax. (#5533) 2024-07-03 12:50:40 +02:00
Olivier Goffart
c144dc71b0 Fix change callback on an alias 2024-06-28 10:45:45 +02:00
Olivier Goffart
a63618fcfe Fix error messages with invalid change callback 2024-06-28 10:45:45 +02:00
Olivier Goffart
42a2c6a569
Only generate code for the exported Window
Have a warning when a component is exported from the main file and
doesn't inherit Window.
Unless it's the last component, for compatibility with Slint 1.6

Also don't warn in the interpreter
2024-06-25 15:13:06 +02:00
Tobias Hunger
0639b9a61b janitor: Fix clippy "bound is already specified as the supertrait" 2024-06-24 14:59:47 +02:00
Olivier Goffart
3764312561
Generate multiple components in Rust and C++ (#5449)
When lowering to the LLR, generate one PulbicComponent for each exported
component in the main file

Closes #784
2024-06-24 10:03:19 +02:00
Olivier Goffart
408637a677 Remove the is_root_component within the component
There will be serveral roots, so this makes no sense.
2024-06-21 11:58:09 +02:00
Olivier Goffart
acb7da11d2 fix missing warning of missing export
... for last component when globals are exported
2024-06-21 11:57:49 +02:00
Olivier Goffart
a4c0cc9f09 Move the used_types from the (root) Component in the Document
Preparation for multi-components

Note that this had to rename one instance of TextStyle because it
conflicts with the struct of the same name used in the FontSettings
in the style. This wasn't a problem before because it shares some
property in common, and the the order of processing of component has
changed leading to the other one being generated.
(But that is a wider bug in the compiler outside of the scope of this
refactoring)
2024-06-20 12:03:38 +02:00
Olivier Goffart
2fd8744cfc compiler: Move embedded_file_resources from the root Component to the Document 2024-06-20 12:03:38 +02:00
Tobias Hunger
c55f0a9b0e compiler: Add a snapshotter to help create snapshots of compiler state
Use this snapshot to keep a unoptimized typeloader around, so that the preview
does not need to do another parsing run.

Move the document cache in the preview over to use the snapshot.
2024-06-12 10:15:29 +02:00
Olivier Goffart
60e7d54e67 Compiler better test coverage in case of error and fix panics
The compile_syntax_node was used by the syntax_test in case of error
to still cover the coverage, but commit e3908cfce6
made this function a noop when there is an error already.

The LSP does try to build an object tree even though there are error in
order to have the most information even in that case, so we must ensure
that it doesn't panic left and right.

This commit also fix some of these panics.
2024-06-11 19:22:59 +02:00
Olivier Goffart
47a61dda10 Fix compiler crash with invalid code 2024-06-11 19:22:59 +02:00
Olivier Goffart
a780dd4905 Testing: Fix duplicated accessibility element
This fix the C++ todo test that wasn't run because of a typo

When an element is optimized in another one, only the first one should
report the accessible properties. (because element with accessible
properties cannot be optimized so they are always the first)
2024-06-07 13:18:12 +02:00
Simon Hausmann
1a8ce3c659 Add support for optimized rectangles in ElementHandle
Keep merging elements, but remember the boundaries in the debug info, separated by a slash.

Also fixed tests that rely on accessible-label being set only once. For example

```
Button { text: "foo"; }
```

will certainly have "foo" as accessible-label on `Button`, but its internal `Text` element has
an implicit "accessible-label" set to the same
value.

So don't rely on that for now but search by id instead.
2024-06-05 01:29:58 -07:00
Simon Hausmann
4eef2d4936 WIP: Add find_by_element_type_name 2024-06-05 01:29:58 -07:00
Olivier Goffart
43a336b534 C++ part of element_ids
Simplify a bit the llr generation so that there is less code duplication
between Rust and C++
2024-06-05 01:29:58 -07:00
Simon Hausmann
73b5136f98 WIP: Search by qualified element id 2024-06-05 01:29:58 -07:00
Tobias Hunger
b4c89bb29a janitor: Fix warning about using for to iterate over an &Option 2024-06-03 16:59:54 +02:00
Aurindam Jana
3523e86359
Simplify commercial license (#3063)
Base the commercial license on the Royalty-free license adding clauses pertaining to the fees.
2024-05-31 14:06:17 +02:00
Aurindam Jana
9a3aa265d5
Update Royalty-free license (#5257)
Add clarification that Application may not expose Slint APIs.
2024-05-31 10:53:19 +02:00
Olivier Goffart
bc8e18e148 Fix compiler panic when trying to set a function in a state
Fixes #5246
2024-05-28 17:25:15 +02:00
Florian Blasius
310b01a2e2
ComboBox reset current on model changed (#5217)
---------

Co-authored-by: Simon Hausmann <simon.hausmann@slint.dev>
2024-05-15 14:28:57 +02:00
Olivier Goffart
25ef8f8711 Fix declaring callback alias that override a property
Do the check for existing property before handling of callback aliases

Fixes #5205
2024-05-10 13:50:04 +02:00
Tobias Hunger
2e3b00e38e janitor: Fix some clippy warnings pre-release
Nothing that should be controversial, but the
`internal/compiler/builtin_macros.rs` could point to a thinko in the original
commit.
2024-05-06 16:47:14 +02:00
Olivier Goffart
af1aa2991e
Fix component that inherits from PopupWindow
This regressed in commit 12d904a71c
which changed the order of the pass to get the lower_popup pass before
the first inlining pass.
If by chance (which is likely if one have children), the component that
inherits from PopupWindow was inlined in that pass, it would be as
if it was not a component, and it would be removed from its parent.
But since it is no longer inlined, we need to support that case and
delay the removal when processing the component that holds that popup.
2024-05-06 13:20:25 +02:00
Olivier Goffart
c5f857ffc9 Change callback: gate behind experimental flag 2024-05-02 22:25:53 +02:00
Olivier Goffart
2e4d1f2427 WIP: work on changed callback 2024-05-02 22:25:53 +02:00
Olivier Goffart
12d904a71c
Fix compiler panic with init in a component inlined into a repeater
The problem was that the code from #4322 inlined the init code in the
parent Component as at that point, the per-repeater component don't
exist yet.
Fix it by removing the workaround from #4322, but changing the order of
the passes so that the init code are already proccessed before any
inlining. This required to change the order of a bunch of passes.

Fixes #5146

As a drive-by, also add the missing C++ implementation of set_animated_value
for Brush that was discovered by the test. (Code wouldn't compile)
2024-04-29 15:34:12 +02:00
Aurindam Jana
0cfeec1a31
Update Slint Community License (#4994)
Updated the version from 1.1 to 1.2 
Renamed the header to "Slint Royalty-free Desktop, Mobile, and Web Applications License"
Added definition of "Mobile Application" and grant of right
Moved "Limitations" to 3rd section and "License Conditions - Attributions" to 2nd section
Added flexibility to choose between showing "MadeWithSlint" as a dialog/splash screen or on a public webpage
Moved the para on copyright notices to section under "Limitations"
2024-04-15 15:18:55 +02:00
Olivier Goffart
18eea8602a Fix insertion point of @children
Don't always appends at the end

Fixes #4935
2024-03-26 18:14:14 +01:00
Tobias Hunger
28b96ca6f6 janitor: manual cargo clippy fixes
Semi-random selection of clippy topics that were
uncontroversial before:-).

Leaves about 84 deduplicated issues in the code base
according to clippy from nightly.
2024-03-14 13:42:38 +01:00
Olivier Goffart
11e8070726 Compiler: fix lookup of the model not seeing that the element is being repeated
The problem is that we were taking the whole `repeated` field and as a
result we wouldn't see that the element was being repeated and that we
shouldn't have to lookup id within it

Fix #4683
2024-02-26 12:16:51 +01:00
Olivier Goffart
fac0921579 Compiler: keep the layout debugging info next to its node 2024-02-21 11:33:37 +01:00
Olivier Goffart
09dc25f107 Keep all nodes for a given element (even if it is optimized out) 2024-01-25 14:45:22 +01:00
Olivier Goffart
ffaf19812c Refactoring: use Element::to_source_location instead of the node directly 2024-01-25 14:45:22 +01:00
Tobias Hunger
9142336d5c interpreter: Add highlighting feature-gated functions
The preview can not leave it up to the interpreter to handle element selection
and highlighting. So add new functions to the interpreter (behind the
"highlight" feature-gate) to query positions of elements.

This exposes some of the code that is used by the existing highlighting code
and extends it where needed.

Two use-cases need to be covered:

1. Query the positions of a component (given by source file path and offset).
   This is then used to highlight all occurences of a component as the
   cursor position in a source file changes.

2. Query the position of an element (given as `ElementRc`).
   This is used when selecting elements in the UI. We need to work at
   the element level for this, not at the component level.

Also make the `highlight` module public but feature-gated, so that we
can put helper-types there.
2023-12-20 19:28:35 +01:00
Tobias Hunger
2404cce0bc janitor: Fix typos 2023-12-19 17:04:33 +01:00
Olivier Goffart
85526d772e Fix detection of properties when they are only used in two way bindings
Fixes #2166
2023-12-19 11:14:53 +01:00
Olivier Goffart
5d4c390b0f
Compiler: Error when assigning to compile time properties
Some property need to be known at compile time. We already had checks
that the binding is a compile time constant, but there was no check to
prevent, say

    self.row = 42;

which wouldn't work or could even cause panic or miscompilation of
generated code

Closes #4037
2023-12-12 21:51:56 +01:00
Olivier Goffart
3b7c2d0c5e compiler: Add layout information the the Element 2023-10-24 15:49:12 +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
d72dbb1386 compiler: Fix font loading
Get the full path before deciding what to do.
2023-10-12 19:15:53 +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
Guilhem Vallat
aada8bb485 include geometries in Element debug print 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
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
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
Olivier Goffart
57e9b5b796 Don't panic when an unresolved alias has a binding
Fixes #3085

When there are both a binding and a two way binding, we must keep the
two way binding in our bindings map. Otherwise type inference will not
work
2023-07-14 14:13:48 +02:00