Fix regression with empty array

Regression noticed in this line:
3f97d98bff/ui/tabs/downloads.slint (L77)

The following used to work:

```slint
import { Button, VerticalBox } from "std-widgets.slint";
export component Demo {
    in property <[int]> mods;
    VerticalBox {
        alignment: start;
        for xxx in true ? mods : [] : HorizontalLayout { alignment: center; Button { text: "OK!"; } }
    }
}
```

But we fixed array conversion and this caused a regression with empty
array
This commit is contained in:
Olivier Goffart 2023-11-01 09:47:44 +01:00
parent 2176523e4f
commit ac8fd60091
4 changed files with 37 additions and 8 deletions

View file

@ -517,6 +517,15 @@ public:
}
};
// Specialize for the empty array. We can't have a Model<void>, but `int` will work for our purpose
template<>
class ArrayModel<0, void> : public Model<int>
{
public:
size_t row_count() const override { return 0; }
std::optional<int> row_data(size_t) const override { return {}; }
};
/// Model to be used when we just want to repeat without data.
struct UIntModel : Model<int>
{