click event
This commit is contained in:
parent
e35b7302cb
commit
f40afe684a
13 changed files with 151 additions and 20 deletions
|
|
@ -22,13 +22,26 @@ export module Crafter.CppDOM:Bindings;
|
|||
import std;
|
||||
|
||||
export namespace Crafter::CppDOM::Bindings {
|
||||
int clickHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(void)>>* clickHandlers = new std::unordered_map<int, std::function<void(void)>>();
|
||||
|
||||
__attribute__((import_module("env"), import_name("freeJs"))) void FreeJs(void* ptr);
|
||||
__attribute__((import_module("env"), import_name("getElementById"))) void* GetElementById(const char* id, std::size_t idLenght);
|
||||
inline void* GetElementById(const std::string& id) {
|
||||
return GetElementById(id.c_str(), id.size());
|
||||
void* GetElementById(const std::string_view id) {
|
||||
return GetElementById(id.data(), id.size());
|
||||
}
|
||||
__attribute__((import_module("env"), import_name("setInnerHTML"))) void SetInnerHTML(void* ptr, const char* html, std::size_t htmlLenght);
|
||||
inline void SetInnerHTML(void* ptr, const std::string& html) {
|
||||
SetInnerHTML(ptr, html.c_str(), html.size());
|
||||
void SetInnerHTML(void* ptr, const std::string_view html) {
|
||||
SetInnerHTML(ptr, html.data(), html.size());
|
||||
}
|
||||
|
||||
// Event handling functions
|
||||
__attribute__((import_module("env"), import_name("addClickListener"))) void AddClickListener(void* ptr, int id);
|
||||
__attribute__((import_module("env"), import_name("removeClickListener"))) void RemoveClickListener(void* ptr, int id);
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
__attribute__((export_name("ExecuteClickHandler"))) void ExecuteClickHandler(int a) {
|
||||
Crafter::CppDOM::Bindings::clickHandlers->find(static_cast<int>(a))->second();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue