41#include "aria/detail/list_replay.hpp"
74 [[nodiscard]]
handle value()
const {
return selected_.get(); }
75 [[nodiscard]]
bool has_value()
const {
return static_cast<bool>(selected_.peek()); }
82 void clear() { selected_.set(
nullptr); }
86 return selected_.peek() == item;
95 std::weak_ptr<bool> weak_alive = alive_;
96 auto rows = std::make_shared<std::vector<handle>>(source.
snapshot());
97 source_sub_ = source.observe([
this, rows, weak_alive](
const ListChange<T>& ch) {
98 auto alive = weak_alive.lock();
99 if (!alive || !*alive)
return;
100 detail::replay_list_change(*rows, ch);
103 auto current = selected_.peek();
104 if (current && std::find(rows->begin(), rows->end(), current) == rows->end())
clear();
109 void unbind() noexcept { source_sub_.release(); }
114 std::shared_ptr<bool> alive_ = std::make_shared<bool>(
true);
116 Subscription source_sub_;
146 [[nodiscard]] std::vector<handle>
values()
const {
return selected_.get(); }
147 [[nodiscard]] std::size_t
size()
const {
return selected_.peek().size(); }
148 [[nodiscard]]
bool empty()
const {
return selected_.peek().empty(); }
151 const auto& v = selected_.peek();
152 return std::find(v.begin(), v.end(), item) != v.end();
159 auto v = selected_.peek();
160 if (std::find(v.begin(), v.end(), item) != v.end())
return;
161 v.push_back(std::move(item));
162 selected_.set(std::move(v));
167 auto v = selected_.peek();
168 auto it = std::find(v.begin(), v.end(), item);
169 if (it == v.end())
return;
171 selected_.set(std::move(v));
178 else add(std::move(item));
182 if (selected_.peek().empty())
return;
189 std::weak_ptr<bool> weak_alive = alive_;
190 auto rows = std::make_shared<std::vector<handle>>(source.
snapshot());
191 source_sub_ = source.observe([
this, rows, weak_alive](
const ListChange<T>& ch) {
192 auto alive = weak_alive.lock();
193 if (!alive || !*alive)
return;
194 detail::replay_list_change(*rows, ch);
199 return std::find(rows->begin(), rows->end(), item) == rows->end();
207 void unbind() noexcept { source_sub_.release(); }
210 std::shared_ptr<bool> alive_ = std::make_shared<bool>(
true);
212 Subscription source_sub_;
const reactive::Property< std::vector< handle > > & selected() const noexcept
Definition selection.hpp:142
MultiSelection & operator=(const MultiSelection &)=delete
void unbind() noexcept
Definition selection.hpp:207
std::size_t size() const
Definition selection.hpp:147
void add(handle item)
Add item to the selection (appended at the end of pick order).
Definition selection.hpp:157
std::vector< handle > values() const
Definition selection.hpp:146
bool is_selected(const handle &item) const
Definition selection.hpp:150
MultiSelection & operator=(MultiSelection &&)=delete
void toggle(handle item)
Toggle membership.
Definition selection.hpp:175
std::shared_ptr< T > handle
Definition selection.hpp:126
void bind_to(ObservableList< T > &source)
Keep selected handles that survive each replayed Remove/Replace/Reset.
Definition selection.hpp:188
void remove(const handle &item)
Remove item from the selection. No-op if not selected.
Definition selection.hpp:166
bool empty() const
Definition selection.hpp:148
~MultiSelection()
Definition selection.hpp:129
T value_type
Definition selection.hpp:125
reactive::Property< std::vector< handle > > & selected() noexcept
Reactive snapshot of selected handles, in pick order.
Definition selection.hpp:139
MultiSelection(const MultiSelection &)=delete
void clear()
Definition selection.hpp:181
MultiSelection(MultiSelection &&)=delete
Observable sequence of owning element handles.
Definition observable_list.hpp:40
std::vector< std::shared_ptr< T > > snapshot() const
Definition observable_list.hpp:72
T peek() const noexcept(std::is_nothrow_copy_constructible_v< T >)
Snapshot read that does NOT register a dependency.
Definition property.hpp:164
void set(const T &new_val)
Commit a new value.
Definition property.hpp:179
bool has_value() const
Definition selection.hpp:75
void select(handle item)
Select item (null clears).
Definition selection.hpp:79
T value_type
Definition selection.hpp:58
void bind_to(ObservableList< T > &source)
Follow source membership by replaying its owning events.
Definition selection.hpp:94
void unbind() noexcept
Detach from the bound source list (idempotent).
Definition selection.hpp:109
Selection & operator=(const Selection &)=delete
void clear()
Clear the selection.
Definition selection.hpp:82
reactive::Property< handle > & selected() noexcept
Reactive selected handle (null when nothing is selected).
Definition selection.hpp:70
~Selection()
Definition selection.hpp:62
handle value() const
Current selected element (may be null).
Definition selection.hpp:74
Selection(const Selection &)=delete
Selection(Selection &&)=delete
std::shared_ptr< T > handle
Definition selection.hpp:59
bool is_selected(const handle &item) const
True iff item is the current selection (by shared_ptr identity).
Definition selection.hpp:85
const reactive::Property< handle > & selected() const noexcept
Definition selection.hpp:71
Selection & operator=(Selection &&)=delete
Definition property.hpp:103
@ Replace
Definition list_change.hpp:10
@ Remove
Definition list_change.hpp:10
@ Reset
Definition list_change.hpp:10
An owning event in a sequential list edit stream.
Definition list_change.hpp:16
ListChangeKind kind
Definition list_change.hpp:18