Skip to content

Add event infrastructure and app events.#81

Merged
crud89 merged 5 commits intomainfrom
events
Mar 22, 2023
Merged

Add event infrastructure and app events.#81
crud89 merged 5 commits intomainfrom
events

Conversation

@crud89
Copy link
Copy Markdown
Owner

@crud89 crud89 commented Mar 21, 2023

Describe the pull request

This PR adds an event infrastructure, which is the foundation for de-coupling certain aspects in apps from their implementation. Currently this only means that Apps define some events, which can be subscribed to. In the future, we might want to add events to other types to allow for a more flexible implementation.

Events are handled similar to those of .NET. Defining an event is straightforward:

Event<EventArgs> myEvent;

Here EventArgs is a default, empty event argument structure, that can be inherited from. Note that all arguments must be passed as members of such a structure and only one structure per event is allowed. The event host may call events using either of the following:

myEvent->invoke(this, { }); // Second argument is EventArgs instance.
myEvent(this, { }); // short-form; analogous to above.

To subscribe to a event, a client can call either Event<>::add or the operator+=:

host.myEvent.add([](const void* sender, EventArgs e) { });
host.myEvent += [](const void* sender, EventArgs e) { };

Event handlers are stored as std::function objects, so using std::bind to regular functions also works. If an event needs to be unsubscribed from, the client can store a token, that identifies the event subscription:

auto token = host.myEvent += [](const void* sender, EventArgs e) { };
host.myEvent -= token; // same as host.myEvent.remove(token);

All samples have been updated to use the the events startup, initializing and resizing. Overloading initialize, run or resize is no longer allowed.

@crud89 crud89 self-assigned this Mar 21, 2023
@crud89 crud89 added Priority: Medium A issue with normal priority. Type: Requirement labels Mar 21, 2023
@crud89 crud89 modified the milestones: Alpha #05, Alpha #04 Mar 21, 2023
@crud89 crud89 merged commit 654e492 into main Mar 22, 2023
@crud89 crud89 deleted the events branch March 22, 2023 09:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Priority: Medium A issue with normal priority.

Projects

Status: v0.4.1

Development

Successfully merging this pull request may close these issues.

1 participant