docs
Loading...
Searching...
No Matches
LayoutCallback

#include <AppCore/layout/Callback.h>

Overview

Scoped handle that controls how long a layout callback stays registered.

Methods that register layout and panel callbacks return a LayoutCallback. The callback stays active for as long as this handle exists.

To keep receiving events, store the handle in an object whose lifetime matches the listener.

This status bar keeps a focus-change callback as a member variable:

class StatusBar {
public:
explicit StatusBar(Window* window)
: on_focus_(window->OnFocusChange([](Panel* focused) {
ShowFocusedKey(focused ? focused->key() : String());
})) {}
private:
LayoutCallback on_focus_; // unregisters when the StatusBar goes away
};
A layout node that hosts a single web view.
Definition Panel.h:59
Unicode string container with conversions for UTF-8, UTF-16, and UTF-32.
Definition String.h:31
A native OS window that displays web content.
Definition Window.h:636

Callback Lifetime

A registered callback stops firing when:

  • The handle is destroyed. Discarding the return value of a registration call unregisters the callback immediately.
  • You call Remove(). The callback unregisters early, even from inside the callback itself.
  • The target node is removed or its window closes.

Call IsActive() to check whether the callback can still fire.

Detaching Callbacks

To keep a callback running without storing its handle, call Detach(). The callback remains registered for the rest of the node's lifetime. Once detached, the callback can't be removed.

Chain Detach() onto the registration call:

sidebar->OnLayoutChange([] { Relayout(); }).Detach();
void Detach()
Leave the callback registered for the rest of its node's lifetime and give up this object.
Note
Callbacks must not let exceptions propagate.
See also
LayoutNode::OnLayoutChange(), LayoutNode::OnUserResize(), Panel::OnDismiss(), Window::OnFocusChange(), Window::OnEditableStateChange()

Public Member Functions

 LayoutCallback ()
 Create an empty LayoutCallback (it owns no registration and IsActive() is false).
 LayoutCallback (const LayoutCallback &)=delete
LayoutCallback & operator= (const LayoutCallback &)=delete
 LayoutCallback (LayoutCallback &&other) noexcept
 Move constructor (transfers the registration, other becomes empty).
LayoutCallback & operator= (LayoutCallback &&other) noexcept
 Move assignment.
 ~LayoutCallback ()
 Unregister the callback (if it is still registered) and release the registration.
 operator bool () const
 Whether or not the callback can still fire.
bool IsActive () const
 The named form of operator bool.
void Remove ()
 Stop receiving callbacks now.
void Detach ()
 Leave the callback registered for the rest of its node's lifetime and give up this object.

Constructor & Destructor Documentation

◆ LayoutCallback() [1/3]

LayoutCallback ( )

Create an empty LayoutCallback (it owns no registration and IsActive() is false).

◆ LayoutCallback() [2/3]

LayoutCallback ( const LayoutCallback & )
delete

◆ LayoutCallback() [3/3]

LayoutCallback ( LayoutCallback && other)
noexcept

Move constructor (transfers the registration, other becomes empty).

◆ ~LayoutCallback()

Unregister the callback (if it is still registered) and release the registration.

Member Function Documentation

◆ Detach()

void Detach ( )

Leave the callback registered for the rest of its node's lifetime and give up this object.

The callback keeps firing until the node is removed or its window closes. There is no way to remove it afterwards.

◆ IsActive()

bool IsActive ( ) const

The named form of operator bool.

◆ operator bool()

operator bool ( ) const
inlineexplicit

Whether or not the callback can still fire.

This is false for an empty object, after Remove(), and once the node is removed or its window closes.

◆ operator=() [1/2]

LayoutCallback & operator= ( const LayoutCallback & )
delete

◆ operator=() [2/2]

LayoutCallback & operator= ( LayoutCallback && other)
noexcept

Move assignment.

Removes any registration this object held, then takes over other's.

◆ Remove()

void Remove ( )

Stop receiving callbacks now.

You can call this more than once, after the node is removed or its window closes, and from inside the callback itself.


The documentation for this class was generated from the following file: