Skip to content

Events

This page documents various window events


Saucer offers a simple event system. Classes that offer events have the following member functions:

  • on<event>(listener)
  • once<event>(callback)
  • off(event)
  • off(event, id)

Registering an event is as simple as calling on:

Example: Event Registration
const auto id = window->on<saucer::window::event::resize>([](int width, int height) {
// ...
});

Each registered event is associated with an ID. This ID can later be used to disconnect the event:

Example: Unregister Event
window->off(saucer::window::event::resize, id);

It is also possible to disconnect all events of a specific type by omitting the ID:

Example: Unregister Events
window->off(saucer::window::event::resize);

There is also the possibility to register events that will not be cleared by wildcard disconnects:

Example: Non-Clearable Event
window->on<saucer::window::event::resize>({{.func = [](int width, int height) { /*...*/ }, .clearable = false}});

These events can only be cleared by explicitly disconnecting them by their ID.

This event is emitted when a windows decorations change.

window->on<saucer::window::event::decorated>([](saucer::window::decoration) {
// ...
});