This commit is contained in:
Jorijn van der Graaf 2025-11-10 22:06:27 +01:00
commit 224dc563e9
9 changed files with 200 additions and 46 deletions

View file

@ -200,4 +200,30 @@ 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("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;
}
}

View file

@ -105,4 +105,35 @@ export namespace Crafter::CppDOMBindings {
__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);
// Style functions
__attribute__((import_module("env"), import_name("setStyle"))) void SetStyle(void* ptr, const char* style, std::size_t styleLength);
void SetStyle(void* ptr, const std::string_view style) {
SetStyle(ptr, style.data(), style.size());
}
__attribute__((import_module("env"), import_name("setProperty"))) void SetProperty(void* ptr, const char* property, std::size_t propertyLength, const char* value, std::size_t valueLength);
void SetProperty(void* ptr, const std::string_view property, const std::string_view value) {
SetProperty(ptr, property.data(), property.size(), value.data(), value.size());
}
__attribute__((import_module("env"), import_name("addClass"))) void AddClass(void* ptr, const char* className, std::size_t classNameLength);
void AddClass(void* ptr, const std::string_view className) {
AddClass(ptr, className.data(), className.size());
}
__attribute__((import_module("env"), import_name("removeClass"))) void RemoveClass(void* ptr, const char* className, std::size_t classNameLength);
void RemoveClass(void* ptr, const std::string_view className) {
RemoveClass(ptr, className.data(), className.size());
}
__attribute__((import_module("env"), import_name("toggleClass"))) void ToggleClass(void* ptr, const char* className, std::size_t classNameLength);
void ToggleClass(void* ptr, const std::string_view className) {
ToggleClass(ptr, className.data(), className.size());
}
__attribute__((import_module("env"), import_name("hasClass"))) bool HasClass(void* ptr, const char* className, std::size_t classNameLength);
bool HasClass(void* ptr, const std::string_view className) {
return HasClass(ptr, className.data(), className.size());
}
}

View file

@ -56,6 +56,12 @@ namespace Crafter {
HtmlElement(const std::string_view id);
HtmlElement(const std::string_view id, const std::string_view html);
void SetInnerHTML(const std::string_view html);
void SetStyle(const std::string_view style);
void SetProperty(const std::string_view property, const std::string_view value);
void AddClass(const std::string_view className);
void RemoveClass(const std::string_view className);
void ToggleClass(const std::string_view className);
bool HasClass(const std::string_view className);
std::int32_t AddClickListener(std::function<void(Crafter::MouseEvent)> callback);
void RemoveClickListener(std::int32_t id);