Skip to main content

Events

On this page you'll learn about the available events and how to use them.

Basics

Events are simply callbacks which are invoked for specific actions and can, in certain circumstances, even alter the behavior of the application.

Register Callback

To register an event callback simply call the on method of your webview.
You'll need to pass the event-type as the template parameter and the callback as the function argument.

Every call to on() will return an id which can later be used to remove the same callback.

Example Callback (Resize Window)
smartview.on<saucer::window_event::resize>([](int width, int height)
{
// ...
});
tip

If you only need an event to be called once, you can also use the once method.

Example Once Callback (Resize Window)
smartview.once<saucer::window_event::resize>([](int width, int height)
{
// Fired once, then automatically removed.
});

Remove Callback

As previously mentioned you can unregister callbacks by saving their id.
To remove a callback, simply call remove with the event-type as the first and the id as the second argument.

Example: Callback Removal
auto id = smartview.on<saucer::window_event::resize>([](int width, int height)
{
// ...
});

smartview.remove(saucer::window_event::resize, id);
tip

In case you simply want to remove all event callbacks of a specific event-type you can use the clear method.

Example: Clearing all Resize Callbacks
smartview.clear(saucer::window_event::resize);

Available Events

Called when the Window is resized.

Signature
std::function<void(int width, int height)>
Example
smartview.on<saucer::window_event::resize>([](int width, int height)
{
std::print("Width: {}, Height: {}\n", width, height);
});