click event
This commit is contained in:
parent
e35b7302cb
commit
f40afe684a
13 changed files with 151 additions and 20 deletions
|
|
@ -22,24 +22,42 @@ export module Crafter.CppDOM:HtmlElement;
|
|||
import std;
|
||||
import :Bindings;
|
||||
|
||||
namespace Crafter::CppDOM {
|
||||
namespace Crafter {
|
||||
export class HtmlElement {
|
||||
public:
|
||||
void* const ptr;
|
||||
inline HtmlElement(const char* id, std::size_t idLenght): ptr(Bindings::GetElementById(id, idLenght)) {
|
||||
std::vector<int> handlers;
|
||||
HtmlElement(const std::string_view id): ptr(CppDOM::Bindings::GetElementById(id)) {
|
||||
|
||||
}
|
||||
inline HtmlElement(const std::string& id): ptr(Bindings::GetElementById(id)) {
|
||||
|
||||
HtmlElement(const std::string_view id, const std::string_view html): ptr(CppDOM::Bindings::GetElementById(id)) {
|
||||
CppDOM::Bindings::SetInnerHTML(ptr, html);
|
||||
}
|
||||
inline void SetInnerHTML(const char* html, std::size_t htmlLenght) {
|
||||
Bindings::SetInnerHTML(ptr, html, htmlLenght);
|
||||
void SetInnerHTML(const std::string_view& html) {
|
||||
CppDOM::Bindings::SetInnerHTML(ptr, html);
|
||||
}
|
||||
inline void SetInnerHTML(const std::string& html) {
|
||||
Bindings::SetInnerHTML(ptr, html);
|
||||
|
||||
// Event handling methods - simplified for now
|
||||
int AddClickListener(std::function<void(void)> callback) {
|
||||
int id = CppDOM::Bindings::clickHandlerMaxId++;
|
||||
handlers.push_back(id);
|
||||
CppDOM::Bindings::clickHandlers->insert({id, callback});
|
||||
CppDOM::Bindings::AddClickListener(ptr, id);
|
||||
return id;
|
||||
}
|
||||
inline ~HtmlElement(){
|
||||
Bindings::FreeJs(ptr);
|
||||
|
||||
void RemoveClickListener(int id) {
|
||||
handlers.erase(std::remove(handlers.begin(), handlers.end(), id), handlers.end());
|
||||
CppDOM::Bindings::clickHandlers->erase(id);
|
||||
CppDOM::Bindings::RemoveClickListener(ptr, id);
|
||||
}
|
||||
|
||||
~HtmlElement(){
|
||||
for(int handler : handlers) {
|
||||
CppDOM::Bindings::clickHandlers->erase(handler);
|
||||
CppDOM::Bindings::RemoveClickListener(ptr, handler);
|
||||
}
|
||||
CppDOM::Bindings::FreeJs(ptr);
|
||||
}
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue