ui::ElementWatch¶
Header: winui/ui/Element.hpp.
A non-owning pointer to an element that goes null when the element is destroyed. It is for something outside the tree that has to reach an element across frames without owning it, and cannot know when the page it sits in is torn down (a ConnectedAnimation's destination). It severs both ways like a Property's Subscription: the element keeps a list of the watches on it, and either side going away unhooks the other. Neither copyable nor movable, since the element holds its address.
Example:
// A tip that points at a button on whichever page is showing.
class Coachmark
{
public:
void point_at(ui::Element* target)
{
target_.reset(target);
}
void tick()
{
if (ui::Element* target = target_.get()) // null once the page was torn down
{
place_next_to(target->bounds());
}
}
private:
void place_next_to(const ui::Rect& anchor); // moves the tip beside `anchor`
ui::ElementWatch target_;
};
ElementWatch¶
Watches nothing.
ElementWatch¶
Watches element (nullptr: nothing).
~ElementWatch¶
Unhooks from the watched element, if it is still alive.
ElementWatch¶
operator=¶
get¶
The watched element, or nullptr once it has been destroyed (or when nothing is watched).
operator bool¶
Whether the watched element is still alive.
reset¶
Watch element instead (nullptr: nothing).