added event example

This commit is contained in:
Jorijn van der Graaf 2025-11-10 21:31:06 +01:00
commit 6c3539fcd5
9 changed files with 249 additions and 31 deletions

View file

@ -24,7 +24,7 @@ import :EventTypes;
export namespace Crafter::CppDOMBindings {
std::int32_t clickHandlerMaxId = 0;
std::unordered_map<int, std::function<void(void)>>* clickHandlers = new std::unordered_map<int, std::function<void(void)>>();
std::unordered_map<int, std::function<void(Crafter::MouseEvent)>>* clickHandlers = new std::unordered_map<int, std::function<void(Crafter::MouseEvent)>>();
std::int32_t mouseOverHandlerMaxId = 0;
std::unordered_map<int, std::function<void(Crafter::MouseEvent)>>* mouseOverHandlers = new std::unordered_map<int, std::function<void(Crafter::MouseEvent)>>();
@ -106,8 +106,8 @@ extern "C" {
std::free(ptr);
}
__attribute__((export_name("ExecuteClickHandler"))) void ExecuteClickHandler(std::int32_t handlerID) {
Crafter::CppDOMBindings::clickHandlers->find(handlerID)->second();
__attribute__((export_name("ExecuteClickHandler"))) void ExecuteClickHandler(std::int32_t handlerID, double clientX, double clientY, double screenX, double screenY, std::int32_t button, std::int32_t buttons, bool altKey, bool ctrlKey, bool shiftKey, bool metaKey) {
Crafter::CppDOMBindings::clickHandlers->find(handlerID)->second(Crafter::MouseEvent(clientX, clientY, screenX, screenY, button, buttons, altKey, ctrlKey, shiftKey, metaKey));
}
__attribute__((export_name("ExecuteMouseOverHandler"))) void ExecuteMouseOverHandler(std::int32_t handlerID, double clientX, double clientY, double screenX, double screenY, std::int32_t button, std::int32_t buttons, bool altKey, bool ctrlKey, bool shiftKey, bool metaKey) {

View file

@ -63,7 +63,7 @@ namespace Crafter {
CppDOMBindings::SetInnerHTML(ptr, html);
}
std::int32_t AddClickListener(std::function<void(void)> callback) {
std::int32_t AddClickListener(std::function<void(Crafter::MouseEvent)> callback) {
std::int32_t id = CppDOMBindings::clickHandlerMaxId++;
clickHandlers.push_back(id);
CppDOMBindings::clickHandlers->insert({id, callback});