Commit graph

184 commits

Author SHA1 Message Date
Olivier Goffart
172dcfa775 C++: fix crash when accessing empty model from Slint
Fixes #3704
2023-10-19 18:09:14 +02:00
Tobias Hunger
88170937e9 janitor: Fix clippy error
That's the only one this time round.
2023-10-16 13:44:37 +02:00
Olivier Goffart
4bbfbd541b Prospective fix for MSVC warnings
Warning looks like that

```
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.35.32215\include\tuple(144,47): warning C4244: 'initializing': conversion from '_Ty' to '_Ty', possible loss of data [D:\a\slint\cppbuild\examples\virtual_keyboard\cpp\virtual_keyboard.vcxproj]
            with
            [
                _Ty=int
            ]
            and
            [
                _Ty=float
            ]
  C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.35.32215\include\tuple(239): message : see reference to function template instantiation 'std::_Tuple_val<_This>::_Tuple_val<_Ty>(_Other &&)' being compiled [D:\a\slint\cppbuild\examples\virtual_keyboard\cpp\virtual_keyboard.vcxproj]
            with
            [
                _This=float,
                _Ty=int,
                _Other=int
            ]
  C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.35.32215\include\tuple(239,81): message : see reference to function template instantiation 'std::_Tuple_val<_This>::_Tuple_val<_Ty>(_Other &&)' being compiled [D:\a\slint\cppbuild\examples\virtual_keyboard\cpp\virtual_keyboard.vcxproj]
            with
            [
                _This=float,
                _Ty=int,
                _Other=int
            ]
  C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.35.32215\include\tuple(802): message : see reference to function template instantiation 'std::tuple<float,float,float,float>::tuple<std::_Exact_args_t,int,float,float,int,0>(_Tag,_This2 &&,float &&,float &&,int &&)' being compiled [D:\a\slint\cppbuild\examples\virtual_keyboard\cpp\virtual_keyboard.vcxproj]
            with
            [
                _Tag=std::_Exact_args_t,
                _This2=int
            ]
  C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.35.32215\include\tuple(802,12): message : see reference to function template instantiation 'std::tuple<float,float,float,float>::tuple<std::_Exact_args_t,int,float,float,int,0>(_Tag,_This2 &&,float &&,float &&,int &&)' being compiled [D:\a\slint\cppbuild\examples\virtual_keyboard\cpp\virtual_keyboard.vcxproj]
            with
            [
                _Tag=std::_Exact_args_t,
                _This2=int
            ]
```
2023-10-09 17:25:24 +02:00
Olivier Goffart
a5488d6285 Rename RepeatedComponent -> RepeatedItemTree
And some more cleanups
2023-10-09 11:01:56 +02:00
Olivier Goffart
852b4d906d Rename ComponentVTable to ItemTreeVTable
and their related name.
Also move the component module in the item_Tree module
register_component -> register_item_tree
ComponentItemTree -> ItemTreeNodeArray

For #3323

Rationale from that issue:

Right now, we use the term `component` in the Slint language and in the compiler to be a a tree of elements that can be used as an element in a .slint file.

The term is also currently used in the runtime as a tree of runtime Items that are allocated together. (declared in ComponentVTable)

But there are no 1 to 1 mapping between a `component` in the slint language, and a runtime Component.
(for example, the items behind a `if` or `for` or `PopupMenu` are in a different runtime component. And `component` declared in Slint are often inlined)

So we should rename the internal runtime `Component` to  `ItemTree`

The currently public `slint::ComponentHandle` wraps the "root" of the ItemTree, but that's ok because it is generated from a .slint `component`,  so it doesn't change name
2023-10-09 11:01:56 +02:00
J-P Nurmi
8dd51f76f1
Fix named exports in native code (#3602) 2023-10-05 16:41:10 +02:00
Olivier Goffart
57ac24e776 Fix compilation of the generated code with deny(rust_2018_idioms)
Fixes #3524
2023-09-22 10:21:00 +02:00
Olivier Goffart
f546d22861 C++: Fix crash when deleting a component from the click event within a sub component
The parent is already deleted when we delete the component that is kept
alive by the `grabber` ItemRc in `handle_mouse_grab`
When the ItemRc goes out of scope, we delete the component, but the
parent was already gone.

This doesn't solve a broader issue that we use the parent in many place
and it is not kept alive (for example when using properties of the
parent)
2023-09-14 11:34:18 +02:00
Olivier Goffart
196f14e89f rust: return LogicalRect for inner item_geometry functions
(More in line to what C++ does)
2023-09-13 16:08:37 +02:00
Olivier Goffart
e04835d209 Fix computation of the item sub range
We need to account for the repeater count in the item sub-range
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
Simon Hausmann
21d44e3a31 Fix data section placement for pre-compiled textures in C++
Place pre-rendered textures into read-only data, instead of the data
section.

Amends 3db168d03d
2023-08-23 18:57:40 +02:00
Simon Hausmann
e683a6338a Make inclusion of various C++ header files optional
Only include iostream, cmath, and cstdlib if needed.
2023-08-21 17:56:50 +02:00
Simon Hausmann
8d0a73c1d4 C++: Add iostream to the list of included header files
When using debug() we generate calls to `std::cout`.
2023-08-21 17:56:50 +02:00
Simon Hausmann
ad84114bae Fix build of generated C++ code with older macOS versions
Avoid the use of std::optional<T>::value.

Amends 0ba6ef1c24
2023-07-31 14:37:45 +02:00
Tobias Hunger
baa4eb1ea3 Get rid of the window when building an embedded component
... now that we can get the WindowAdapter from the parent component when
we embed it.
2023-07-27 12:04:16 +02:00
Tobias Hunger
a362b7a1ae Add window_adapter to ComponentVTable
Make it duplicate as `maybe_window_adapter` with a boolean `do_create`
parameter.
2023-07-27 12:04:16 +02:00
Tobias Hunger
9de515b768 Implement embedding in rust 2023-07-27 12:04:16 +02:00
Tobias Hunger
5db78b6dd2 Implement LLR code lowering for ComponentContainer 2023-07-27 12:04:16 +02:00
Tobias Hunger
d47d52bf52 ItemVTable::init(...): Take an ItemRc so that the itan can know where in the Item Tree it is located 2023-07-27 12:04:16 +02:00
Tobias Hunger
74ef877f70 Add embed_component to ComponentVTable 2023-07-27 12:04:16 +02:00
Tobias Hunger
2840886d28 Add component-factory type to Slint language
Add a type "component-factory" to the Slint language.
2023-07-27 12:04:16 +02:00
Olivier Goffart
bde0ae7585 Compiler: Fix access_item_rc in the generator for complex path
Fixes #3148
2023-07-26 13:45:20 +02:00
Guiguiprim
ef8ddaaa1d
Add native support for min/max 2023-07-21 16:26:41 +02:00
Simon Hausmann
0b760cc7f7 Fix C++ embedded glyphset generation
Declare the correct array length

Amends 917cecff85
2023-07-20 18:17:05 +02:00
Simon Hausmann
3db168d03d C++: Attempt to place embedded into read-only data sections 2023-07-20 16:20:51 +02:00
Simon Hausmann
917cecff85 Add support for embedding bitmap fonts in C++ 2023-07-20 16:20:51 +02:00
Guilhem Vallat
0ebcc2be70 remove clippy warning in rust code gen
This generated a `clippy::clone-on-ref-ptr` warning
2023-07-19 11:04:25 +02:00
Simon Hausmann
59d869cb84 Fix missing invocation of init() on Items with C++
In Rust, register_component in the run-time library is called unconditionally and
invokes init(). The window adapter is an optional
parameter.

In C++, we'd call register_component only if we had a window adapter, which meant
that we're missing init calls().

Amends cd9994306e
2023-07-14 13:09:45 +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
Guilhem Vallat
3d30e81668 reduce rust generated file size
using `use slint::private_unstable_api::re_exports as sp;` should
allow to safely qualify everything will keeping things shorter.

For the `todo` example:
- before 1_050_650 octets for 24_012 formatted lines
- after 934_049 octets for 23_032 formatted lines

This also makes the generated code more readable if needed.
2023-07-03 16:36:11 +02:00
Olivier Goffart
d4216385d8 refactor: extract the resource code generation in a function 2023-06-29 10:43:46 +02:00
Tobias Hunger
e02c360000 Clippy polish 2023-06-28 14:22:30 +02:00
Olivier Goffart
331e5713c2 C++: Use a static_assert to detect Slint version mismatch
cc #2909 , #223

New message:
```
/home/olivier/slint/build2/examples/gallery/gallery.h:6:73: error: static assertion failed: This file was generated with Slint compiler version 1.1.1, but the Slint library used is 1.1.0. The version numbers must match exactly.
    6 | static_assert(1 == SLINT_VERSION_MAJOR && 1 == SLINT_VERSION_MINOR && 1 == SLINT_VERSION_PATCH, "This file was generated with Slint compiler version 1.1.1, but the Slint library used is " SLINT_VERSION_STRING ". The version numbers must match exactly.");
/home/olivier/slint/build2/examples/gallery/gallery.h:6:73: note: the comparison reduces to ‘(1 == 0)’
```

Previous message:
```
/home/olivier/slint/build2/examples/printerdemo/cpp/printerdemo.h:12218:161: error: conversion from ‘VersionCheckHelper<[...],[...],0>’ to non-scalar type ‘VersionCheckHelper<[...],[...],1>’ requested
12218 | [[maybe_unused]] constexpr slint::private_api::VersionCheckHelper<1, 1, 1> THE_SAME_VERSION_MUST_BE_USED_FOR_THE_COMPILER_AND_THE_RUNTIME = slint::private_api::VersionCheckHelper<SLINT_VERSION_MAJOR, SLINT_VERSION_MINOR, SLINT_VERSION_PATCH>();
      |                                                                                                                                                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/olivier/slint/build2/examples/printerdemo/cpp/printerdemo.h:12218:161: error: could not convert ‘slint::private_api::VersionCheckHelper<1, 1, 0>()’ from ‘VersionCheckHelper<[...],[...],0>’ to ‘VersionCheckHelper<[...],[...],1>’
12218 | [[maybe_unused]] constexpr slint::private_api::VersionCheckHelper<1, 1, 1> THE_SAME_VERSION_MUST_BE_USED_FOR_THE_COMPILER_AND_THE_RUNTIME = slint::private_api::VersionCheckHelper<SLINT_VERSION_MAJOR, SLINT_VERSION_MINOR, SLINT_VERSION_PATCH>();
      |                                                                                                                                                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                                                                                                                                 |
      |                                                                                                                                                                 VersionCheckHelper<[...],[...],0>
```
2023-06-28 14:16:52 +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
Olivier Goffart
fdec5960bd Support for @rust-attr on enums 2023-06-19 22:40:49 +02:00
Olivier Goffart
11dea135f7 Domain: slint-ui.com -> slint.dev 2023-06-16 10:55:08 +02:00
Aurindam Jana
039e54a5de
Add royalty free license to files except examples and docs (#2888) 2023-06-15 11:20:50 +02:00
Tobias Hunger
99ea465734 c++: use unsigned integers for the index in visit_dynamic_children
This is what rust does, too, and prevents errors when the indices
get big.
2023-06-14 16:24:36 +02:00
Olivier Goffart
0e31f097a4 Un-seal the WindowAdapter trait 2023-06-13 17:44:04 +02:00
Simon Hausmann
cd9994306e Create the window adapter lazily in C++ 2023-06-13 15:13:42 +02:00
Olivier Goffart
18ba3c2ae2 Slint enums in Rust and C++ 2023-06-12 13:02:14 +02:00
Simon Hausmann
e663282c65 Fix support for High-DPI with Qt
Preserve the early backend initialization of commit
f0b047057b
2023-06-10 11:41:04 +02:00
Simon Hausmann
01b00d26eb Rust: Allocate the window adapter lazily
This will be needed for embedding - to avoid creating two window
adapters - and it will be needed for the API to allow creating a
component from an existing window.
2023-06-10 11:41:04 +02:00
Olivier Goffart
12e6b34e2d Translations: support for plurals 2023-06-07 10:34:34 +02:00
Simon Hausmann
1bf05eae7c
Add support for absolute-x and absolute-y properties on any element (#2823)
Fixes #1691
2023-06-06 14:37:53 +02:00