Usually, the canvas is full screen, keeping this on every resize in JS.
150
151
152
153
154
155
158
159
252
let resize = function ()
{
if (!canvas || !gl) return;
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
gl.viewport(0, 0, canvas.width, canvas.height);
};
window.addEventListener("resize", function() { resize(); draw(); });
The canvas is
position: absolute
placed, and so is the menu over it.
Pressing M key shows or hides the menu. This is a problem for inputs on the menu
accepting the M character. Ctrl+M is the mute shortcut for browsers, so I didn't use it.
Instead, in the keypress handler function, I checked if any textareas has the focus,
the handler exits without doing anything.
TextAreas are usually for code, and pressing the Tab key in browsers just transfers focus.
To prevent this, there is no magic switch, I had to hardcode Tab key handling.
627
628
629
630
631
632
633
634
635
636
637
638
639
640
let handletab = function (ta_dom)
{
ta_dom.addEventListener('keydown', (e) => {
if (e.key === 'Tab')
{
e.preventDefault();
let str = ta_dom.value;
let start = ta_dom.selectionStart;
let end = ta_dom.selectionEnd;
ta_dom.value = str.substring(0, start) + " " + str.substring(end);
ta_dom.selectionEnd = end-(end-start)+4;
}
});
};
Inputs either have immediate effect when the onchange fires, but sometimes,
usually on bigger computation need, several inputs have a "SET" button. It is a bit
confusing, I plan to indicate this somehow.
Input variables, and their DOM variables are usually in the global scope. There is an exception,
in the
Grid program. There were
so many variables, I created a class for them, in
grid-ui.js.