ui::ItemCount¶
Header: winui/core/ObservableVector.hpp.
How many items an index-based control shows, and the changes that lead from one count to the next. The typed views hand one to their controls, and an app uses one to drive a control by hand. It is either a plain number or ui::item_count() of a ui::ObservableVector or a ui::Property<std::vector<T>>. The second keeps the view in step with the collection, so no change has to be announced by hand.
Example:
ui::ObservableVector<std::string> names{"Ada", "Grace"};
auto list = std::make_unique<ui::VirtualListControl>();
list->set_item_factory([&names](std::size_t i) { return std::make_unique<ui::TextControl>(names[i]); });
ui::ItemCount count = ui::item_count(names);
list->set_item_count(count.initial());
list->add_subscription(count.subscribe(
[raw = list.get()](const ui::CollectionChange& change) { raw->set_item_count(change.size); }));
names.push_back("Edsger"); // the list shows a third row
Attach¶
Subscribes a sink to the collection's changes.
ItemCount¶
No items.
ItemCount¶
A fixed number of items; a later change goes through the control's set_item_count(). A negative number is no items.
ItemCount¶
The live form, made by ui::item_count().
initial¶
The number of items when the spec is built.
reactive¶
True when the count follows a collection.
subscribe¶
Starts following the collection; only valid when reactive().