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:
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:
window->off(saucer::window::event::resize, id);It is also possible to disconnect all events of a specific type by omitting the ID:
window->off(saucer::window::event::resize);There is also the possibility to register events that will not be cleared by wildcard disconnects:
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.
Available Events
Section titled “Available Events”This event is emitted when a windows decorations change.
window->on<saucer::window::event::decorated>([](saucer::window::decoration) { // ...});This event is emitted when a window is (un-)maximized.
window->on<saucer::window::event::maximize>([](bool) { // ...});The passed parameter is set to true when the window was maximized and false otherwise.
This event is emitted when a window is (un-)minimized.
window->on<saucer::window::event::minimize>([](bool) { // ...});The passed parameter is set to true when the window was minimized and false otherwise.
This event is emitted when a window is closed.
window->on<saucer::window::event::closed>([] { // ...});This event is emitted when a window is resized.
window->on<saucer::window::event::resize>([](int, int) { // ...});The passed parameters are the new width and height.
This event is emitted when a window is (un-)focused.
window->on<saucer::window::event::focus>([](bool) { // ...});The passed parameter is set to true when the window was focused and false otherwise.
This event is emitted when a window is about to be closed.
window->on<saucer::window::event::close>([] -> saucer::policy { // ...});Subscribers of this event can block (saucer::policy::block) or allow (saucer::policy::allow) the close operation by returning the respective policy decision.