mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-27 20:42:25 +00:00
Replace sixtyfps::
almost everywhere
This commit is contained in:
parent
323dc8f66b
commit
fc6b7cc966
7 changed files with 42 additions and 42 deletions
|
@ -192,17 +192,17 @@ This will generate a `my_application_ui.h` header file. It basically contains th
|
|||
|
||||
struct TodoItem {
|
||||
bool checked;
|
||||
sixtyfps::SharedString title;
|
||||
slint::SharedString title;
|
||||
};
|
||||
|
||||
struct MainWindow {
|
||||
public:
|
||||
inline auto create () -> sixtyfps::ComponentHandle<MainWindow>;
|
||||
inline auto create () -> slint::ComponentHandle<MainWindow>;
|
||||
|
||||
inline auto get_todo_model () const -> std::shared_ptr<sixtyfps::Model<TodoItem>>;
|
||||
inline void set_todo_model (const std::shared_ptr<sixtyfps::Model<TodoItem>> &value) const;
|
||||
inline auto get_todo_model () const -> std::shared_ptr<slint::Model<TodoItem>>;
|
||||
inline void set_todo_model (const std::shared_ptr<slint::Model<TodoItem>> &value) const;
|
||||
|
||||
inline void invoke_todo_added (sixtyfps::SharedString arg_0) const;
|
||||
inline void invoke_todo_added (slint::SharedString arg_0) const;
|
||||
template<typename Functor> inline void on_todo_added (Functor && callback_handler) const;
|
||||
|
||||
//...
|
||||
|
@ -220,14 +220,14 @@ int main() {
|
|||
auto todo_app = MainWindow::create();
|
||||
|
||||
// let's create a model:
|
||||
auto todo_model = std::make_shared<sixtyfps::VectorModel<TodoItem>>(std::vector {
|
||||
auto todo_model = std::make_shared<slint::VectorModel<TodoItem>>(std::vector {
|
||||
TodoItem { false, "Write documentation" },
|
||||
});
|
||||
// set the model as the model of our view
|
||||
todo_app->set_todo_model(todo_model);
|
||||
|
||||
// let's connect our "add" button to add an item in the model
|
||||
todo_app->on_todo_added([todo_model](const sixtyfps::SharedString &s) {
|
||||
todo_app->on_todo_added([todo_model](const slint::SharedString &s) {
|
||||
todo_model->push_back(TodoItem { false, s} );
|
||||
});
|
||||
|
||||
|
|
|
@ -7,10 +7,10 @@ This class will have the following public member functions:
|
|||
|
||||
* A `create` constructor function and a destructor.
|
||||
* A `show` function, which will show the component on the screen. Note that in order to render
|
||||
and react to user input, it's still necessary to spin the event loop, by calling {cpp:func}`sixtyfps::run_event_loop()`
|
||||
and react to user input, it's still necessary to spin the event loop, by calling {cpp:func}`slint::run_event_loop()`
|
||||
or using the convenience `fun` function in this class.
|
||||
* A `hide` function, which de-registers the component from the windowing system.
|
||||
* A `window` function that provides access to the {cpp:class}`sixtyfps::Window`, allow for further customization
|
||||
* A `window` function that provides access to the {cpp:class}`slint::Window`, allow for further customization
|
||||
towards the windowing system.
|
||||
* A `run` convenience function, which will show the component and starts the event loop.
|
||||
* for each properties:
|
||||
|
@ -22,14 +22,14 @@ This class will have the following public member functions:
|
|||
for this callback. the functor must accept the type parameter of the callback
|
||||
* A `global` function, to provide access to any exported global singletons.
|
||||
|
||||
The class is instantiated with the `create` function, which returns the type wrapped in {cpp:class}`sixtyfps::ComponentHandle`.
|
||||
This is a smart pointer that owns the actual instance and keeps it alive as long as at least one {cpp:class}`sixtyfps::ComponentHandle`
|
||||
The class is instantiated with the `create` function, which returns the type wrapped in {cpp:class}`slint::ComponentHandle`.
|
||||
This is a smart pointer that owns the actual instance and keeps it alive as long as at least one {cpp:class}`slint::ComponentHandle`
|
||||
is in scope, similar to `std::shared_ptr<T>`.
|
||||
|
||||
For more complex UIs it is common to supply data in the form of an abstract data model, that is used with
|
||||
[`for` - `in`](markdown/langref.md#repetition) repetitions or [`ListView`](markdown/widgets.md#listview) elements in the `.slint` language.
|
||||
All models in C++ are sub-classes of the {cpp:class}`sixtyfps::Model` and you can sub-class it yourself. For convenience,
|
||||
the {cpp:class}`sixtyfps::VectorModel` provides an implementation that is backed by a `std::vector<T>`.
|
||||
All models in C++ are sub-classes of the {cpp:class}`slint::Model` and you can sub-class it yourself. For convenience,
|
||||
the {cpp:class}`slint::VectorModel` provides an implementation that is backed by a `std::vector<T>`.
|
||||
|
||||
## Example
|
||||
|
||||
|
@ -55,14 +55,14 @@ This will generate a header with the following contents (edited for documentatio
|
|||
class SampleComponent {
|
||||
public:
|
||||
/// Constructor function
|
||||
inline auto create () -> sixtyfps::ComponentHandle<MainWindow>;
|
||||
inline auto create () -> slint::ComponentHandle<MainWindow>;
|
||||
/// Destructor
|
||||
inline ~SampleComponent ();
|
||||
|
||||
/// Show this component, and runs the event loop
|
||||
inline void run () const;
|
||||
|
||||
/// Show the window that renders this component. Call `sixtyfps::run_event_loop()`
|
||||
/// Show the window that renders this component. Call `slint::run_event_loop()`
|
||||
/// to continuously render the contents and react to user input.
|
||||
inline void show () const;
|
||||
|
||||
|
@ -75,9 +75,9 @@ public:
|
|||
inline void set_counter (const int &value) const;
|
||||
|
||||
/// Getter for the `user_name` property
|
||||
inline sixtyfps::SharedString get_user_name () const;
|
||||
inline slint::SharedString get_user_name () const;
|
||||
/// Setter for the `user_name` property
|
||||
inline void set_user_name (const sixtyfps::SharedString &value) const;
|
||||
inline void set_user_name (const slint::SharedString &value) const;
|
||||
|
||||
/// Call this function to call the `hello` callback
|
||||
inline void invoke_hello () const;
|
||||
|
|
|
@ -20,7 +20,7 @@ and lowest memory consumption.
|
|||
The `slint_target_sources` cmake command makes the translation automatic
|
||||
and [generated code](generated_code.md) has an API that allows setting and getting
|
||||
property values, etc. That API will use types from the {ref}`sixtyfps <namespace_sixtyfps>`
|
||||
namespace, for example {cpp:class}`sixtyfps::SharedString` or {cpp:class}`sixtyfps::Color`.
|
||||
namespace, for example {cpp:class}`slint::SharedString` or {cpp:class}`slint::Color`.
|
||||
|
||||
## Run-time interpreted `.slint` designs
|
||||
|
||||
|
@ -28,29 +28,29 @@ Instead of compiling `.slint` designs to C++, you can also choose to dynamically
|
|||
files at run-time. This is slower than compiling them ahead of time and requires more memory,
|
||||
however it provides more flexibility in your application design.
|
||||
|
||||
The entry point to loading a `.slint` file is the {cpp:class}`sixtyfps::interpreter::ComponentCompiler`
|
||||
class in the {ref}`sixtyfps::interpreter <namespace_sixtyfps__interpreter>` namespace.
|
||||
The entry point to loading a `.slint` file is the {cpp:class}`slint::interpreter::ComponentCompiler`
|
||||
class in the {ref}`slint::interpreter <namespace_sixtyfps__interpreter>` namespace.
|
||||
|
||||
With the help of {cpp:class}`sixtyfps::interpreter::ComponentCompiler` you create a {cpp:class}`sixtyfps::interpreter::ComponentDefinition`,
|
||||
With the help of {cpp:class}`slint::interpreter::ComponentCompiler` you create a {cpp:class}`slint::interpreter::ComponentDefinition`,
|
||||
which provides you with information about properties and callbacks that are common to all instances. The
|
||||
{cpp:func}`sixtyfps::interpreter::ComponentDefinition::create()` function creates new instances, which
|
||||
are wrapped in {cpp:class}`sixtyfps::ComponentHandle`. This is a smart pointer that owns the actual instance
|
||||
and keeps it alive as long as at least one {cpp:class}`sixtyfps::ComponentHandle` is in scope, similar to `std::shared_ptr<T>`.
|
||||
{cpp:func}`slint::interpreter::ComponentDefinition::create()` function creates new instances, which
|
||||
are wrapped in {cpp:class}`slint::ComponentHandle`. This is a smart pointer that owns the actual instance
|
||||
and keeps it alive as long as at least one {cpp:class}`slint::ComponentHandle` is in scope, similar to `std::shared_ptr<T>`.
|
||||
|
||||
All property values in `.slint` are mapped to {cpp:class}`sixtyfps::interpreter::Value` in C++. This is a
|
||||
All property values in `.slint` are mapped to {cpp:class}`slint::interpreter::Value` in C++. This is a
|
||||
polymorphic data type that can hold different kinds of values, such as numbers, strings or even data models.
|
||||
|
||||
For more complex UIs it is common to supply data in the form of an abstract data model, that is used with
|
||||
[`for` - `in`](markdown/langref.md#repetition) repetitions or [`ListView`](markdown/widgets.md#listview) elements in the `.slint` language.
|
||||
All models in C++ with the interpreter API are sub-classes of the {cpp:class}`sixtyfps::Model` where the template
|
||||
parameter is {cpp:class}`sixtyfps::interpreter::Value`. Therefore to provide your own data model, you can subclass
|
||||
`sixtyfps::Model<sixtyfps::interpreter::Value>`.
|
||||
All models in C++ with the interpreter API are sub-classes of the {cpp:class}`slint::Model` where the template
|
||||
parameter is {cpp:class}`slint::interpreter::Value`. Therefore to provide your own data model, you can subclass
|
||||
`slint::Model<slint::interpreter::Value>`.
|
||||
|
||||
In `.slint` files it is possible to declare [singletons that are globally available](markdown/langref.md#global-singletons).
|
||||
You can access them from to your C++ code by exporting them and using the getter and setter functions on
|
||||
{cpp:class}`sixtyfps::interpreter::ComponentInstance` to change properties and callbacks:
|
||||
{cpp:class}`slint::interpreter::ComponentInstance` to change properties and callbacks:
|
||||
|
||||
1. {cpp:func}`sixtyfps::interpreter::ComponentInstance::set_global_property()`
|
||||
1. {cpp:func}`sixtyfps::interpreter::ComponentInstance::get_global_property()`
|
||||
1. {cpp:func}`sixtyfps::interpreter::ComponentInstance::set_global_callback()`
|
||||
1. {cpp:func}`sixtyfps::interpreter::ComponentInstance::invoke_global_callback()`
|
||||
1. {cpp:func}`slint::interpreter::ComponentInstance::set_global_property()`
|
||||
1. {cpp:func}`slint::interpreter::ComponentInstance::get_global_property()`
|
||||
1. {cpp:func}`slint::interpreter::ComponentInstance::set_global_callback()`
|
||||
1. {cpp:func}`slint::interpreter::ComponentInstance::invoke_global_callback()`
|
||||
|
|
|
@ -8,10 +8,10 @@ The follow table summarizes the entire mapping:
|
|||
| `int` | `int` | |
|
||||
| `float` | `float` | |
|
||||
| `bool` | `bool` | |
|
||||
| `string` | [`sixtyfps::SharedString`](api/structsixtyfps_1_1_shared_string.html) | A reference-counted string type that uses UTF-8 encoding and can be easily converted to a std::string_view or a const char *. |
|
||||
| `color` | [`sixtyfps::Color`](api/classsixtyfps_1_1_color.html) | |
|
||||
| `brush` | [`sixtyfps::Brush`](api/classsixtyfps_1_1_brush.html) | |
|
||||
| `image` | [`sixtyfps::Image`](api/structsixtyfps_1_1_image.html) | |
|
||||
| `string` | [`slint::SharedString`](api/structsixtyfps_1_1_shared_string.html) | A reference-counted string type that uses UTF-8 encoding and can be easily converted to a std::string_view or a const char *. |
|
||||
| `color` | [`slint::Color`](api/classsixtyfps_1_1_color.html) | |
|
||||
| `brush` | [`slint::Brush`](api/classsixtyfps_1_1_brush.html) | |
|
||||
| `image` | [`slint::Image`](api/structsixtyfps_1_1_image.html) | |
|
||||
| `physical_length` | `float` | The unit are physical pixels. |
|
||||
| `length` | `float` | At run-time, logical lengths are automatically translated to physical pixels using the device pixel ratio. |
|
||||
| `duration` | `std::int64_t` | At run-time, durations are always represented as signed 64-bit integers with millisecond precision. |
|
||||
|
@ -37,7 +37,7 @@ It would result in the following type being generated:
|
|||
```cpp
|
||||
class MyStruct {
|
||||
public:
|
||||
sixtyfps::SharedString bar;
|
||||
slint::SharedString bar;
|
||||
int foo;
|
||||
};
|
||||
```
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
What we'll do is take the list of tiles declared in the .slint language, duplicate it, and shuffle it.
|
||||
We'll do so by accessing the `memory_tiles` property through the Rust code. For each top-level property,
|
||||
a getter and a setter function is generated - in our case `get_memory_tiles` and `set_memory_tiles`.
|
||||
Since `memory_tiles` is an array in the `.slint` language, it is represented as a [`std::shared_ptr<sixtyfps::Model>`](https://sixtyfps.io/docs/cpp/api/classsixtyfps_1_1model).
|
||||
Since `memory_tiles` is an array in the `.slint` language, it is represented as a [`std::shared_ptr<slint::Model>`](https://sixtyfps.io/docs/cpp/api/classsixtyfps_1_1model).
|
||||
We can't modify the model generated by the .slint, but we can extract the tiles from it, and put it
|
||||
in a [`sixtyfps::VectorModel`](https://sixtyfps.io/docs/cpp/api/classsixtyfps_1_1vectormodel) which inherits from `Model`.
|
||||
in a [`slint::VectorModel`](https://sixtyfps.io/docs/cpp/api/classsixtyfps_1_1vectormodel) which inherits from `Model`.
|
||||
`VectorModel` allows us to make modifications and we can use it to replace the static generated model.
|
||||
|
||||
We modify the main function like so:
|
||||
|
|
|
@ -145,7 +145,7 @@ pub fn main() {
|
|||
main_window.on_filter_image(move |filter_index| {
|
||||
let filter_fn = filters.0[filter_index as usize].apply_function;
|
||||
let filtered_image = filter_fn(&source_image);
|
||||
slint::Image::from_rgba8(sixtyfps::SharedPixelBuffer::clone_from_slice(
|
||||
slint::Image::from_rgba8(slint::SharedPixelBuffer::clone_from_slice(
|
||||
filtered_image.as_raw(),
|
||||
filtered_image.width(),
|
||||
filtered_image.height(),
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
* `Value::Array` was removed and [`Value::Model`] needs to be used instead.
|
||||
* `CallCallbackError` was renamed to [`InvokeCallbackError`].
|
||||
* `WeakComponentInstance` was removed. Use `slint::Weak<sixtyfps::interpreter::ComponentInstance>` instead.
|
||||
* `WeakComponentInstance` was removed. Use `slint::Weak<slint::interpreter::ComponentInstance>` instead.
|
||||
You might need to `use slint::ComponentHandle;` in your code to bring the trait into scope.
|
||||
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue