mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 14:21:16 +00:00
Change Model::row_data to return an Option<T> (#873)
Change Model::row_data to return an Option<T> (rust) or std::optional<T> (c++) Co-authored-by: Olivier Goffart <olivier@woboq.com> Co-authored-by: Simon Hausmann <hausmann@gmail.com>
This commit is contained in:
parent
e2ec76f9ef
commit
e3c4209b1f
24 changed files with 229 additions and 102 deletions
|
@ -6,7 +6,7 @@ This guide lists all API incompatible changes between major versions and describ
|
|||
|
||||
## Migrating from Version 0.1.x to 0.2.0
|
||||
|
||||
In the 0.2.x series we have increased the minimum version of C++. You need to have a C++ compiler installed that supports C++ 20 or newer.
|
||||
In version 0.2.0 we have increased the minimum version of C++. You need to have a C++ compiler installed that supports C++ 20 or newer.
|
||||
|
||||
If you are building SixtyFPS from source, you need to make sure that your Rust installation is up-to-date. If you have installed Rust using `rustup`, then you can upgrade to the latest Version of Rust by running `rustup update`.
|
||||
|
||||
|
@ -29,3 +29,28 @@ New code:
|
|||
sixtyfps::Value args[] = { SharedString("Hello"), 42. };
|
||||
instance->invoke_callback("foo", args);
|
||||
```
|
||||
|
||||
#### Models
|
||||
|
||||
`Model::row_data` returns now a `std::optional<ModelData>` and can thus be used with indices that are out of bounds.
|
||||
|
||||
This also means that `Model`s must handle invalid indices and may not crash when a invalid index is passed in.
|
||||
|
||||
Old code:
|
||||
|
||||
```cpp
|
||||
float value = another_model->row_data(2);
|
||||
do_something(value)
|
||||
```
|
||||
|
||||
New code:
|
||||
|
||||
```cpp
|
||||
// `another_model` is a model that contains floats.
|
||||
std::optional<float> value = another_model->row_data(2);
|
||||
if (value.has_value()) {
|
||||
do_something(*value);
|
||||
} else {
|
||||
// row index 2 is out of bounds
|
||||
}
|
||||
```
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue