value
This commit is contained in:
parent
e9afde5216
commit
b96faacf89
4 changed files with 39 additions and 0 deletions
|
|
@ -630,6 +630,19 @@ let env = {
|
|||
element.parentNode.removeChild(element);
|
||||
}
|
||||
},
|
||||
getValue: function(ptr) {
|
||||
const element = jsmemory.get(ptr);
|
||||
if(element.value) {
|
||||
return writeStringToWasm(element.value || "");
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
},
|
||||
setValue: function(ptr, value, valueLength) {
|
||||
const element = jsmemory.get(ptr);
|
||||
const val = decoder.decode(new Int8Array(window.crafter_webbuild_wasi.instance.exports.memory.buffer, value, valueLength));
|
||||
element.value = val;
|
||||
},
|
||||
addClickListener: addClickListener,
|
||||
removeClickListener: removeClickListener,
|
||||
addMouseOverListener: addMouseOverListener,
|
||||
|
|
|
|||
|
|
@ -62,6 +62,21 @@ namespace Crafter {
|
|||
return CppDOMBindings::HasClass(ptr, className);
|
||||
}
|
||||
|
||||
std::string HtmlElementView::GetValue() {
|
||||
const char* value = CppDOMBindings::GetValue(ptr);
|
||||
if(value != nullptr) {
|
||||
std::string result(value);
|
||||
std::free(value);
|
||||
return result;
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
void HtmlElementView::SetValue(const std::string_view value) {
|
||||
CppDOMBindings::SetValue(ptr, value);
|
||||
}
|
||||
|
||||
std::int32_t HtmlElementView::AddClickListener(std::function<void(Crafter::MouseEvent)> callback) {
|
||||
std::int32_t id = CppDOMBindings::clickHandlerMaxId++;
|
||||
clickHandlers.push_back(id);
|
||||
|
|
|
|||
|
|
@ -138,4 +138,11 @@ export namespace Crafter::CppDOMBindings {
|
|||
}
|
||||
|
||||
__attribute__((import_module("env"), import_name("deleteElement"))) void DeleteElement(void* ptr);
|
||||
|
||||
// Value property functions
|
||||
__attribute__((import_module("env"), import_name("getValue"))) const char* GetValue(void* ptr);
|
||||
__attribute__((import_module("env"), import_name("setValue"))) void SetValue(void* ptr, const char* value, std::int32_t valueLength);
|
||||
void SetValue(void* ptr, const std::string_view value) {
|
||||
SetValue(ptr, value.data(), value.size());
|
||||
}
|
||||
}
|
||||
|
|
@ -63,6 +63,10 @@ namespace Crafter {
|
|||
void ToggleClass(const std::string_view className);
|
||||
bool HasClass(const std::string_view className);
|
||||
|
||||
// Value property accessors
|
||||
std::string GetValue();
|
||||
void SetValue(const std::string_view value);
|
||||
|
||||
std::int32_t AddClickListener(std::function<void(Crafter::MouseEvent)> callback);
|
||||
void RemoveClickListener(std::int32_t id);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue