Emscripten: text input with HTML <input> element

This commit is contained in:
Sergii Pylypenko
2021-06-24 01:00:17 +03:00
parent 4eed59213e
commit 8ffb519ec6
2 changed files with 70 additions and 2 deletions

View File

@@ -81,6 +81,13 @@
padding: 4px 4px;
}
div.textinput {
position: absolute;
width: 100%;
z-index: 4;
display: "none";
}
canvas.emscripten {
border: 0px none;
height: 100%;
@@ -108,6 +115,10 @@
Warning: savegames are stored in the Indexed DB of your browser.<br/>Your browser can delete savegames without notice!
</div>
</div>
<div class="textinput" id="textinput">
<input type="textinput" id="textinputbox" value=""></input>
<input type="submit" value="OK" onclick="Module.finishTextInput();" ></input>
</div>
<div>
<canvas class="emscripten" id="canvas" oncontextmenu="event.preventDefault()" tabindex=-1></canvas>
</div>
@@ -200,7 +211,34 @@
document.getElementById("filesystem").style.display = "none";
}, 300);
}, 10000);
}
},
textInputValue: null,
startTextInput: function(text) {
Module.print("Start text input!");
Module.textInputValue = null;
document.getElementById("textinput").style.display = "block";
document.getElementById("textinputbox").value = text;
document.getElementById("textinputbox").focus();
},
getTextInput: function() {
if (Module.textInputValue !== null) {
var value = Module.textInputValue;
Module.textInputValue = null;
return value;
}
return null;
},
finishTextInput: function() {
Module.print("Text input finished!");
Module.textInputValue = document.getElementById("textinputbox").value;
Module.print(Module.textInputValue);
document.getElementById("textinput").style.display = "none";
},
};
window.onerror = function() {