mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-28 21:04:47 +00:00
ListView in C++
This make sure the layout is correct, but does not implement the optimization to only instentiate visible items
This commit is contained in:
parent
5695e251b7
commit
58b176d10c
2 changed files with 97 additions and 15 deletions
|
@ -467,6 +467,18 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
template<typename Parent>
|
||||
void ensure_updated_listview(const Parent *parent, const Property<float> *viewport_width,
|
||||
const Property<float> *viewport_height, [[maybe_unused]] const Property<float> *viewport_y,
|
||||
float listview_width, [[maybe_unused]] float listview_height) const
|
||||
{
|
||||
// TODO: the rust code in model.rs try to only allocate as many items as visible items
|
||||
ensure_updated(parent);
|
||||
|
||||
float h = compute_layout_listview(viewport_width, listview_width);
|
||||
viewport_height->set(h);
|
||||
}
|
||||
|
||||
intptr_t visit(TraversalOrder order, private_api::ItemVisitorRefMut visitor) const
|
||||
{
|
||||
for (std::size_t i = 0; i < inner->data.size(); ++i) {
|
||||
|
@ -494,6 +506,17 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
float compute_layout_listview(const Property<float> *viewport_width, float listview_width) const {
|
||||
float offset = 0;
|
||||
viewport_width->set(listview_width);
|
||||
if (!inner)
|
||||
return offset;
|
||||
for (auto &x : inner->data) {
|
||||
x.ptr->listview_layout(&offset, viewport_width);
|
||||
}
|
||||
return offset;
|
||||
}
|
||||
|
||||
void model_set_row_data(int row, const ModelData &data) const {
|
||||
if (model.is_dirty()) {
|
||||
std::abort();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue