Skip to content

ui::Signal

Header: winui/core/Property.hpp.

Derives from ui::PropertyBase.

An event with no value, meaning "ask again".

The same edge list as a Property and the same two-way lifetime safety, with no value and so no equality gate: raise() always reaches every observer. A copy (or a move) is a different object with no observers of its own. Assigning to a Signal keeps the observers it has, since they observe this object and not the one it was assigned from. A struct holding one therefore stays an ordinary copyable aggregate.

Example:

ui::Signal settings_changed;
ui::Subscription reload = settings_changed.observe([&] { std::println("Reloading the settings"); });

// Every save raises it, and every raise() runs the handler again, even when nothing in the
// file changed, since a Signal has no value to compare.
window.set_content(ui::Button{.text = "Save", .on_click = [&] { save(); settings_changed.raise(); }});

Signal

Signal() = default

A signal with no observers.

~Signal

~Signal() = default

Leaves every remaining Subscription dead.

Signal

Signal(const Signal&) noexcept

A fresh signal with no observers; other's observers are not copied.

operator=

Signal& operator=(const Signal&) noexcept

No-op: this signal keeps its own observers.

observe

Subscription observe(Callback<void()> fn) const

Observe. The returned Subscription must be kept for fn to keep firing.

raise

void raise(std::source_location where = std::source_location::current()) const

Tell every observer. Const: raising changes nothing a reader of the signal can see, and the objects that own one are handed around by const pointer (a control's ui::CommandRef).

observer_count

std::size_t observer_count() const noexcept

How many live subscriptions observe this signal.