Commit graph

111 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
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
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
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
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
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
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
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
Aurindam Jana
5a4a7fee63
Update royalty free license to 1.1 (#2994) 2023-07-10 10:12:11 +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
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
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
1bf05eae7c
Add support for absolute-x and absolute-y properties on any element (#2823)
Fixes #1691
2023-06-06 14:37:53 +02:00
Olivier Goffart
cf746ddf8d WIP: formatting implementation of translate in rust and C++ 2023-06-05 16:34:59 +02:00
Olivier Goffart
dcd8450dfa WIP: start working on translations: @tr()
This commit just do the parsing of the @tr macro.
2023-06-05 16:34:59 +02:00
Amirhossein Akhlaghpour
3a4f3c61d5
Add @rust-attr on scturct (#2785)
Fixes: #2660
2023-06-05 16:29:55 +02:00
Simon Hausmann
0f54b9599b Add support for manually closing PopupWindows
This patch adds a `close()` function that can be called to close a popup
window, and a `close-to-click` boolean that can be set to false to
disable the default behavior.
2023-06-02 18:07:49 +02:00
Olivier Goffart
5599bd44e0 Remove Color::opaque
It is not a right name and i don't think it is a so common operation
2023-06-02 17:02:08 +02:00
Olivier Goffart
4845241ebf Rename translucent to transparentize and mixed to mix 2023-06-02 17:02:08 +02:00
Arthur Araruna
64ad1ce357 Add some color and brush manipulation funcs (#2565)
The added functions enable mixing colors and manipulating the opacity
of colors and brushes.

They enable the behavior of some of the available functions from SASS and are
added for future use for adding the Adwaita style (future PR).
2023-06-02 17:02:08 +02:00
Simon Hausmann
c428601370
Add support for select-all(), cut(), copy() and paste() functions on text input elements (#2804)
In the compiler this is still very primitive, but an attempt to start a
generic interface. The basic assumption is that all item functions will
eventually need access to the window adapter and itemrc. Support for
additional arguments is still missing.

Also missing is support for the function access via rtti in the
interpreter, hence the hardcoding at the moment.
2023-06-01 16:04:53 +02:00
Simon Hausmann
ea769cb10c C++: Make sure embedded image data is declared const 2023-04-12 16:14:13 +02:00
Olivier Goffart
a57c7eb6bc Added TextInputInterface.text-input-focused 2023-04-12 14:49:08 +02:00
Olivier Goffart
cdaf2abb47
C++: sort the member of a struct in the same order as in the .slint file 2023-03-29 19:11:33 +02:00
Olivier Goffart
7652097582 Better error message when trying to use private property in native code
If one declare a `property <int> foo;` in Slint, it will be private by
default, and the getter/setter won't be generated, and it may be
confusing as to why

With this change, it still generate private getter and setter so this
gives a better hint to the developer what the problem is.

Replaces #2170
2023-03-27 17:49:07 +02:00
Olivier Goffart
889b953304 C++: Don't make the global_* member public
This requires adding more friends to the component root

Fixes: #2169
2023-02-17 17:54:03 +01:00
Olivier Goffart
81cb89d374 C++: fix including the generated file in several translation units 2023-02-17 16:42:40 +01:00
Olivier Goffart
acb41d8244 CPP: fix struct which have a field with the same name as the struct
The operator== reference the struct name, so if there is a
field with the same name, we should disambiguate

Fix  tests/cases/issues/name_conflicts.slint that was added in last
commit
2023-02-08 18:34:52 +01:00
Olivier Goffart
eaa9db4911 C++: use size_t everywhere as index in our models
cc #2024
2023-02-07 15:25:44 +01:00