Used __builtin_wasm_memory_size(0) instead of having the Javascript code call init_mem with the initial page count. Added a simple <div> below the canvas that can hold any number of labels that can be filled/updated through jsSetLabel which lives in a new file misc_functions.js.
This commit is contained in:
40
data/misc_functions.js
Normal file
40
data/misc_functions.js
Normal file
@@ -0,0 +1,40 @@
|
||||
|
||||
import { appGlobals } from './globals.js'
|
||||
import { wasmPntrToJsString, wasmPntrAndLengthToJsString } from './wasm_functions.js'
|
||||
|
||||
export function jsSetLabel(labelIdStrPntr, labelStrPntr)
|
||||
{
|
||||
let labelIdStr = wasmPntrToJsString(labelIdStrPntr);
|
||||
let labelStr = wasmPntrToJsString(labelStrPntr);
|
||||
var labelContainer = document.getElementById("label_container");
|
||||
if (labelContainer != null)
|
||||
{
|
||||
var foundExistingLabel = false;
|
||||
var existingLabels = labelContainer.getElementsByClassName("wasm_label");
|
||||
if (existingLabels != null)
|
||||
{
|
||||
for (var lIndex = 0; lIndex < existingLabels.length; lIndex++)
|
||||
{
|
||||
if (existingLabels[lIndex].id == labelIdStr)
|
||||
{
|
||||
existingLabels[lIndex].textContent = labelStr;
|
||||
foundExistingLabel = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!foundExistingLabel)
|
||||
{
|
||||
const newLabel = document.createElement("p");
|
||||
newLabel.className = "wasm_label";
|
||||
newLabel.id = labelIdStr;
|
||||
newLabel.textContent = labelStr;
|
||||
labelContainer.appendChild(newLabel);
|
||||
}
|
||||
}
|
||||
else { console.error("Failed to file container with id \"label_container\"!"); }
|
||||
}
|
||||
|
||||
export let jsMiscFunctions = {
|
||||
jsSetLabel: jsSetLabel,
|
||||
};
|
||||
Reference in New Issue
Block a user