fixes
This commit is contained in:
parent
6210e9c99b
commit
2254ad53c5
11 changed files with 300 additions and 466 deletions
|
|
@ -1,84 +0,0 @@
|
||||||
# Complete Event Handling Example
|
|
||||||
|
|
||||||
This example demonstrates comprehensive event handling capabilities in Crafter.CppDOM.
|
|
||||||
|
|
||||||
## Features
|
|
||||||
|
|
||||||
- Shows how to handle various types of DOM events using C++
|
|
||||||
- Demonstrates mouse, keyboard, form, and window events
|
|
||||||
- Illustrates proper event listener attachment and callback handling
|
|
||||||
- Shows real-time interaction with UI elements
|
|
||||||
|
|
||||||
## Event Types Demonstrated
|
|
||||||
|
|
||||||
### Mouse Events
|
|
||||||
- Click events
|
|
||||||
- Mouse over/out events
|
|
||||||
- Mouse move events
|
|
||||||
|
|
||||||
### Focus Events
|
|
||||||
- Focus and blur events
|
|
||||||
|
|
||||||
### Keyboard Events
|
|
||||||
- Key down, up, and press events
|
|
||||||
|
|
||||||
### Form Events
|
|
||||||
- Change, submit, and input events
|
|
||||||
|
|
||||||
### Window Events
|
|
||||||
- Load, error, resize, and scroll events
|
|
||||||
|
|
||||||
### Context Menu Events
|
|
||||||
- Context menu events
|
|
||||||
|
|
||||||
### Drag and Drop Events
|
|
||||||
- Drag start, end, and drop events
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
import Crafter.CppDOM;
|
|
||||||
using namespace Crafter::CppDOM;
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
// Create UI elements
|
|
||||||
HtmlElement body("body");
|
|
||||||
body.SetInnerHTML("<h1>Complete Event Handling Demo</h1>"
|
|
||||||
"<button id='myButton'>Click Me!</button>"
|
|
||||||
"<input type='text' id='textInput' placeholder='Type something...'>"
|
|
||||||
"<p id='output'>Events will appear here</p>");
|
|
||||||
|
|
||||||
// Handle click event
|
|
||||||
HtmlElement button("myButton");
|
|
||||||
button.AddClickListener([]() {
|
|
||||||
HtmlElement output("output");
|
|
||||||
output.SetInnerHTML("Button was clicked!");
|
|
||||||
});
|
|
||||||
|
|
||||||
// Handle keyboard events
|
|
||||||
HtmlElement input("textInput");
|
|
||||||
input.AddInputListener([]() {
|
|
||||||
HtmlElement output("output");
|
|
||||||
output.SetInnerHTML("Input changed!");
|
|
||||||
});
|
|
||||||
|
|
||||||
// Handle form events
|
|
||||||
input.AddChangeListener([]() {
|
|
||||||
HtmlElement output("output");
|
|
||||||
output.SetInnerHTML("Form value changed!");
|
|
||||||
});
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Building and Running
|
|
||||||
|
|
||||||
```bash
|
|
||||||
crafter-build build executable
|
|
||||||
run.sh
|
|
||||||
```
|
|
||||||
|
|
||||||
Then navigate to `http://localhost:8080/` in your browser.
|
|
||||||
|
|
||||||
If caddy is not installed, you can use your favorite static file server instead.
|
|
||||||
|
|
@ -1,75 +0,0 @@
|
||||||
import Crafter.CppDOM;
|
|
||||||
using namespace Crafter;
|
|
||||||
|
|
||||||
HtmlElement* body = new HtmlElement("body", "<div id='container'><button id='myButton'>Click Me!</button><input type='text' id='textInput' placeholder='Type something'><div id='output'></div></div>");
|
|
||||||
HtmlElement* button = new HtmlElement("myButton");
|
|
||||||
HtmlElement* input = new HtmlElement("textInput");
|
|
||||||
HtmlElement* output = new HtmlElement("output");
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
// Click event
|
|
||||||
button->AddClickListener([&]() {
|
|
||||||
output->SetInnerHTML("Button was clicked!");
|
|
||||||
});
|
|
||||||
|
|
||||||
// Mouse events
|
|
||||||
button->AddMouseOverListener([&]() {
|
|
||||||
output->SetInnerHTML("Mouse over button!");
|
|
||||||
});
|
|
||||||
|
|
||||||
button->AddMouseOutListener([&]() {
|
|
||||||
output->SetInnerHTML("Mouse left button!");
|
|
||||||
});
|
|
||||||
|
|
||||||
// Focus/Blur events
|
|
||||||
input->AddFocusListener([&]() {
|
|
||||||
output->SetInnerHTML("Input focused!");
|
|
||||||
});
|
|
||||||
|
|
||||||
input->AddBlurListener([&]() {
|
|
||||||
output->SetInnerHTML("Input blurred!");
|
|
||||||
});
|
|
||||||
|
|
||||||
// Keyboard events
|
|
||||||
input->AddKeyDownListener([&]() {
|
|
||||||
output->SetInnerHTML("Key pressed in input!");
|
|
||||||
});
|
|
||||||
|
|
||||||
input->AddKeyUpListener([&]() {
|
|
||||||
output->SetInnerHTML("Key released in input!");
|
|
||||||
});
|
|
||||||
|
|
||||||
// Input/change events
|
|
||||||
input->AddInputListener([&]() {
|
|
||||||
output->SetInnerHTML("Input value changed!");
|
|
||||||
});
|
|
||||||
|
|
||||||
input->AddChangeListener([&]() {
|
|
||||||
output->SetInnerHTML("Input value changed and lost focus!");
|
|
||||||
});
|
|
||||||
|
|
||||||
// Context menu
|
|
||||||
button->AddContextMenuListener([&]() {
|
|
||||||
output->SetInnerHTML("Context menu opened!");
|
|
||||||
});
|
|
||||||
|
|
||||||
// Scroll event on body
|
|
||||||
body->AddScrollListener([&]() {
|
|
||||||
output->SetInnerHTML("Page scrolled!");
|
|
||||||
});
|
|
||||||
|
|
||||||
// Resize event
|
|
||||||
body->AddResizeListener([&]() {
|
|
||||||
output->SetInnerHTML("Window resized!");
|
|
||||||
});
|
|
||||||
|
|
||||||
// Load event
|
|
||||||
body->AddLoadListener([&]() {
|
|
||||||
output->SetInnerHTML("Page loaded!");
|
|
||||||
});
|
|
||||||
|
|
||||||
// Error event
|
|
||||||
body->AddErrorListener([&]() {
|
|
||||||
output->SetInnerHTML("An error occurred!");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
{
|
|
||||||
"name": "main",
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "executable",
|
|
||||||
"implementations": ["main"],
|
|
||||||
"target": "wasm32-wasi",
|
|
||||||
"debug" : true,
|
|
||||||
"dependencies": [
|
|
||||||
{
|
|
||||||
"path":"../../project.json",
|
|
||||||
"configuration":"lib-debug"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
caddy file-server --listen :8080 --root bin/executable
|
|
||||||
|
|
@ -4,30 +4,13 @@ import std;
|
||||||
|
|
||||||
HtmlElement* body = new HtmlElement("body", "<div id='container'>"
|
HtmlElement* body = new HtmlElement("body", "<div id='container'>"
|
||||||
"<h1>Enhanced Event Handling Demo</h1>"
|
"<h1>Enhanced Event Handling Demo</h1>"
|
||||||
"<button id='clickButton'>Click Me!</button>"
|
|
||||||
"<button id='mouseButton'>Mouse Events</button>"
|
|
||||||
"<input type='text' id='keyInput' placeholder='Press keys here'>"
|
"<input type='text' id='keyInput' placeholder='Press keys here'>"
|
||||||
"<input type='text' id='changeInput' placeholder='Change me'>"
|
|
||||||
"<div id='output'></div>"
|
"<div id='output'></div>"
|
||||||
"</div>");
|
"</div>");
|
||||||
HtmlElement* clickButton = new HtmlElement("clickButton");
|
|
||||||
HtmlElement* mouseButton = new HtmlElement("mouseButton");
|
|
||||||
HtmlElement* keyInput = new HtmlElement("keyInput");
|
HtmlElement* keyInput = new HtmlElement("keyInput");
|
||||||
HtmlElement* changeInput = new HtmlElement("changeInput");
|
|
||||||
HtmlElement* output = new HtmlElement("output");
|
HtmlElement* output = new HtmlElement("output");
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
// Click event - simple handler
|
|
||||||
clickButton->AddClickListener([&]() {
|
|
||||||
output->SetInnerHTML("<p>Simple click event triggered!</p>");
|
|
||||||
});
|
|
||||||
|
|
||||||
// Mouse events with position data
|
|
||||||
// mouseButton->AddMouseMoveListener([&](MouseEvent event) {
|
|
||||||
// output->SetInnerHTML("<p>Mouse moved to: (" + std::to_string(event.clientX) + ", " + std::to_string(event.clientY) + ")</p>");
|
|
||||||
// });
|
|
||||||
|
|
||||||
// Keyboard events with rich data
|
|
||||||
keyInput->AddKeyDownListener([&](KeyboardEvent event) {
|
keyInput->AddKeyDownListener([&](KeyboardEvent event) {
|
||||||
std::string keyInfo = std::format("<p>Key pressed: {}</p>", event.key);
|
std::string keyInfo = std::format("<p>Key pressed: {}</p>", event.key);
|
||||||
if (event.ctrlKey) keyInfo += "<p>Ctrl key pressed</p>";
|
if (event.ctrlKey) keyInfo += "<p>Ctrl key pressed</p>";
|
||||||
|
|
@ -35,29 +18,4 @@ int main(){
|
||||||
if (event.altKey) keyInfo += "<p>Alt key pressed</p>";
|
if (event.altKey) keyInfo += "<p>Alt key pressed</p>";
|
||||||
output->SetInnerHTML(keyInfo);
|
output->SetInnerHTML(keyInfo);
|
||||||
});
|
});
|
||||||
|
|
||||||
// // Input event with data
|
|
||||||
// keyInput->AddInputListener([&](InputEvent event) {
|
|
||||||
// output->SetInnerHTML(std::format("<p>Input data: {} (composing: {})</p>", event.data, event.isComposing));
|
|
||||||
// });
|
|
||||||
|
|
||||||
// Change event with value
|
|
||||||
changeInput->AddChangeListener([&](ChangeEvent event) {
|
|
||||||
output->SetInnerHTML("<p>Input value changed to: '" + event.value + "'</p>");
|
|
||||||
});
|
|
||||||
|
|
||||||
// Context menu with position
|
|
||||||
mouseButton->AddContextMenuListener([&](MouseEvent event) {
|
|
||||||
output->SetInnerHTML("<p>Context menu at: (" + std::to_string(event.clientX) + ", " + std::to_string(event.clientY) + ")</p>");
|
|
||||||
});
|
|
||||||
|
|
||||||
// Resize event
|
|
||||||
body->AddResizeListener([&](ResizeEvent event) {
|
|
||||||
output->SetInnerHTML("<p>Window resized to: " + std::to_string(event.width) + "x" + std::to_string(event.height) + "</p>");
|
|
||||||
});
|
|
||||||
|
|
||||||
// Scroll event
|
|
||||||
body->AddScrollListener([&](ScrollEvent event) {
|
|
||||||
output->SetInnerHTML("<p>Scrolled to: (" + std::to_string(event.scrollX) + ", " + std::to_string(event.scrollY) + ")</p>");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
@ -18,7 +18,7 @@ License along with this library; if not, write to the Free Software
|
||||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export module Crafter.CppDOM:Bindings;
|
export module Crafter.CppDOM:BindingsExport;
|
||||||
import std;
|
import std;
|
||||||
import :EventTypes;
|
import :EventTypes;
|
||||||
|
|
||||||
|
|
@ -94,89 +94,6 @@ export namespace Crafter::CppDOMBindings {
|
||||||
|
|
||||||
int dragLeaveHandlerMaxId = 0;
|
int 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<int, std::function<void(Crafter::MouseEvent)>>* dragLeaveHandlers = new std::unordered_map<int, std::function<void(Crafter::MouseEvent)>>();
|
||||||
|
|
||||||
__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);
|
|
||||||
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);
|
|
||||||
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);
|
|
||||||
|
|
||||||
__attribute__((import_module("env"), import_name("addMouseOverListener"))) void AddMouseOverListener(void* ptr, int id);
|
|
||||||
__attribute__((import_module("env"), import_name("removeMouseOverListener"))) void RemoveMouseOverListener(void* ptr, int id);
|
|
||||||
|
|
||||||
__attribute__((import_module("env"), import_name("addMouseOutListener"))) void AddMouseOutListener(void* ptr, int id);
|
|
||||||
__attribute__((import_module("env"), import_name("removeMouseOutListener"))) void RemoveMouseOutListener(void* ptr, int id);
|
|
||||||
|
|
||||||
__attribute__((import_module("env"), import_name("addMouseMoveListener"))) void AddMouseMoveListener(void* ptr, int id);
|
|
||||||
__attribute__((import_module("env"), import_name("removeMouseMoveListener"))) void RemoveMouseMoveListener(void* ptr, int id);
|
|
||||||
|
|
||||||
__attribute__((import_module("env"), import_name("addMouseDownListener"))) void AddMouseDownListener(void* ptr, int id);
|
|
||||||
__attribute__((import_module("env"), import_name("removeMouseDownListener"))) void RemoveMouseDownListener(void* ptr, int id);
|
|
||||||
|
|
||||||
__attribute__((import_module("env"), import_name("addMouseUpListener"))) void AddMouseUpListener(void* ptr, int id);
|
|
||||||
__attribute__((import_module("env"), import_name("removeMouseUpListener"))) void RemoveMouseUpListener(void* ptr, int id);
|
|
||||||
|
|
||||||
__attribute__((import_module("env"), import_name("addFocusListener"))) void AddFocusListener(void* ptr, int id);
|
|
||||||
__attribute__((import_module("env"), import_name("removeFocusListener"))) void RemoveFocusListener(void* ptr, int id);
|
|
||||||
|
|
||||||
__attribute__((import_module("env"), import_name("addBlurListener"))) void AddBlurListener(void* ptr, int id);
|
|
||||||
__attribute__((import_module("env"), import_name("removeBlurListener"))) void RemoveBlurListener(void* ptr, int id);
|
|
||||||
|
|
||||||
__attribute__((import_module("env"), import_name("addKeyDownListener"))) void AddKeyDownListener(void* ptr, int id);
|
|
||||||
__attribute__((import_module("env"), import_name("removeKeyDownListener"))) void RemoveKeyDownListener(void* ptr, int id);
|
|
||||||
|
|
||||||
__attribute__((import_module("env"), import_name("addKeyUpListener"))) void AddKeyUpListener(void* ptr, int id);
|
|
||||||
__attribute__((import_module("env"), import_name("removeKeyUpListener"))) void RemoveKeyUpListener(void* ptr, int id);
|
|
||||||
|
|
||||||
__attribute__((import_module("env"), import_name("addKeyPressListener"))) void AddKeyPressListener(void* ptr, int id);
|
|
||||||
__attribute__((import_module("env"), import_name("removeKeyPressListener"))) void RemoveKeyPressListener(void* ptr, int id);
|
|
||||||
|
|
||||||
__attribute__((import_module("env"), import_name("addChangeListener"))) void AddChangeListener(void* ptr, int id);
|
|
||||||
__attribute__((import_module("env"), import_name("removeChangeListener"))) void RemoveChangeListener(void* ptr, int id);
|
|
||||||
|
|
||||||
__attribute__((import_module("env"), import_name("addSubmitListener"))) void AddSubmitListener(void* ptr, int id);
|
|
||||||
__attribute__((import_module("env"), import_name("removeSubmitListener"))) void RemoveSubmitListener(void* ptr, int id);
|
|
||||||
|
|
||||||
__attribute__((import_module("env"), import_name("addInputListener"))) void AddInputListener(void* ptr, int id);
|
|
||||||
__attribute__((import_module("env"), import_name("removeInputListener"))) void RemoveInputListener(void* ptr, int id);
|
|
||||||
|
|
||||||
__attribute__((import_module("env"), import_name("addResizeListener"))) void AddResizeListener(void* ptr, int id);
|
|
||||||
__attribute__((import_module("env"), import_name("removeResizeListener"))) void RemoveResizeListener(void* ptr, int id);
|
|
||||||
|
|
||||||
__attribute__((import_module("env"), import_name("addScrollListener"))) void AddScrollListener(void* ptr, int id);
|
|
||||||
__attribute__((import_module("env"), import_name("removeScrollListener"))) void RemoveScrollListener(void* ptr, int id);
|
|
||||||
|
|
||||||
__attribute__((import_module("env"), import_name("addContextMenuListener"))) void AddContextMenuListener(void* ptr, int id);
|
|
||||||
__attribute__((import_module("env"), import_name("removeContextMenuListener"))) void RemoveContextMenuListener(void* ptr, int id);
|
|
||||||
|
|
||||||
__attribute__((import_module("env"), import_name("addDragStartListener"))) void AddDragStartListener(void* ptr, int id);
|
|
||||||
__attribute__((import_module("env"), import_name("removeDragStartListener"))) void RemoveDragStartListener(void* ptr, int id);
|
|
||||||
|
|
||||||
__attribute__((import_module("env"), import_name("addDragEndListener"))) void AddDragEndListener(void* ptr, int id);
|
|
||||||
__attribute__((import_module("env"), import_name("removeDragEndListener"))) void RemoveDragEndListener(void* ptr, int id);
|
|
||||||
|
|
||||||
__attribute__((import_module("env"), import_name("addDropListener"))) void AddDropListener(void* ptr, int id);
|
|
||||||
__attribute__((import_module("env"), import_name("removeDropListener"))) void RemoveDropListener(void* ptr, int id);
|
|
||||||
|
|
||||||
__attribute__((import_module("env"), import_name("addWheelListener"))) void AddWheelListener(void* ptr, int id);
|
|
||||||
__attribute__((import_module("env"), import_name("removeWheelListener"))) void RemoveWheelListener(void* ptr, int id);
|
|
||||||
|
|
||||||
__attribute__((import_module("env"), import_name("addDragOverListener"))) void AddDragOverListener(void* ptr, int id);
|
|
||||||
__attribute__((import_module("env"), import_name("removeDragOverListener"))) void RemoveDragOverListener(void* ptr, int id);
|
|
||||||
|
|
||||||
__attribute__((import_module("env"), import_name("addDragEnterListener"))) void AddDragEnterListener(void* ptr, int id);
|
|
||||||
__attribute__((import_module("env"), import_name("removeDragEnterListener"))) void RemoveDragEnterListener(void* ptr, int id);
|
|
||||||
|
|
||||||
__attribute__((import_module("env"), import_name("addDragLeaveListener"))) void AddDragLeaveListener(void* ptr, int id);
|
|
||||||
__attribute__((import_module("env"), import_name("removeDragLeaveListener"))) void RemoveDragLeaveListener(void* ptr, int id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
@ -234,9 +151,7 @@ extern "C" {
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((export_name("ExecuteChangeHandler"))) void ExecuteChangeHandler(std::int32_t handlerID, const char* value) {
|
__attribute__((export_name("ExecuteChangeHandler"))) void ExecuteChangeHandler(std::int32_t handlerID, const char* value) {
|
||||||
Crafter::ChangeEvent event;
|
Crafter::CppDOMBindings::changeHandlers->find(handlerID)->second(Crafter::ChangeEvent(value));
|
||||||
event.value = value;
|
|
||||||
Crafter::CppDOMBindings::changeHandlers->find(handlerID)->second(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((export_name("ExecuteSubmitHandler"))) void ExecuteSubmitHandler(std::int32_t handlerID) {
|
__attribute__((export_name("ExecuteSubmitHandler"))) void ExecuteSubmitHandler(std::int32_t handlerID) {
|
||||||
|
|
@ -244,138 +159,46 @@ extern "C" {
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((export_name("ExecuteInputHandler"))) void ExecuteInputHandler(std::int32_t handlerID, const char* data, bool isComposing) {
|
__attribute__((export_name("ExecuteInputHandler"))) void ExecuteInputHandler(std::int32_t handlerID, const char* data, bool isComposing) {
|
||||||
Crafter::InputEvent event;
|
Crafter::CppDOMBindings::inputHandlers->find(handlerID)->second(Crafter::InputEvent(data, isComposing));
|
||||||
event.data = data;
|
|
||||||
event.isComposing = isComposing;
|
|
||||||
Crafter::CppDOMBindings::inputHandlers->find(handlerID)->second(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((export_name("ExecuteResizeHandler"))) void ExecuteResizeHandler(std::int32_t handlerID, unsigned int width, unsigned int height) {
|
__attribute__((export_name("ExecuteResizeHandler"))) void ExecuteResizeHandler(std::int32_t handlerID, unsigned int width, unsigned int height) {
|
||||||
Crafter::ResizeEvent event;
|
Crafter::CppDOMBindings::resizeHandlers->find(handlerID)->second(Crafter::ResizeEvent(width, height));
|
||||||
event.width = width;
|
|
||||||
event.height = height;
|
|
||||||
Crafter::CppDOMBindings::resizeHandlers->find(handlerID)->second(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((export_name("ExecuteScrollHandler"))) void ExecuteScrollHandler(std::int32_t handlerID, double scrollX, double scrollY) {
|
__attribute__((export_name("ExecuteScrollHandler"))) void ExecuteScrollHandler(std::int32_t handlerID, double scrollX, double scrollY) {
|
||||||
Crafter::ScrollEvent event;
|
Crafter::CppDOMBindings::scrollHandlers->find(handlerID)->second(Crafter::ScrollEvent(scrollX, scrollY));
|
||||||
event.scrollX = scrollX;
|
|
||||||
event.scrollY = scrollY;
|
|
||||||
Crafter::CppDOMBindings::scrollHandlers->find(handlerID)->second(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((export_name("ExecuteContextMenuHandler"))) void ExecuteContextMenuHandler(std::int32_t handlerID, double clientX, double clientY, double screenX, double screenY, int button, bool altKey, bool ctrlKey, bool shiftKey, bool metaKey) {
|
__attribute__((export_name("ExecuteContextMenuHandler"))) void ExecuteContextMenuHandler(std::int32_t handlerID, double clientX, double clientY, double screenX, double screenY, int button, bool altKey, bool ctrlKey, bool shiftKey, bool metaKey) {
|
||||||
Crafter::MouseEvent event;
|
Crafter::CppDOMBindings::contextMenuHandlers->find(handlerID)->second(Crafter::MouseEvent(clientX, clientY, screenX, screenY, button, 0, altKey, ctrlKey, shiftKey, metaKey));
|
||||||
event.clientX = clientX;
|
|
||||||
event.clientY = clientY;
|
|
||||||
event.screenX = screenX;
|
|
||||||
event.screenY = screenY;
|
|
||||||
event.button = button;
|
|
||||||
event.altKey = altKey;
|
|
||||||
event.ctrlKey = ctrlKey;
|
|
||||||
event.shiftKey = shiftKey;
|
|
||||||
event.metaKey = metaKey;
|
|
||||||
Crafter::CppDOMBindings::contextMenuHandlers->find(handlerID)->second(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((export_name("ExecuteDragStartHandler"))) void ExecuteDragStartHandler(std::int32_t handlerID, double clientX, double clientY, double screenX, double screenY, int button, bool altKey, bool ctrlKey, bool shiftKey, bool metaKey) {
|
__attribute__((export_name("ExecuteDragStartHandler"))) void ExecuteDragStartHandler(std::int32_t handlerID, double clientX, double clientY, double screenX, double screenY, int button, bool altKey, bool ctrlKey, bool shiftKey, bool metaKey) {
|
||||||
Crafter::MouseEvent event;
|
Crafter::CppDOMBindings::dragStartHandlers->find(handlerID)->second(Crafter::MouseEvent(clientX, clientY, screenX, screenY, button, 0, altKey, ctrlKey, shiftKey, metaKey));
|
||||||
event.clientX = clientX;
|
|
||||||
event.clientY = clientY;
|
|
||||||
event.screenX = screenX;
|
|
||||||
event.screenY = screenY;
|
|
||||||
event.button = button;
|
|
||||||
event.altKey = altKey;
|
|
||||||
event.ctrlKey = ctrlKey;
|
|
||||||
event.shiftKey = shiftKey;
|
|
||||||
event.metaKey = metaKey;
|
|
||||||
Crafter::CppDOMBindings::dragStartHandlers->find(handlerID)->second(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((export_name("ExecuteDragEndHandler"))) void ExecuteDragEndHandler(std::int32_t handlerID, double clientX, double clientY, double screenX, double screenY, int button, bool altKey, bool ctrlKey, bool shiftKey, bool metaKey) {
|
__attribute__((export_name("ExecuteDragEndHandler"))) void ExecuteDragEndHandler(std::int32_t handlerID, double clientX, double clientY, double screenX, double screenY, int button, bool altKey, bool ctrlKey, bool shiftKey, bool metaKey) {
|
||||||
Crafter::MouseEvent event;
|
Crafter::CppDOMBindings::dragEndHandlers->find(handlerID)->second(Crafter::MouseEvent(clientX, clientY, screenX, screenY, button, 0, altKey, ctrlKey, shiftKey, metaKey));
|
||||||
event.clientX = clientX;
|
|
||||||
event.clientY = clientY;
|
|
||||||
event.screenX = screenX;
|
|
||||||
event.screenY = screenY;
|
|
||||||
event.button = button;
|
|
||||||
event.altKey = altKey;
|
|
||||||
event.ctrlKey = ctrlKey;
|
|
||||||
event.shiftKey = shiftKey;
|
|
||||||
event.metaKey = metaKey;
|
|
||||||
Crafter::CppDOMBindings::dragEndHandlers->find(handlerID)->second(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((export_name("ExecuteDropHandler"))) void ExecuteDropHandler(std::int32_t handlerID, double clientX, double clientY, double screenX, double screenY, int button, bool altKey, bool ctrlKey, bool shiftKey, bool metaKey) {
|
__attribute__((export_name("ExecuteDropHandler"))) void ExecuteDropHandler(std::int32_t handlerID, double clientX, double clientY, double screenX, double screenY, int button, bool altKey, bool ctrlKey, bool shiftKey, bool metaKey) {
|
||||||
Crafter::MouseEvent event;
|
Crafter::CppDOMBindings::dropHandlers->find(handlerID)->second(Crafter::MouseEvent(clientX, clientY, screenX, screenY, button, 0, altKey, ctrlKey, shiftKey, metaKey));
|
||||||
event.clientX = clientX;
|
|
||||||
event.clientY = clientY;
|
|
||||||
event.screenX = screenX;
|
|
||||||
event.screenY = screenY;
|
|
||||||
event.button = button;
|
|
||||||
event.altKey = altKey;
|
|
||||||
event.ctrlKey = ctrlKey;
|
|
||||||
event.shiftKey = shiftKey;
|
|
||||||
event.metaKey = metaKey;
|
|
||||||
Crafter::CppDOMBindings::dropHandlers->find(handlerID)->second(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((export_name("ExecuteWheelHandler"))) void ExecuteWheelHandler(std::int32_t handlerID, double deltaX, double deltaY, double deltaZ, int deltaMode, double clientX, double clientY, double screenX, double screenY, int button, bool altKey, bool ctrlKey, bool shiftKey, bool metaKey) {
|
__attribute__((export_name("ExecuteWheelHandler"))) void ExecuteWheelHandler(std::int32_t handlerID, double deltaX, double deltaY, double deltaZ, int deltaMode, double clientX, double clientY, double screenX, double screenY, int button, bool altKey, bool ctrlKey, bool shiftKey, bool metaKey) {
|
||||||
Crafter::WheelEvent event;
|
Crafter::CppDOMBindings::wheelHandlers->find(handlerID)->second(Crafter::WheelEvent(clientX, clientY, screenX, screenY, button, 0, altKey, ctrlKey, shiftKey, metaKey, deltaX, deltaY, deltaZ));
|
||||||
event.deltaX = deltaX;
|
|
||||||
event.deltaY = deltaY;
|
|
||||||
event.deltaZ = deltaZ;
|
|
||||||
event.clientX = clientX;
|
|
||||||
event.clientY = clientY;
|
|
||||||
event.screenX = screenX;
|
|
||||||
event.screenY = screenY;
|
|
||||||
event.button = button;
|
|
||||||
event.altKey = altKey;
|
|
||||||
event.ctrlKey = ctrlKey;
|
|
||||||
event.shiftKey = shiftKey;
|
|
||||||
event.metaKey = metaKey;
|
|
||||||
Crafter::CppDOMBindings::wheelHandlers->find(handlerID)->second(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((export_name("ExecuteDragOverHandler"))) void ExecuteDragOverHandler(std::int32_t handlerID, double clientX, double clientY, double screenX, double screenY, int button, bool altKey, bool ctrlKey, bool shiftKey, bool metaKey) {
|
__attribute__((export_name("ExecuteDragOverHandler"))) void ExecuteDragOverHandler(std::int32_t handlerID, double clientX, double clientY, double screenX, double screenY, int button, bool altKey, bool ctrlKey, bool shiftKey, bool metaKey) {
|
||||||
Crafter::MouseEvent event;
|
Crafter::CppDOMBindings::dragOverHandlers->find(handlerID)->second(Crafter::MouseEvent(clientX, clientY, screenX, screenY, button, 0, altKey, ctrlKey, shiftKey, metaKey));
|
||||||
event.clientX = clientX;
|
|
||||||
event.clientY = clientY;
|
|
||||||
event.screenX = screenX;
|
|
||||||
event.screenY = screenY;
|
|
||||||
event.button = button;
|
|
||||||
event.altKey = altKey;
|
|
||||||
event.ctrlKey = ctrlKey;
|
|
||||||
event.shiftKey = shiftKey;
|
|
||||||
event.metaKey = metaKey;
|
|
||||||
Crafter::CppDOMBindings::dragOverHandlers->find(handlerID)->second(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((export_name("ExecuteDragEnterHandler"))) void ExecuteDragEnterHandler(std::int32_t handlerID, double clientX, double clientY, double screenX, double screenY, int button, bool altKey, bool ctrlKey, bool shiftKey, bool metaKey) {
|
__attribute__((export_name("ExecuteDragEnterHandler"))) void ExecuteDragEnterHandler(std::int32_t handlerID, double clientX, double clientY, double screenX, double screenY, int button, bool altKey, bool ctrlKey, bool shiftKey, bool metaKey) {
|
||||||
Crafter::MouseEvent event;
|
Crafter::CppDOMBindings::dragEnterHandlers->find(handlerID)->second(Crafter::MouseEvent(clientX, clientY, screenX, screenY, button, 0, altKey, ctrlKey, shiftKey, metaKey));
|
||||||
event.clientX = clientX;
|
|
||||||
event.clientY = clientY;
|
|
||||||
event.screenX = screenX;
|
|
||||||
event.screenY = screenY;
|
|
||||||
event.button = button;
|
|
||||||
event.altKey = altKey;
|
|
||||||
event.ctrlKey = ctrlKey;
|
|
||||||
event.shiftKey = shiftKey;
|
|
||||||
event.metaKey = metaKey;
|
|
||||||
Crafter::CppDOMBindings::dragEnterHandlers->find(handlerID)->second(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((export_name("ExecuteDragLeaveHandler"))) void ExecuteDragLeaveHandler(std::int32_t handlerID, double clientX, double clientY, double screenX, double screenY, int button, bool altKey, bool ctrlKey, bool shiftKey, bool metaKey) {
|
__attribute__((export_name("ExecuteDragLeaveHandler"))) void ExecuteDragLeaveHandler(std::int32_t handlerID, double clientX, double clientY, double screenX, double screenY, int button, bool altKey, bool ctrlKey, bool shiftKey, bool metaKey) {
|
||||||
Crafter::MouseEvent event;
|
Crafter::CppDOMBindings::dragLeaveHandlers->find(handlerID)->second(Crafter::MouseEvent(clientX, clientY, screenX, screenY, button, 0, altKey, ctrlKey, shiftKey, metaKey));
|
||||||
event.clientX = clientX;
|
|
||||||
event.clientY = clientY;
|
|
||||||
event.screenX = screenX;
|
|
||||||
event.screenY = screenY;
|
|
||||||
event.button = button;
|
|
||||||
event.altKey = altKey;
|
|
||||||
event.ctrlKey = ctrlKey;
|
|
||||||
event.shiftKey = shiftKey;
|
|
||||||
event.metaKey = metaKey;
|
|
||||||
Crafter::CppDOMBindings::dragLeaveHandlers->find(handlerID)->second(event);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
108
interfaces/Crafter.CppDOM-BindingsImport.cppm
Normal file
108
interfaces/Crafter.CppDOM-BindingsImport.cppm
Normal file
|
|
@ -0,0 +1,108 @@
|
||||||
|
/*
|
||||||
|
Crafter.CppDOM
|
||||||
|
Copyright (C) 2025 Catcrafts
|
||||||
|
Catcrafts.net
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
export module Crafter.CppDOM:BindingsImport;
|
||||||
|
import std;
|
||||||
|
import :EventTypes;
|
||||||
|
|
||||||
|
export namespace Crafter::CppDOMBindings {
|
||||||
|
__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);
|
||||||
|
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);
|
||||||
|
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);
|
||||||
|
|
||||||
|
__attribute__((import_module("env"), import_name("addMouseOverListener"))) void AddMouseOverListener(void* ptr, int id);
|
||||||
|
__attribute__((import_module("env"), import_name("removeMouseOverListener"))) void RemoveMouseOverListener(void* ptr, int id);
|
||||||
|
|
||||||
|
__attribute__((import_module("env"), import_name("addMouseOutListener"))) void AddMouseOutListener(void* ptr, int id);
|
||||||
|
__attribute__((import_module("env"), import_name("removeMouseOutListener"))) void RemoveMouseOutListener(void* ptr, int id);
|
||||||
|
|
||||||
|
__attribute__((import_module("env"), import_name("addMouseMoveListener"))) void AddMouseMoveListener(void* ptr, int id);
|
||||||
|
__attribute__((import_module("env"), import_name("removeMouseMoveListener"))) void RemoveMouseMoveListener(void* ptr, int id);
|
||||||
|
|
||||||
|
__attribute__((import_module("env"), import_name("addMouseDownListener"))) void AddMouseDownListener(void* ptr, int id);
|
||||||
|
__attribute__((import_module("env"), import_name("removeMouseDownListener"))) void RemoveMouseDownListener(void* ptr, int id);
|
||||||
|
|
||||||
|
__attribute__((import_module("env"), import_name("addMouseUpListener"))) void AddMouseUpListener(void* ptr, int id);
|
||||||
|
__attribute__((import_module("env"), import_name("removeMouseUpListener"))) void RemoveMouseUpListener(void* ptr, int id);
|
||||||
|
|
||||||
|
__attribute__((import_module("env"), import_name("addFocusListener"))) void AddFocusListener(void* ptr, int id);
|
||||||
|
__attribute__((import_module("env"), import_name("removeFocusListener"))) void RemoveFocusListener(void* ptr, int id);
|
||||||
|
|
||||||
|
__attribute__((import_module("env"), import_name("addBlurListener"))) void AddBlurListener(void* ptr, int id);
|
||||||
|
__attribute__((import_module("env"), import_name("removeBlurListener"))) void RemoveBlurListener(void* ptr, int id);
|
||||||
|
|
||||||
|
__attribute__((import_module("env"), import_name("addKeyDownListener"))) void AddKeyDownListener(void* ptr, int id);
|
||||||
|
__attribute__((import_module("env"), import_name("removeKeyDownListener"))) void RemoveKeyDownListener(void* ptr, int id);
|
||||||
|
|
||||||
|
__attribute__((import_module("env"), import_name("addKeyUpListener"))) void AddKeyUpListener(void* ptr, int id);
|
||||||
|
__attribute__((import_module("env"), import_name("removeKeyUpListener"))) void RemoveKeyUpListener(void* ptr, int id);
|
||||||
|
|
||||||
|
__attribute__((import_module("env"), import_name("addKeyPressListener"))) void AddKeyPressListener(void* ptr, int id);
|
||||||
|
__attribute__((import_module("env"), import_name("removeKeyPressListener"))) void RemoveKeyPressListener(void* ptr, int id);
|
||||||
|
|
||||||
|
__attribute__((import_module("env"), import_name("addChangeListener"))) void AddChangeListener(void* ptr, int id);
|
||||||
|
__attribute__((import_module("env"), import_name("removeChangeListener"))) void RemoveChangeListener(void* ptr, int id);
|
||||||
|
|
||||||
|
__attribute__((import_module("env"), import_name("addSubmitListener"))) void AddSubmitListener(void* ptr, int id);
|
||||||
|
__attribute__((import_module("env"), import_name("removeSubmitListener"))) void RemoveSubmitListener(void* ptr, int id);
|
||||||
|
|
||||||
|
__attribute__((import_module("env"), import_name("addInputListener"))) void AddInputListener(void* ptr, int id);
|
||||||
|
__attribute__((import_module("env"), import_name("removeInputListener"))) void RemoveInputListener(void* ptr, int id);
|
||||||
|
|
||||||
|
__attribute__((import_module("env"), import_name("addResizeListener"))) void AddResizeListener(void* ptr, int id);
|
||||||
|
__attribute__((import_module("env"), import_name("removeResizeListener"))) void RemoveResizeListener(void* ptr, int id);
|
||||||
|
|
||||||
|
__attribute__((import_module("env"), import_name("addScrollListener"))) void AddScrollListener(void* ptr, int id);
|
||||||
|
__attribute__((import_module("env"), import_name("removeScrollListener"))) void RemoveScrollListener(void* ptr, int id);
|
||||||
|
|
||||||
|
__attribute__((import_module("env"), import_name("addContextMenuListener"))) void AddContextMenuListener(void* ptr, int id);
|
||||||
|
__attribute__((import_module("env"), import_name("removeContextMenuListener"))) void RemoveContextMenuListener(void* ptr, int id);
|
||||||
|
|
||||||
|
__attribute__((import_module("env"), import_name("addDragStartListener"))) void AddDragStartListener(void* ptr, int id);
|
||||||
|
__attribute__((import_module("env"), import_name("removeDragStartListener"))) void RemoveDragStartListener(void* ptr, int id);
|
||||||
|
|
||||||
|
__attribute__((import_module("env"), import_name("addDragEndListener"))) void AddDragEndListener(void* ptr, int id);
|
||||||
|
__attribute__((import_module("env"), import_name("removeDragEndListener"))) void RemoveDragEndListener(void* ptr, int id);
|
||||||
|
|
||||||
|
__attribute__((import_module("env"), import_name("addDropListener"))) void AddDropListener(void* ptr, int id);
|
||||||
|
__attribute__((import_module("env"), import_name("removeDropListener"))) void RemoveDropListener(void* ptr, int id);
|
||||||
|
|
||||||
|
__attribute__((import_module("env"), import_name("addWheelListener"))) void AddWheelListener(void* ptr, int id);
|
||||||
|
__attribute__((import_module("env"), import_name("removeWheelListener"))) void RemoveWheelListener(void* ptr, int id);
|
||||||
|
|
||||||
|
__attribute__((import_module("env"), import_name("addDragOverListener"))) void AddDragOverListener(void* ptr, int id);
|
||||||
|
__attribute__((import_module("env"), import_name("removeDragOverListener"))) void RemoveDragOverListener(void* ptr, int id);
|
||||||
|
|
||||||
|
__attribute__((import_module("env"), import_name("addDragEnterListener"))) void AddDragEnterListener(void* ptr, int id);
|
||||||
|
__attribute__((import_module("env"), import_name("removeDragEnterListener"))) void RemoveDragEnterListener(void* ptr, int id);
|
||||||
|
|
||||||
|
__attribute__((import_module("env"), import_name("addDragLeaveListener"))) void AddDragLeaveListener(void* ptr, int id);
|
||||||
|
__attribute__((import_module("env"), import_name("removeDragLeaveListener"))) void RemoveDragLeaveListener(void* ptr, int id);
|
||||||
|
}
|
||||||
|
|
@ -44,30 +44,36 @@ export namespace Crafter {
|
||||||
bool ctrlKey;
|
bool ctrlKey;
|
||||||
bool shiftKey;
|
bool shiftKey;
|
||||||
bool metaKey;
|
bool metaKey;
|
||||||
|
MouseEvent(double clientX, double clientY, double screenX, double screenY, std::uint_fast32_t button, std::uint_fast32_t buttons, bool altKey, bool ctrlKey, bool shiftKey, bool metaKey) : clientX(clientX), clientY(clientY), screenX(screenX), screenY(screenY), button(button), buttons(buttons), altKey(altKey), ctrlKey(ctrlKey), shiftKey(shiftKey), metaKey(metaKey) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct InputEvent {
|
struct InputEvent {
|
||||||
std::string data;
|
std::string data;
|
||||||
bool isComposing;
|
bool isComposing;
|
||||||
|
InputEvent(const char* data, bool isComposing) : data(data), isComposing(isComposing) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct WheelEvent : public MouseEvent {
|
struct WheelEvent : public MouseEvent {
|
||||||
double deltaX;
|
double deltaX;
|
||||||
double deltaY;
|
double deltaY;
|
||||||
double deltaZ;
|
double deltaZ;
|
||||||
|
WheelEvent(double clientX, double clientY, double screenX, double screenY, std::uint_fast32_t button, std::uint_fast32_t buttons, bool altKey, bool ctrlKey, bool shiftKey, bool metaKey, double deltaX, double deltaY, double deltaZ): MouseEvent(clientX, clientY, screenX, screenY, button, buttons, altKey, ctrlKey, shiftKey, metaKey), deltaX(deltaX), deltaY(deltaY), deltaZ(deltaZ) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ResizeEvent {
|
struct ResizeEvent {
|
||||||
std::uint_fast32_t width;
|
std::uint_fast32_t width;
|
||||||
std::uint_fast32_t height;
|
std::uint_fast32_t height;
|
||||||
|
ResizeEvent(std::uint_fast32_t width, std::uint_fast32_t height) : width(width), height(height) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ScrollEvent {
|
struct ScrollEvent {
|
||||||
double scrollX;
|
double scrollX;
|
||||||
double scrollY;
|
double scrollY;
|
||||||
|
ScrollEvent(double scrollX, double scrollY) : scrollX(scrollX), scrollY(scrollY) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ChangeEvent {
|
struct ChangeEvent {
|
||||||
std::string value;
|
std::string value;
|
||||||
|
ChangeEvent(const char* value) : value(value) {}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -20,14 +20,39 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
export module Crafter.CppDOM:HtmlElement;
|
export module Crafter.CppDOM:HtmlElement;
|
||||||
import std;
|
import std;
|
||||||
import :Bindings;
|
import :BindingsExport;
|
||||||
|
import :BindingsImport;
|
||||||
import :EventTypes;
|
import :EventTypes;
|
||||||
|
|
||||||
namespace Crafter {
|
namespace Crafter {
|
||||||
export class HtmlElement {
|
export class HtmlElement {
|
||||||
public:
|
public:
|
||||||
void* const ptr;
|
void* const ptr;
|
||||||
std::vector<std::int32_t> handlers;
|
std::vector<std::int32_t> clickHandlers;
|
||||||
|
std::vector<std::int32_t> mouseOverHandlers;
|
||||||
|
std::vector<std::int32_t> mouseOutHandlers;
|
||||||
|
std::vector<std::int32_t> mouseMoveHandlers;
|
||||||
|
std::vector<std::int32_t> mouseDownHandlers;
|
||||||
|
std::vector<std::int32_t> mouseUpHandlers;
|
||||||
|
std::vector<std::int32_t> focusHandlers;
|
||||||
|
std::vector<std::int32_t> blurHandlers;
|
||||||
|
std::vector<std::int32_t> keyDownHandlers;
|
||||||
|
std::vector<std::int32_t> keyUpHandlers;
|
||||||
|
std::vector<std::int32_t> keyPressHandlers;
|
||||||
|
std::vector<std::int32_t> changeHandlers;
|
||||||
|
std::vector<std::int32_t> submitHandlers;
|
||||||
|
std::vector<std::int32_t> inputHandlers;
|
||||||
|
std::vector<std::int32_t> resizeHandlers;
|
||||||
|
std::vector<std::int32_t> scrollHandlers;
|
||||||
|
std::vector<std::int32_t> contextMenuHandlers;
|
||||||
|
std::vector<std::int32_t> dragStartHandlers;
|
||||||
|
std::vector<std::int32_t> dragEndHandlers;
|
||||||
|
std::vector<std::int32_t> dropHandlers;
|
||||||
|
std::vector<std::int32_t> dragOverHandlers;
|
||||||
|
std::vector<std::int32_t> dragEnterHandlers;
|
||||||
|
std::vector<std::int32_t> dragLeaveHandlers;
|
||||||
|
std::vector<std::int32_t> wheelHandlers;
|
||||||
|
|
||||||
HtmlElement(const std::string_view id): ptr(CppDOMBindings::GetElementById(id)) {
|
HtmlElement(const std::string_view id): ptr(CppDOMBindings::GetElementById(id)) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -38,89 +63,86 @@ namespace Crafter {
|
||||||
CppDOMBindings::SetInnerHTML(ptr, html);
|
CppDOMBindings::SetInnerHTML(ptr, html);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Event handling methods with event data
|
|
||||||
|
|
||||||
// Mouse Events
|
|
||||||
std::int32_t AddClickListener(std::function<void(void)> callback) {
|
std::int32_t AddClickListener(std::function<void(void)> callback) {
|
||||||
std::int32_t id = CppDOMBindings::clickHandlerMaxId++;
|
std::int32_t id = CppDOMBindings::clickHandlerMaxId++;
|
||||||
handlers.push_back(id);
|
clickHandlers.push_back(id);
|
||||||
CppDOMBindings::clickHandlers->insert({id, callback});
|
CppDOMBindings::clickHandlers->insert({id, callback});
|
||||||
CppDOMBindings::AddClickListener(ptr, id);
|
CppDOMBindings::AddClickListener(ptr, id);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveClickListener(std::int32_t id) {
|
void RemoveClickListener(std::int32_t id) {
|
||||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
clickHandlers.erase(std::remove(clickHandlers.begin(), clickHandlers.end(), id), clickHandlers.end());
|
||||||
CppDOMBindings::clickHandlers->erase(id);
|
CppDOMBindings::clickHandlers->erase(id);
|
||||||
CppDOMBindings::RemoveClickListener(ptr, id);
|
CppDOMBindings::RemoveClickListener(ptr, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::int32_t AddMouseOverListener(std::function<void(void)> callback) {
|
std::int32_t AddMouseOverListener(std::function<void(void)> callback) {
|
||||||
std::int32_t id = CppDOMBindings::mouseOverHandlerMaxId++;
|
std::int32_t id = CppDOMBindings::mouseOverHandlerMaxId++;
|
||||||
handlers.push_back(id);
|
mouseOverHandlers.push_back(id);
|
||||||
CppDOMBindings::mouseOverHandlers->insert({id, callback});
|
CppDOMBindings::mouseOverHandlers->insert({id, callback});
|
||||||
CppDOMBindings::AddMouseOverListener(ptr, id);
|
CppDOMBindings::AddMouseOverListener(ptr, id);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveMouseOverListener(std::int32_t id) {
|
void RemoveMouseOverListener(std::int32_t id) {
|
||||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
mouseOverHandlers.erase(std::remove(mouseOverHandlers.begin(), mouseOverHandlers.end(), id), mouseOverHandlers.end());
|
||||||
CppDOMBindings::mouseOverHandlers->erase(id);
|
CppDOMBindings::mouseOverHandlers->erase(id);
|
||||||
CppDOMBindings::RemoveMouseOverListener(ptr, id);
|
CppDOMBindings::RemoveMouseOverListener(ptr, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::int32_t AddMouseOutListener(std::function<void(void)> callback) {
|
std::int32_t AddMouseOutListener(std::function<void(void)> callback) {
|
||||||
std::int32_t id = CppDOMBindings::mouseOutHandlerMaxId++;
|
std::int32_t id = CppDOMBindings::mouseOutHandlerMaxId++;
|
||||||
handlers.push_back(id);
|
mouseOutHandlers.push_back(id);
|
||||||
CppDOMBindings::mouseOutHandlers->insert({id, callback});
|
CppDOMBindings::mouseOutHandlers->insert({id, callback});
|
||||||
CppDOMBindings::AddMouseOutListener(ptr, id);
|
CppDOMBindings::AddMouseOutListener(ptr, id);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveMouseOutListener(std::int32_t id) {
|
void RemoveMouseOutListener(std::int32_t id) {
|
||||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
mouseOutHandlers.erase(std::remove(mouseOutHandlers.begin(), mouseOutHandlers.end(), id), mouseOutHandlers.end());
|
||||||
CppDOMBindings::mouseOutHandlers->erase(id);
|
CppDOMBindings::mouseOutHandlers->erase(id);
|
||||||
CppDOMBindings::RemoveMouseOutListener(ptr, id);
|
CppDOMBindings::RemoveMouseOutListener(ptr, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::int32_t AddMouseMoveListener(std::function<void(void)> callback) {
|
std::int32_t AddMouseMoveListener(std::function<void(void)> callback) {
|
||||||
std::int32_t id = CppDOMBindings::mouseMoveHandlerMaxId++;
|
std::int32_t id = CppDOMBindings::mouseMoveHandlerMaxId++;
|
||||||
handlers.push_back(id);
|
mouseMoveHandlers.push_back(id);
|
||||||
CppDOMBindings::mouseMoveHandlers->insert({id, callback});
|
CppDOMBindings::mouseMoveHandlers->insert({id, callback});
|
||||||
CppDOMBindings::AddMouseMoveListener(ptr, id);
|
CppDOMBindings::AddMouseMoveListener(ptr, id);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveMouseMoveListener(std::int32_t id) {
|
void RemoveMouseMoveListener(std::int32_t id) {
|
||||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
mouseMoveHandlers.erase(std::remove(mouseMoveHandlers.begin(), mouseMoveHandlers.end(), id), mouseMoveHandlers.end());
|
||||||
CppDOMBindings::mouseMoveHandlers->erase(id);
|
CppDOMBindings::mouseMoveHandlers->erase(id);
|
||||||
CppDOMBindings::RemoveMouseMoveListener(ptr, id);
|
CppDOMBindings::RemoveMouseMoveListener(ptr, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::int32_t AddMouseDownListener(std::function<void(void)> callback) {
|
std::int32_t AddMouseDownListener(std::function<void(void)> callback) {
|
||||||
std::int32_t id = CppDOMBindings::mouseDownHandlerMaxId++;
|
std::int32_t id = CppDOMBindings::mouseDownHandlerMaxId++;
|
||||||
handlers.push_back(id);
|
mouseDownHandlers.push_back(id);
|
||||||
CppDOMBindings::mouseDownHandlers->insert({id, callback});
|
CppDOMBindings::mouseDownHandlers->insert({id, callback});
|
||||||
CppDOMBindings::AddMouseDownListener(ptr, id);
|
CppDOMBindings::AddMouseDownListener(ptr, id);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveMouseDownListener(std::int32_t id) {
|
void RemoveMouseDownListener(std::int32_t id) {
|
||||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
mouseDownHandlers.erase(std::remove(mouseDownHandlers.begin(), mouseDownHandlers.end(), id), mouseDownHandlers.end());
|
||||||
CppDOMBindings::mouseDownHandlers->erase(id);
|
CppDOMBindings::mouseDownHandlers->erase(id);
|
||||||
CppDOMBindings::RemoveMouseDownListener(ptr, id);
|
CppDOMBindings::RemoveMouseDownListener(ptr, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::int32_t AddMouseUpListener(std::function<void(void)> callback) {
|
std::int32_t AddMouseUpListener(std::function<void(void)> callback) {
|
||||||
std::int32_t id = CppDOMBindings::mouseUpHandlerMaxId++;
|
std::int32_t id = CppDOMBindings::mouseUpHandlerMaxId++;
|
||||||
handlers.push_back(id);
|
mouseUpHandlers.push_back(id);
|
||||||
CppDOMBindings::mouseUpHandlers->insert({id, callback});
|
CppDOMBindings::mouseUpHandlers->insert({id, callback});
|
||||||
CppDOMBindings::AddMouseUpListener(ptr, id);
|
CppDOMBindings::AddMouseUpListener(ptr, id);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveMouseUpListener(std::int32_t id) {
|
void RemoveMouseUpListener(std::int32_t id) {
|
||||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
mouseUpHandlers.erase(std::remove(mouseUpHandlers.begin(), mouseUpHandlers.end(), id), mouseUpHandlers.end());
|
||||||
CppDOMBindings::mouseUpHandlers->erase(id);
|
CppDOMBindings::mouseUpHandlers->erase(id);
|
||||||
CppDOMBindings::RemoveMouseUpListener(ptr, id);
|
CppDOMBindings::RemoveMouseUpListener(ptr, id);
|
||||||
}
|
}
|
||||||
|
|
@ -128,28 +150,28 @@ namespace Crafter {
|
||||||
// Focus Events
|
// Focus Events
|
||||||
std::int32_t AddFocusListener(std::function<void(void)> callback) {
|
std::int32_t AddFocusListener(std::function<void(void)> callback) {
|
||||||
std::int32_t id = CppDOMBindings::focusHandlerMaxId++;
|
std::int32_t id = CppDOMBindings::focusHandlerMaxId++;
|
||||||
handlers.push_back(id);
|
focusHandlers.push_back(id);
|
||||||
CppDOMBindings::focusHandlers->insert({id, callback});
|
CppDOMBindings::focusHandlers->insert({id, callback});
|
||||||
CppDOMBindings::AddFocusListener(ptr, id);
|
CppDOMBindings::AddFocusListener(ptr, id);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveFocusListener(std::int32_t id) {
|
void RemoveFocusListener(std::int32_t id) {
|
||||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
focusHandlers.erase(std::remove(focusHandlers.begin(), focusHandlers.end(), id), focusHandlers.end());
|
||||||
CppDOMBindings::focusHandlers->erase(id);
|
CppDOMBindings::focusHandlers->erase(id);
|
||||||
CppDOMBindings::RemoveFocusListener(ptr, id);
|
CppDOMBindings::RemoveFocusListener(ptr, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::int32_t AddBlurListener(std::function<void(void)> callback) {
|
std::int32_t AddBlurListener(std::function<void(void)> callback) {
|
||||||
std::int32_t id = CppDOMBindings::blurHandlerMaxId++;
|
std::int32_t id = CppDOMBindings::blurHandlerMaxId++;
|
||||||
handlers.push_back(id);
|
blurHandlers.push_back(id);
|
||||||
CppDOMBindings::blurHandlers->insert({id, callback});
|
CppDOMBindings::blurHandlers->insert({id, callback});
|
||||||
CppDOMBindings::AddBlurListener(ptr, id);
|
CppDOMBindings::AddBlurListener(ptr, id);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveBlurListener(std::int32_t id) {
|
void RemoveBlurListener(std::int32_t id) {
|
||||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
blurHandlers.erase(std::remove(blurHandlers.begin(), blurHandlers.end(), id), blurHandlers.end());
|
||||||
CppDOMBindings::blurHandlers->erase(id);
|
CppDOMBindings::blurHandlers->erase(id);
|
||||||
CppDOMBindings::RemoveBlurListener(ptr, id);
|
CppDOMBindings::RemoveBlurListener(ptr, id);
|
||||||
}
|
}
|
||||||
|
|
@ -157,42 +179,42 @@ namespace Crafter {
|
||||||
// Keyboard Events
|
// Keyboard Events
|
||||||
std::int32_t AddKeyDownListener(std::function<void(KeyboardEvent)> callback) {
|
std::int32_t AddKeyDownListener(std::function<void(KeyboardEvent)> callback) {
|
||||||
std::int32_t id = CppDOMBindings::keyDownHandlerMaxId++;
|
std::int32_t id = CppDOMBindings::keyDownHandlerMaxId++;
|
||||||
handlers.push_back(id);
|
keyDownHandlers.push_back(id);
|
||||||
CppDOMBindings::keyDownHandlers->insert({id, callback});
|
CppDOMBindings::keyDownHandlers->insert({id, callback});
|
||||||
CppDOMBindings::AddKeyDownListener(ptr, id);
|
CppDOMBindings::AddKeyDownListener(ptr, id);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveKeyDownListener(std::int32_t id) {
|
void RemoveKeyDownListener(std::int32_t id) {
|
||||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
keyDownHandlers.erase(std::remove(keyDownHandlers.begin(), keyDownHandlers.end(), id), keyDownHandlers.end());
|
||||||
CppDOMBindings::keyDownHandlers->erase(id);
|
CppDOMBindings::keyDownHandlers->erase(id);
|
||||||
CppDOMBindings::RemoveKeyDownListener(ptr, id);
|
CppDOMBindings::RemoveKeyDownListener(ptr, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::int32_t AddKeyUpListener(std::function<void(KeyboardEvent)> callback) {
|
std::int32_t AddKeyUpListener(std::function<void(KeyboardEvent)> callback) {
|
||||||
std::int32_t id = CppDOMBindings::keyUpHandlerMaxId++;
|
std::int32_t id = CppDOMBindings::keyUpHandlerMaxId++;
|
||||||
handlers.push_back(id);
|
keyUpHandlers.push_back(id);
|
||||||
CppDOMBindings::keyUpHandlers->insert({id, callback});
|
CppDOMBindings::keyUpHandlers->insert({id, callback});
|
||||||
CppDOMBindings::AddKeyUpListener(ptr, id);
|
CppDOMBindings::AddKeyUpListener(ptr, id);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveKeyUpListener(std::int32_t id) {
|
void RemoveKeyUpListener(std::int32_t id) {
|
||||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
keyUpHandlers.erase(std::remove(keyUpHandlers.begin(), keyUpHandlers.end(), id), keyUpHandlers.end());
|
||||||
CppDOMBindings::keyUpHandlers->erase(id);
|
CppDOMBindings::keyUpHandlers->erase(id);
|
||||||
CppDOMBindings::RemoveKeyUpListener(ptr, id);
|
CppDOMBindings::RemoveKeyUpListener(ptr, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::int32_t AddKeyPressListener(std::function<void(KeyboardEvent)> callback) {
|
std::int32_t AddKeyPressListener(std::function<void(KeyboardEvent)> callback) {
|
||||||
std::int32_t id = CppDOMBindings::keyPressHandlerMaxId++;
|
std::int32_t id = CppDOMBindings::keyPressHandlerMaxId++;
|
||||||
handlers.push_back(id);
|
keyPressHandlers.push_back(id);
|
||||||
CppDOMBindings::keyPressHandlers->insert({id, callback});
|
CppDOMBindings::keyPressHandlers->insert({id, callback});
|
||||||
CppDOMBindings::AddKeyPressListener(ptr, id);
|
CppDOMBindings::AddKeyPressListener(ptr, id);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveKeyPressListener(std::int32_t id) {
|
void RemoveKeyPressListener(std::int32_t id) {
|
||||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
keyPressHandlers.erase(std::remove(keyPressHandlers.begin(), keyPressHandlers.end(), id), keyPressHandlers.end());
|
||||||
CppDOMBindings::keyPressHandlers->erase(id);
|
CppDOMBindings::keyPressHandlers->erase(id);
|
||||||
CppDOMBindings::RemoveKeyPressListener(ptr, id);
|
CppDOMBindings::RemoveKeyPressListener(ptr, id);
|
||||||
}
|
}
|
||||||
|
|
@ -200,70 +222,70 @@ namespace Crafter {
|
||||||
// Form Events
|
// Form Events
|
||||||
std::int32_t AddChangeListener(std::function<void(ChangeEvent)> callback) {
|
std::int32_t AddChangeListener(std::function<void(ChangeEvent)> callback) {
|
||||||
std::int32_t id = CppDOMBindings::changeHandlerMaxId++;
|
std::int32_t id = CppDOMBindings::changeHandlerMaxId++;
|
||||||
handlers.push_back(id);
|
changeHandlers.push_back(id);
|
||||||
CppDOMBindings::changeHandlers->insert({id, callback});
|
CppDOMBindings::changeHandlers->insert({id, callback});
|
||||||
CppDOMBindings::AddChangeListener(ptr, id);
|
CppDOMBindings::AddChangeListener(ptr, id);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveChangeListener(std::int32_t id) {
|
void RemoveChangeListener(std::int32_t id) {
|
||||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
changeHandlers.erase(std::remove(changeHandlers.begin(), changeHandlers.end(), id), changeHandlers.end());
|
||||||
CppDOMBindings::changeHandlers->erase(id);
|
CppDOMBindings::changeHandlers->erase(id);
|
||||||
CppDOMBindings::RemoveChangeListener(ptr, id);
|
CppDOMBindings::RemoveChangeListener(ptr, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::int32_t AddSubmitListener(std::function<void(void)> callback) {
|
std::int32_t AddSubmitListener(std::function<void(void)> callback) {
|
||||||
std::int32_t id = CppDOMBindings::submitHandlerMaxId++;
|
std::int32_t id = CppDOMBindings::submitHandlerMaxId++;
|
||||||
handlers.push_back(id);
|
submitHandlers.push_back(id);
|
||||||
CppDOMBindings::submitHandlers->insert({id, callback});
|
CppDOMBindings::submitHandlers->insert({id, callback});
|
||||||
CppDOMBindings::AddSubmitListener(ptr, id);
|
CppDOMBindings::AddSubmitListener(ptr, id);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveSubmitListener(std::int32_t id) {
|
void RemoveSubmitListener(std::int32_t id) {
|
||||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
submitHandlers.erase(std::remove(submitHandlers.begin(), submitHandlers.end(), id), submitHandlers.end());
|
||||||
CppDOMBindings::submitHandlers->erase(id);
|
CppDOMBindings::submitHandlers->erase(id);
|
||||||
CppDOMBindings::RemoveSubmitListener(ptr, id);
|
CppDOMBindings::RemoveSubmitListener(ptr, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::int32_t AddInputListener(std::function<void(InputEvent)> callback) {
|
std::int32_t AddInputListener(std::function<void(InputEvent)> callback) {
|
||||||
std::int32_t id = CppDOMBindings::inputHandlerMaxId++;
|
std::int32_t id = CppDOMBindings::inputHandlerMaxId++;
|
||||||
handlers.push_back(id);
|
inputHandlers.push_back(id);
|
||||||
CppDOMBindings::inputHandlers->insert({id, callback});
|
CppDOMBindings::inputHandlers->insert({id, callback});
|
||||||
CppDOMBindings::AddInputListener(ptr, id);
|
CppDOMBindings::AddInputListener(ptr, id);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveInputListener(std::int32_t id) {
|
void RemoveInputListener(std::int32_t id) {
|
||||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
inputHandlers.erase(std::remove(inputHandlers.begin(), inputHandlers.end(), id), inputHandlers.end());
|
||||||
CppDOMBindings::inputHandlers->erase(id);
|
CppDOMBindings::inputHandlers->erase(id);
|
||||||
CppDOMBindings::RemoveInputListener(ptr, id);
|
CppDOMBindings::RemoveInputListener(ptr, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::int32_t AddResizeListener(std::function<void(ResizeEvent)> callback) {
|
std::int32_t AddResizeListener(std::function<void(ResizeEvent)> callback) {
|
||||||
std::int32_t id = CppDOMBindings::resizeHandlerMaxId++;
|
std::int32_t id = CppDOMBindings::resizeHandlerMaxId++;
|
||||||
handlers.push_back(id);
|
resizeHandlers.push_back(id);
|
||||||
CppDOMBindings::resizeHandlers->insert({id, callback});
|
CppDOMBindings::resizeHandlers->insert({id, callback});
|
||||||
CppDOMBindings::AddResizeListener(ptr, id);
|
CppDOMBindings::AddResizeListener(ptr, id);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveResizeListener(std::int32_t id) {
|
void RemoveResizeListener(std::int32_t id) {
|
||||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
resizeHandlers.erase(std::remove(resizeHandlers.begin(), resizeHandlers.end(), id), resizeHandlers.end());
|
||||||
CppDOMBindings::resizeHandlers->erase(id);
|
CppDOMBindings::resizeHandlers->erase(id);
|
||||||
CppDOMBindings::RemoveResizeListener(ptr, id);
|
CppDOMBindings::RemoveResizeListener(ptr, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::int32_t AddScrollListener(std::function<void(ScrollEvent)> callback) {
|
std::int32_t AddScrollListener(std::function<void(ScrollEvent)> callback) {
|
||||||
std::int32_t id = CppDOMBindings::scrollHandlerMaxId++;
|
std::int32_t id = CppDOMBindings::scrollHandlerMaxId++;
|
||||||
handlers.push_back(id);
|
scrollHandlers.push_back(id);
|
||||||
CppDOMBindings::scrollHandlers->insert({id, callback});
|
CppDOMBindings::scrollHandlers->insert({id, callback});
|
||||||
CppDOMBindings::AddScrollListener(ptr, id);
|
CppDOMBindings::AddScrollListener(ptr, id);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveScrollListener(std::int32_t id) {
|
void RemoveScrollListener(std::int32_t id) {
|
||||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
scrollHandlers.erase(std::remove(scrollHandlers.begin(), scrollHandlers.end(), id), scrollHandlers.end());
|
||||||
CppDOMBindings::scrollHandlers->erase(id);
|
CppDOMBindings::scrollHandlers->erase(id);
|
||||||
CppDOMBindings::RemoveScrollListener(ptr, id);
|
CppDOMBindings::RemoveScrollListener(ptr, id);
|
||||||
}
|
}
|
||||||
|
|
@ -271,14 +293,14 @@ namespace Crafter {
|
||||||
// Context Menu Events
|
// Context Menu Events
|
||||||
std::int32_t AddContextMenuListener(std::function<void(MouseEvent)> callback) {
|
std::int32_t AddContextMenuListener(std::function<void(MouseEvent)> callback) {
|
||||||
std::int32_t id = CppDOMBindings::contextMenuHandlerMaxId++;
|
std::int32_t id = CppDOMBindings::contextMenuHandlerMaxId++;
|
||||||
handlers.push_back(id);
|
contextMenuHandlers.push_back(id);
|
||||||
CppDOMBindings::contextMenuHandlers->insert({id, callback});
|
CppDOMBindings::contextMenuHandlers->insert({id, callback});
|
||||||
CppDOMBindings::AddContextMenuListener(ptr, id);
|
CppDOMBindings::AddContextMenuListener(ptr, id);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveContextMenuListener(std::int32_t id) {
|
void RemoveContextMenuListener(std::int32_t id) {
|
||||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
contextMenuHandlers.erase(std::remove(contextMenuHandlers.begin(), contextMenuHandlers.end(), id), contextMenuHandlers.end());
|
||||||
CppDOMBindings::contextMenuHandlers->erase(id);
|
CppDOMBindings::contextMenuHandlers->erase(id);
|
||||||
CppDOMBindings::RemoveContextMenuListener(ptr, id);
|
CppDOMBindings::RemoveContextMenuListener(ptr, id);
|
||||||
}
|
}
|
||||||
|
|
@ -286,42 +308,42 @@ namespace Crafter {
|
||||||
// Drag and Drop Events
|
// Drag and Drop Events
|
||||||
std::int32_t AddDragStartListener(std::function<void(MouseEvent)> callback) {
|
std::int32_t AddDragStartListener(std::function<void(MouseEvent)> callback) {
|
||||||
std::int32_t id = CppDOMBindings::dragStartHandlerMaxId++;
|
std::int32_t id = CppDOMBindings::dragStartHandlerMaxId++;
|
||||||
handlers.push_back(id);
|
dragStartHandlers.push_back(id);
|
||||||
CppDOMBindings::dragStartHandlers->insert({id, callback});
|
CppDOMBindings::dragStartHandlers->insert({id, callback});
|
||||||
CppDOMBindings::AddDragStartListener(ptr, id);
|
CppDOMBindings::AddDragStartListener(ptr, id);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveDragStartListener(std::int32_t id) {
|
void RemoveDragStartListener(std::int32_t id) {
|
||||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
dragStartHandlers.erase(std::remove(dragStartHandlers.begin(), dragStartHandlers.end(), id), dragStartHandlers.end());
|
||||||
CppDOMBindings::dragStartHandlers->erase(id);
|
CppDOMBindings::dragStartHandlers->erase(id);
|
||||||
CppDOMBindings::RemoveDragStartListener(ptr, id);
|
CppDOMBindings::RemoveDragStartListener(ptr, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::int32_t AddDragEndListener(std::function<void(MouseEvent)> callback) {
|
std::int32_t AddDragEndListener(std::function<void(MouseEvent)> callback) {
|
||||||
std::int32_t id = CppDOMBindings::dragEndHandlerMaxId++;
|
std::int32_t id = CppDOMBindings::dragEndHandlerMaxId++;
|
||||||
handlers.push_back(id);
|
dragEndHandlers.push_back(id);
|
||||||
CppDOMBindings::dragEndHandlers->insert({id, callback});
|
CppDOMBindings::dragEndHandlers->insert({id, callback});
|
||||||
CppDOMBindings::AddDragEndListener(ptr, id);
|
CppDOMBindings::AddDragEndListener(ptr, id);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveDragEndListener(std::int32_t id) {
|
void RemoveDragEndListener(std::int32_t id) {
|
||||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
dragEndHandlers.erase(std::remove(dragEndHandlers.begin(), dragEndHandlers.end(), id), dragEndHandlers.end());
|
||||||
CppDOMBindings::dragEndHandlers->erase(id);
|
CppDOMBindings::dragEndHandlers->erase(id);
|
||||||
CppDOMBindings::RemoveDragEndListener(ptr, id);
|
CppDOMBindings::RemoveDragEndListener(ptr, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::int32_t AddDropListener(std::function<void(MouseEvent)> callback) {
|
std::int32_t AddDropListener(std::function<void(MouseEvent)> callback) {
|
||||||
std::int32_t id = CppDOMBindings::dropHandlerMaxId++;
|
std::int32_t id = CppDOMBindings::dropHandlerMaxId++;
|
||||||
handlers.push_back(id);
|
dropHandlers.push_back(id);
|
||||||
CppDOMBindings::dropHandlers->insert({id, callback});
|
CppDOMBindings::dropHandlers->insert({id, callback});
|
||||||
CppDOMBindings::AddDropListener(ptr, id);
|
CppDOMBindings::AddDropListener(ptr, id);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveDropListener(std::int32_t id) {
|
void RemoveDropListener(std::int32_t id) {
|
||||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
dropHandlers.erase(std::remove(dropHandlers.begin(), dropHandlers.end(), id), dropHandlers.end());
|
||||||
CppDOMBindings::dropHandlers->erase(id);
|
CppDOMBindings::dropHandlers->erase(id);
|
||||||
CppDOMBindings::RemoveDropListener(ptr, id);
|
CppDOMBindings::RemoveDropListener(ptr, id);
|
||||||
}
|
}
|
||||||
|
|
@ -329,42 +351,42 @@ namespace Crafter {
|
||||||
// Additional Drag Events
|
// Additional Drag Events
|
||||||
std::int32_t AddDragOverListener(std::function<void(MouseEvent)> callback) {
|
std::int32_t AddDragOverListener(std::function<void(MouseEvent)> callback) {
|
||||||
std::int32_t id = CppDOMBindings::dragOverHandlerMaxId++;
|
std::int32_t id = CppDOMBindings::dragOverHandlerMaxId++;
|
||||||
handlers.push_back(id);
|
dragOverHandlers.push_back(id);
|
||||||
CppDOMBindings::dragOverHandlers->insert({id, callback});
|
CppDOMBindings::dragOverHandlers->insert({id, callback});
|
||||||
CppDOMBindings::AddDragOverListener(ptr, id);
|
CppDOMBindings::AddDragOverListener(ptr, id);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveDragOverListener(std::int32_t id) {
|
void RemoveDragOverListener(std::int32_t id) {
|
||||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
dragOverHandlers.erase(std::remove(dragOverHandlers.begin(), dragOverHandlers.end(), id), dragOverHandlers.end());
|
||||||
CppDOMBindings::dragOverHandlers->erase(id);
|
CppDOMBindings::dragOverHandlers->erase(id);
|
||||||
CppDOMBindings::RemoveDragOverListener(ptr, id);
|
CppDOMBindings::RemoveDragOverListener(ptr, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::int32_t AddDragEnterListener(std::function<void(MouseEvent)> callback) {
|
std::int32_t AddDragEnterListener(std::function<void(MouseEvent)> callback) {
|
||||||
std::int32_t id = CppDOMBindings::dragEnterHandlerMaxId++;
|
std::int32_t id = CppDOMBindings::dragEnterHandlerMaxId++;
|
||||||
handlers.push_back(id);
|
dragEnterHandlers.push_back(id);
|
||||||
CppDOMBindings::dragEnterHandlers->insert({id, callback});
|
CppDOMBindings::dragEnterHandlers->insert({id, callback});
|
||||||
CppDOMBindings::AddDragEnterListener(ptr, id);
|
CppDOMBindings::AddDragEnterListener(ptr, id);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveDragEnterListener(std::int32_t id) {
|
void RemoveDragEnterListener(std::int32_t id) {
|
||||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
dragEnterHandlers.erase(std::remove(dragEnterHandlers.begin(), dragEnterHandlers.end(), id), dragEnterHandlers.end());
|
||||||
CppDOMBindings::dragEnterHandlers->erase(id);
|
CppDOMBindings::dragEnterHandlers->erase(id);
|
||||||
CppDOMBindings::RemoveDragEnterListener(ptr, id);
|
CppDOMBindings::RemoveDragEnterListener(ptr, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::int32_t AddDragLeaveListener(std::function<void(MouseEvent)> callback) {
|
std::int32_t AddDragLeaveListener(std::function<void(MouseEvent)> callback) {
|
||||||
std::int32_t id = CppDOMBindings::dragLeaveHandlerMaxId++;
|
std::int32_t id = CppDOMBindings::dragLeaveHandlerMaxId++;
|
||||||
handlers.push_back(id);
|
dragLeaveHandlers.push_back(id);
|
||||||
CppDOMBindings::dragLeaveHandlers->insert({id, callback});
|
CppDOMBindings::dragLeaveHandlers->insert({id, callback});
|
||||||
CppDOMBindings::AddDragLeaveListener(ptr, id);
|
CppDOMBindings::AddDragLeaveListener(ptr, id);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveDragLeaveListener(std::int32_t id) {
|
void RemoveDragLeaveListener(std::int32_t id) {
|
||||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
dragLeaveHandlers.erase(std::remove(dragLeaveHandlers.begin(), dragLeaveHandlers.end(), id), dragLeaveHandlers.end());
|
||||||
CppDOMBindings::dragLeaveHandlers->erase(id);
|
CppDOMBindings::dragLeaveHandlers->erase(id);
|
||||||
CppDOMBindings::RemoveDragLeaveListener(ptr, id);
|
CppDOMBindings::RemoveDragLeaveListener(ptr, id);
|
||||||
}
|
}
|
||||||
|
|
@ -372,23 +394,116 @@ namespace Crafter {
|
||||||
// Wheel Event
|
// Wheel Event
|
||||||
std::int32_t AddWheelListener(std::function<void(WheelEvent)> callback) {
|
std::int32_t AddWheelListener(std::function<void(WheelEvent)> callback) {
|
||||||
std::int32_t id = CppDOMBindings::wheelHandlerMaxId++;
|
std::int32_t id = CppDOMBindings::wheelHandlerMaxId++;
|
||||||
handlers.push_back(id);
|
wheelHandlers.push_back(id);
|
||||||
CppDOMBindings::wheelHandlers->insert({id, callback});
|
CppDOMBindings::wheelHandlers->insert({id, callback});
|
||||||
CppDOMBindings::AddWheelListener(ptr, id);
|
CppDOMBindings::AddWheelListener(ptr, id);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveWheelListener(std::int32_t id) {
|
void RemoveWheelListener(std::int32_t id) {
|
||||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
wheelHandlers.erase(std::remove(wheelHandlers.begin(), wheelHandlers.end(), id), wheelHandlers.end());
|
||||||
CppDOMBindings::wheelHandlers->erase(id);
|
CppDOMBindings::wheelHandlers->erase(id);
|
||||||
CppDOMBindings::RemoveWheelListener(ptr, id);
|
CppDOMBindings::RemoveWheelListener(ptr, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
~HtmlElement(){
|
~HtmlElement(){
|
||||||
for(std::int32_t handler : handlers) {
|
// Clean up all handlers by type
|
||||||
|
for(std::int32_t handler : clickHandlers) {
|
||||||
CppDOMBindings::clickHandlers->erase(handler);
|
CppDOMBindings::clickHandlers->erase(handler);
|
||||||
CppDOMBindings::RemoveClickListener(ptr, handler);
|
CppDOMBindings::RemoveClickListener(ptr, handler);
|
||||||
}
|
}
|
||||||
|
for(std::int32_t handler : mouseOverHandlers) {
|
||||||
|
CppDOMBindings::mouseOverHandlers->erase(handler);
|
||||||
|
CppDOMBindings::RemoveMouseOverListener(ptr, handler);
|
||||||
|
}
|
||||||
|
for(std::int32_t handler : mouseOutHandlers) {
|
||||||
|
CppDOMBindings::mouseOutHandlers->erase(handler);
|
||||||
|
CppDOMBindings::RemoveMouseOutListener(ptr, handler);
|
||||||
|
}
|
||||||
|
for(std::int32_t handler : mouseMoveHandlers) {
|
||||||
|
CppDOMBindings::mouseMoveHandlers->erase(handler);
|
||||||
|
CppDOMBindings::RemoveMouseMoveListener(ptr, handler);
|
||||||
|
}
|
||||||
|
for(std::int32_t handler : mouseDownHandlers) {
|
||||||
|
CppDOMBindings::mouseDownHandlers->erase(handler);
|
||||||
|
CppDOMBindings::RemoveMouseDownListener(ptr, handler);
|
||||||
|
}
|
||||||
|
for(std::int32_t handler : mouseUpHandlers) {
|
||||||
|
CppDOMBindings::mouseUpHandlers->erase(handler);
|
||||||
|
CppDOMBindings::RemoveMouseUpListener(ptr, handler);
|
||||||
|
}
|
||||||
|
for(std::int32_t handler : focusHandlers) {
|
||||||
|
CppDOMBindings::focusHandlers->erase(handler);
|
||||||
|
CppDOMBindings::RemoveFocusListener(ptr, handler);
|
||||||
|
}
|
||||||
|
for(std::int32_t handler : blurHandlers) {
|
||||||
|
CppDOMBindings::blurHandlers->erase(handler);
|
||||||
|
CppDOMBindings::RemoveBlurListener(ptr, handler);
|
||||||
|
}
|
||||||
|
for(std::int32_t handler : keyDownHandlers) {
|
||||||
|
CppDOMBindings::keyDownHandlers->erase(handler);
|
||||||
|
CppDOMBindings::RemoveKeyDownListener(ptr, handler);
|
||||||
|
}
|
||||||
|
for(std::int32_t handler : keyUpHandlers) {
|
||||||
|
CppDOMBindings::keyUpHandlers->erase(handler);
|
||||||
|
CppDOMBindings::RemoveKeyUpListener(ptr, handler);
|
||||||
|
}
|
||||||
|
for(std::int32_t handler : keyPressHandlers) {
|
||||||
|
CppDOMBindings::keyPressHandlers->erase(handler);
|
||||||
|
CppDOMBindings::RemoveKeyPressListener(ptr, handler);
|
||||||
|
}
|
||||||
|
for(std::int32_t handler : changeHandlers) {
|
||||||
|
CppDOMBindings::changeHandlers->erase(handler);
|
||||||
|
CppDOMBindings::RemoveChangeListener(ptr, handler);
|
||||||
|
}
|
||||||
|
for(std::int32_t handler : submitHandlers) {
|
||||||
|
CppDOMBindings::submitHandlers->erase(handler);
|
||||||
|
CppDOMBindings::RemoveSubmitListener(ptr, handler);
|
||||||
|
}
|
||||||
|
for(std::int32_t handler : inputHandlers) {
|
||||||
|
CppDOMBindings::inputHandlers->erase(handler);
|
||||||
|
CppDOMBindings::RemoveInputListener(ptr, handler);
|
||||||
|
}
|
||||||
|
for(std::int32_t handler : resizeHandlers) {
|
||||||
|
CppDOMBindings::resizeHandlers->erase(handler);
|
||||||
|
CppDOMBindings::RemoveResizeListener(ptr, handler);
|
||||||
|
}
|
||||||
|
for(std::int32_t handler : scrollHandlers) {
|
||||||
|
CppDOMBindings::scrollHandlers->erase(handler);
|
||||||
|
CppDOMBindings::RemoveScrollListener(ptr, handler);
|
||||||
|
}
|
||||||
|
for(std::int32_t handler : contextMenuHandlers) {
|
||||||
|
CppDOMBindings::contextMenuHandlers->erase(handler);
|
||||||
|
CppDOMBindings::RemoveContextMenuListener(ptr, handler);
|
||||||
|
}
|
||||||
|
for(std::int32_t handler : dragStartHandlers) {
|
||||||
|
CppDOMBindings::dragStartHandlers->erase(handler);
|
||||||
|
CppDOMBindings::RemoveDragStartListener(ptr, handler);
|
||||||
|
}
|
||||||
|
for(std::int32_t handler : dragEndHandlers) {
|
||||||
|
CppDOMBindings::dragEndHandlers->erase(handler);
|
||||||
|
CppDOMBindings::RemoveDragEndListener(ptr, handler);
|
||||||
|
}
|
||||||
|
for(std::int32_t handler : dropHandlers) {
|
||||||
|
CppDOMBindings::dropHandlers->erase(handler);
|
||||||
|
CppDOMBindings::RemoveDropListener(ptr, handler);
|
||||||
|
}
|
||||||
|
for(std::int32_t handler : dragOverHandlers) {
|
||||||
|
CppDOMBindings::dragOverHandlers->erase(handler);
|
||||||
|
CppDOMBindings::RemoveDragOverListener(ptr, handler);
|
||||||
|
}
|
||||||
|
for(std::int32_t handler : dragEnterHandlers) {
|
||||||
|
CppDOMBindings::dragEnterHandlers->erase(handler);
|
||||||
|
CppDOMBindings::RemoveDragEnterListener(ptr, handler);
|
||||||
|
}
|
||||||
|
for(std::int32_t handler : dragLeaveHandlers) {
|
||||||
|
CppDOMBindings::dragLeaveHandlers->erase(handler);
|
||||||
|
CppDOMBindings::RemoveDragLeaveListener(ptr, handler);
|
||||||
|
}
|
||||||
|
for(std::int32_t handler : wheelHandlers) {
|
||||||
|
CppDOMBindings::wheelHandlers->erase(handler);
|
||||||
|
CppDOMBindings::RemoveWheelListener(ptr, handler);
|
||||||
|
}
|
||||||
CppDOMBindings::FreeJs(ptr);
|
CppDOMBindings::FreeJs(ptr);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export module Crafter.CppDOM;
|
export module Crafter.CppDOM;
|
||||||
export import :Bindings;
|
|
||||||
export import :HtmlElement;
|
export import :HtmlElement;
|
||||||
export import :EventTypes;
|
export import :EventTypes;
|
||||||
|
export import :BindingsExport;
|
||||||
|
export import :BindingsImport;
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "lib",
|
"name": "lib",
|
||||||
"interfaces": ["interfaces/Crafter.CppDOM-HtmlElement", "interfaces/Crafter.CppDOM", "interfaces/Crafter.CppDOM-Bindings", "interfaces/Crafter.CppDOM-EventTypes"],
|
"interfaces": ["interfaces/Crafter.CppDOM-HtmlElement", "interfaces/Crafter.CppDOM", "interfaces/Crafter.CppDOM-BindingsExport", "interfaces/Crafter.CppDOM-BindingsImport", "interfaces/Crafter.CppDOM-EventTypes"],
|
||||||
"additional_files": ["additional/env.js"],
|
"additional_files": ["additional/env.js"],
|
||||||
"type":"library",
|
"type":"library",
|
||||||
"target":"wasm32-wasi"
|
"target":"wasm32-wasi"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue