expand input field relative to drawable canvas
Signed-off-by: Victor Seiji Hariki <victorseijih@gmail.com>
This commit is contained in:
parent
458df53fac
commit
c2e0cf4615
3 changed files with 35 additions and 7 deletions
|
@ -63,8 +63,8 @@ mouse.registerContext(
|
||||||
ctx.coords.prev.y = ctx.coords.pos.y;
|
ctx.coords.prev.y = ctx.coords.pos.y;
|
||||||
|
|
||||||
if (evn.layerX !== evn.clientX || evn.layerY !== evn.clientY) {
|
if (evn.layerX !== evn.clientX || evn.layerY !== evn.clientY) {
|
||||||
ctx.coords.pos.x = evn.layerX;
|
ctx.coords.pos.x = Math.round(evn.layerX + imageCollection.inputOffset.x);
|
||||||
ctx.coords.pos.y = evn.layerY;
|
ctx.coords.pos.y = Math.round(evn.layerY + imageCollection.inputOffset.y);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,9 @@ const layers = {
|
||||||
options: {},
|
options: {},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Input multiplier (Size of the input element div)
|
||||||
|
inputSizeMultiplier: 999,
|
||||||
|
|
||||||
// Target
|
// Target
|
||||||
targetElement: document.getElementById("layer-render"),
|
targetElement: document.getElementById("layer-render"),
|
||||||
|
|
||||||
|
@ -35,6 +38,8 @@ const layers = {
|
||||||
resolution: size,
|
resolution: size,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (options.inputSizeMultiplier % 2 === 0) options.inputSizeMultiplier++;
|
||||||
|
|
||||||
// Path used for logging purposes
|
// Path used for logging purposes
|
||||||
const _logpath = "layers.collections." + key;
|
const _logpath = "layers.collections." + key;
|
||||||
|
|
||||||
|
@ -51,8 +56,6 @@ const layers = {
|
||||||
// Input element (overlay element for input handling)
|
// Input element (overlay element for input handling)
|
||||||
const inputel = document.createElement("div");
|
const inputel = document.createElement("div");
|
||||||
inputel.id = `collection-input-${id}`;
|
inputel.id = `collection-input-${id}`;
|
||||||
inputel.style.width = `${size.w}px`;
|
|
||||||
inputel.style.height = `${size.h}px`;
|
|
||||||
inputel.addEventListener("mouseover", (evn) => {
|
inputel.addEventListener("mouseover", (evn) => {
|
||||||
document.activeElement.blur();
|
document.activeElement.blur();
|
||||||
});
|
});
|
||||||
|
@ -73,6 +76,28 @@ const layers = {
|
||||||
name: options.name,
|
name: options.name,
|
||||||
element,
|
element,
|
||||||
inputElement: inputel,
|
inputElement: inputel,
|
||||||
|
_inputOffset: null,
|
||||||
|
get inputOffset() {
|
||||||
|
return this._inputOffset;
|
||||||
|
},
|
||||||
|
|
||||||
|
_resizeInputDiv() {
|
||||||
|
// Set offset
|
||||||
|
this._inputOffset = {
|
||||||
|
x: -Math.floor(options.inputSizeMultiplier / 2) * size.w,
|
||||||
|
y: -Math.floor(options.inputSizeMultiplier / 2) * size.h,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Resize the input element
|
||||||
|
this.inputElement.style.left = `${this.inputOffset.x}px`;
|
||||||
|
this.inputElement.style.top = `${this.inputOffset.y}px`;
|
||||||
|
this.inputElement.style.width = `${
|
||||||
|
size.w * options.inputSizeMultiplier
|
||||||
|
}px`;
|
||||||
|
this.inputElement.style.height = `${
|
||||||
|
size.h * options.inputSizeMultiplier
|
||||||
|
}px`;
|
||||||
|
},
|
||||||
|
|
||||||
size,
|
size,
|
||||||
resolution: options.resolution,
|
resolution: options.resolution,
|
||||||
|
@ -278,9 +303,12 @@ const layers = {
|
||||||
else console.debug(`[layers] Anonymous layer '${lobj.id}' deleted`);
|
else console.debug(`[layers] Anonymous layer '${lobj.id}' deleted`);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
_logpath
|
_logpath,
|
||||||
|
["_inputOffset"]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
collection._resizeInputDiv();
|
||||||
|
|
||||||
layers._collections.push(collection);
|
layers._collections.push(collection);
|
||||||
layers.collections[key] = collection;
|
layers.collections[key] = collection;
|
||||||
|
|
||||||
|
|
|
@ -135,8 +135,8 @@ const _generate = async (
|
||||||
const makeElement = (type, x, y) => {
|
const makeElement = (type, x, y) => {
|
||||||
const el = document.createElement(type);
|
const el = document.createElement(type);
|
||||||
el.style.position = "absolute";
|
el.style.position = "absolute";
|
||||||
el.style.left = `${x}px`;
|
el.style.left = `${x - imageCollection.inputOffset.x}px`;
|
||||||
el.style.top = `${y}px`;
|
el.style.top = `${y - imageCollection.inputOffset.y}px`;
|
||||||
|
|
||||||
// We can use the input element to add interactible html elements in the world
|
// We can use the input element to add interactible html elements in the world
|
||||||
imageCollection.inputElement.appendChild(el);
|
imageCollection.inputElement.appendChild(el);
|
||||||
|
|
Loading…
Reference in a new issue