fetch
This commit is contained in:
parent
580e53d3bc
commit
98d0af014d
7 changed files with 132 additions and 57 deletions
|
|
@ -24,76 +24,79 @@ import :EventTypes;
|
|||
|
||||
export namespace Crafter::CppDOMBindings {
|
||||
std::int32_t clickHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(Crafter::MouseEvent)>>* clickHandlers = new std::unordered_map<int, std::function<void(Crafter::MouseEvent)>>();
|
||||
std::unordered_map<std::int32_t, std::function<void(Crafter::MouseEvent)>>* clickHandlers = new std::unordered_map<std::int32_t, 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)>>();
|
||||
std::unordered_map<std::int32_t, std::function<void(Crafter::MouseEvent)>>* mouseOverHandlers = new std::unordered_map<std::int32_t, std::function<void(Crafter::MouseEvent)>>();
|
||||
|
||||
std::int32_t mouseOutHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(Crafter::MouseEvent)>>* mouseOutHandlers = new std::unordered_map<int, std::function<void(Crafter::MouseEvent)>>();
|
||||
std::unordered_map<std::int32_t, std::function<void(Crafter::MouseEvent)>>* mouseOutHandlers = new std::unordered_map<std::int32_t, std::function<void(Crafter::MouseEvent)>>();
|
||||
|
||||
std::int32_t mouseMoveHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(Crafter::MouseEvent)>>* mouseMoveHandlers = new std::unordered_map<int, std::function<void(Crafter::MouseEvent)>>();
|
||||
std::unordered_map<std::int32_t, std::function<void(Crafter::MouseEvent)>>* mouseMoveHandlers = new std::unordered_map<std::int32_t, std::function<void(Crafter::MouseEvent)>>();
|
||||
|
||||
std::int32_t mouseDownHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(Crafter::MouseEvent)>>* mouseDownHandlers = new std::unordered_map<int, std::function<void(Crafter::MouseEvent)>>();
|
||||
std::unordered_map<std::int32_t, std::function<void(Crafter::MouseEvent)>>* mouseDownHandlers = new std::unordered_map<std::int32_t, std::function<void(Crafter::MouseEvent)>>();
|
||||
|
||||
std::int32_t mouseUpHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(Crafter::MouseEvent)>>* mouseUpHandlers = new std::unordered_map<int, std::function<void(Crafter::MouseEvent)>>();
|
||||
std::unordered_map<std::int32_t, std::function<void(Crafter::MouseEvent)>>* mouseUpHandlers = new std::unordered_map<std::int32_t, std::function<void(Crafter::MouseEvent)>>();
|
||||
|
||||
std::int32_t focusHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(Crafter::FocusEvent)>>* focusHandlers = new std::unordered_map<int, std::function<void(Crafter::FocusEvent)>>();
|
||||
std::unordered_map<std::int32_t, std::function<void(Crafter::FocusEvent)>>* focusHandlers = new std::unordered_map<std::int32_t, std::function<void(Crafter::FocusEvent)>>();
|
||||
|
||||
std::int32_t blurHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(Crafter::FocusEvent)>>* blurHandlers = new std::unordered_map<int, std::function<void(Crafter::FocusEvent)>>();
|
||||
std::unordered_map<std::int32_t, std::function<void(Crafter::FocusEvent)>>* blurHandlers = new std::unordered_map<std::int32_t, std::function<void(Crafter::FocusEvent)>>();
|
||||
|
||||
std::int32_t keyDownHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(Crafter::KeyboardEvent)>>* keyDownHandlers = new std::unordered_map<int, std::function<void(Crafter::KeyboardEvent)>>();
|
||||
std::unordered_map<std::int32_t, std::function<void(Crafter::KeyboardEvent)>>* keyDownHandlers = new std::unordered_map<std::int32_t, std::function<void(Crafter::KeyboardEvent)>>();
|
||||
|
||||
std::int32_t keyUpHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(Crafter::KeyboardEvent)>>* keyUpHandlers = new std::unordered_map<int, std::function<void(Crafter::KeyboardEvent)>>();
|
||||
std::unordered_map<std::int32_t, std::function<void(Crafter::KeyboardEvent)>>* keyUpHandlers = new std::unordered_map<std::int32_t, std::function<void(Crafter::KeyboardEvent)>>();
|
||||
|
||||
std::int32_t keyPressHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(Crafter::KeyboardEvent)>>* keyPressHandlers = new std::unordered_map<int, std::function<void(Crafter::KeyboardEvent)>>();
|
||||
std::unordered_map<std::int32_t, std::function<void(Crafter::KeyboardEvent)>>* keyPressHandlers = new std::unordered_map<std::int32_t, std::function<void(Crafter::KeyboardEvent)>>();
|
||||
|
||||
std::int32_t changeHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(Crafter::ChangeEvent)>>* changeHandlers = new std::unordered_map<int, std::function<void(Crafter::ChangeEvent)>>();
|
||||
std::unordered_map<std::int32_t, std::function<void(Crafter::ChangeEvent)>>* changeHandlers = new std::unordered_map<std::int32_t, std::function<void(Crafter::ChangeEvent)>>();
|
||||
|
||||
std::int32_t submitHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(void)>>* submitHandlers = new std::unordered_map<int, std::function<void(void)>>();
|
||||
std::unordered_map<std::int32_t, std::function<void(void)>>* submitHandlers = new std::unordered_map<std::int32_t, std::function<void(void)>>();
|
||||
|
||||
std::int32_t inputHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(Crafter::InputEvent)>>* inputHandlers = new std::unordered_map<int, std::function<void(Crafter::InputEvent)>>();
|
||||
std::unordered_map<std::int32_t, std::function<void(Crafter::InputEvent)>>* inputHandlers = new std::unordered_map<std::int32_t, std::function<void(Crafter::InputEvent)>>();
|
||||
|
||||
std::int32_t resizeHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(Crafter::ResizeEvent)>>* resizeHandlers = new std::unordered_map<int, std::function<void(Crafter::ResizeEvent)>>();
|
||||
std::unordered_map<std::int32_t, std::function<void(Crafter::ResizeEvent)>>* resizeHandlers = new std::unordered_map<std::int32_t, std::function<void(Crafter::ResizeEvent)>>();
|
||||
|
||||
std::int32_t scrollHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(Crafter::ScrollEvent)>>* scrollHandlers = new std::unordered_map<int, std::function<void(Crafter::ScrollEvent)>>();
|
||||
std::unordered_map<std::int32_t, std::function<void(Crafter::ScrollEvent)>>* scrollHandlers = new std::unordered_map<std::int32_t, std::function<void(Crafter::ScrollEvent)>>();
|
||||
|
||||
std::int32_t contextMenuHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(Crafter::MouseEvent)>>* contextMenuHandlers = new std::unordered_map<int, std::function<void(Crafter::MouseEvent)>>();
|
||||
std::unordered_map<std::int32_t, std::function<void(Crafter::MouseEvent)>>* contextMenuHandlers = new std::unordered_map<std::int32_t, std::function<void(Crafter::MouseEvent)>>();
|
||||
|
||||
std::int32_t dragStartHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(Crafter::MouseEvent)>>* dragStartHandlers = new std::unordered_map<int, std::function<void(Crafter::MouseEvent)>>();
|
||||
std::unordered_map<std::int32_t, std::function<void(Crafter::MouseEvent)>>* dragStartHandlers = new std::unordered_map<std::int32_t, std::function<void(Crafter::MouseEvent)>>();
|
||||
|
||||
std::int32_t dragEndHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(Crafter::MouseEvent)>>* dragEndHandlers = new std::unordered_map<int, std::function<void(Crafter::MouseEvent)>>();
|
||||
std::unordered_map<std::int32_t, std::function<void(Crafter::MouseEvent)>>* dragEndHandlers = new std::unordered_map<std::int32_t, std::function<void(Crafter::MouseEvent)>>();
|
||||
|
||||
std::int32_t dropHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(Crafter::MouseEvent)>>* dropHandlers = new std::unordered_map<int, std::function<void(Crafter::MouseEvent)>>();
|
||||
std::unordered_map<std::int32_t, std::function<void(Crafter::MouseEvent)>>* dropHandlers = new std::unordered_map<std::int32_t, std::function<void(Crafter::MouseEvent)>>();
|
||||
|
||||
std::int32_t wheelHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(Crafter::WheelEvent)>>* wheelHandlers = new std::unordered_map<int, std::function<void(Crafter::WheelEvent)>>();
|
||||
std::unordered_map<std::int32_t, std::function<void(Crafter::WheelEvent)>>* wheelHandlers = new std::unordered_map<std::int32_t, std::function<void(Crafter::WheelEvent)>>();
|
||||
|
||||
std::int32_t dragOverHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(Crafter::MouseEvent)>>* dragOverHandlers = new std::unordered_map<int, std::function<void(Crafter::MouseEvent)>>();
|
||||
std::unordered_map<std::int32_t, std::function<void(Crafter::MouseEvent)>>* dragOverHandlers = new std::unordered_map<std::int32_t, std::function<void(Crafter::MouseEvent)>>();
|
||||
|
||||
std::int32_t dragEnterHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(Crafter::MouseEvent)>>* dragEnterHandlers = new std::unordered_map<int, std::function<void(Crafter::MouseEvent)>>();
|
||||
std::unordered_map<std::int32_t, std::function<void(Crafter::MouseEvent)>>* dragEnterHandlers = new std::unordered_map<std::int32_t, std::function<void(Crafter::MouseEvent)>>();
|
||||
|
||||
std::int32_t dragLeaveHandlerMaxId = 0;
|
||||
std::unordered_map<int, std::function<void(Crafter::MouseEvent)>>* dragLeaveHandlers = new std::unordered_map<int, std::function<void(Crafter::MouseEvent)>>();
|
||||
std::unordered_map<std::int32_t, std::function<void(Crafter::MouseEvent)>>* dragLeaveHandlers = new std::unordered_map<std::int32_t, std::function<void(Crafter::MouseEvent)>>();
|
||||
|
||||
std::int32_t fetchHandlerMaxId = 0;
|
||||
std::unordered_map<std::int32_t, std::function<void(std::string)>>* fetchHandlers = new std::unordered_map<std::int32_t, std::function<void(std::string)>>();
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
|
@ -204,30 +207,19 @@ extern "C" {
|
|||
__attribute__((export_name("ExecuteDragLeaveHandler"))) void ExecuteDragLeaveHandler(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::dragLeaveHandlers->find(handlerID)->second(Crafter::MouseEvent(clientX, clientY, screenX, screenY, button, buttons, altKey, ctrlKey, shiftKey, metaKey));
|
||||
}
|
||||
|
||||
// Style functions
|
||||
__attribute__((export_name("setStyle"))) void SetStyle(void* ptr, const char* style, std::size_t styleLength) {
|
||||
// This will be implemented in JavaScript
|
||||
|
||||
__attribute__((export_name("ExecuteFetchHandler"))) void ExecuteFetchHandler(std::int32_t handlerID, const char* response) {
|
||||
std::cout << handlerID << std::endl;
|
||||
Crafter::CppDOMBindings::fetchHandlers->find(handlerID)->second(response);
|
||||
Crafter::CppDOMBindings::fetchHandlers->erase(handlerID);
|
||||
}
|
||||
|
||||
__attribute__((export_name("setProperty"))) void SetProperty(void* ptr, const char* property, std::size_t propertyLength, const char* value, std::size_t valueLength) {
|
||||
// This will be implemented in JavaScript
|
||||
}
|
||||
|
||||
__attribute__((export_name("addClass"))) void AddClass(void* ptr, const char* className, std::size_t classNameLength) {
|
||||
// This will be implemented in JavaScript
|
||||
}
|
||||
|
||||
__attribute__((export_name("removeClass"))) void RemoveClass(void* ptr, const char* className, std::size_t classNameLength) {
|
||||
// This will be implemented in JavaScript
|
||||
}
|
||||
|
||||
__attribute__((export_name("toggleClass"))) void ToggleClass(void* ptr, const char* className, std::size_t classNameLength) {
|
||||
// This will be implemented in JavaScript
|
||||
}
|
||||
|
||||
__attribute__((export_name("hasClass"))) bool HasClass(void* ptr, const char* className, std::size_t classNameLength) {
|
||||
// This will be implemented in JavaScript
|
||||
return false;
|
||||
}
|
||||
|
||||
export namespace Crafter::CppDOMBindings {
|
||||
__attribute__((import_module("env"), import_name("fetch"))) void Fetch(const char* url, std::int32_t urlLenght, std::int32_t handlerID);
|
||||
void Fetch(const std::string_view url, std::function<void(std::string)> callback) {
|
||||
std::int32_t id = fetchHandlerMaxId++;
|
||||
CppDOMBindings::fetchHandlers->insert({id, callback});
|
||||
Fetch(url.data(), url.size(), id);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue