Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚩PR: Added feature of GridLayout repositioning #624

Merged
merged 10 commits into from
Mar 12, 2024
Merged
Prev Previous commit
Next Next commit
Fixed mouse leave event handling
  • Loading branch information
elsoazemelet committed Mar 1, 2024
commit 34fd628d40b76646f075159422e54fa7c0b9158e
19 changes: 15 additions & 4 deletions src/renderer/main/MiddlePanelContainer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,27 @@
const stickyRect = stickyContainer.getBoundingClientRect();
const threshold = -15;

showFixedStickyContainer = !(
stickyRect.bottom <
contRect.bottom + threshold
);
showFixedStickyContainer =
stickyRect.bottom >= contRect.bottom + threshold ||
stickyRect.top <= contRect.top - threshold ||
stickyRect.left <= contRect.left - threshold ||
stickyRect.right >= contRect.right + threshold;
}

onMount(() => {
window.addEventListener("resize", handleResize, true);
});

function handleGridLayoutShift(vector) {
if (vector.x === 0 && vector.y === 0) {
return;
}

handleResize();
}

$: handleGridLayoutShift($appSettings.gridLayoutShift);

let showModuleHangingDialog = false;
let moduleHangingTimeout = undefined;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,42 +26,58 @@

switch (e.type) {
case "keydown": {
trackMouse = true;
handleKeyDown(e);
break;
}
case "keyup": {
trackMouse = false;
handleKeyUp(e);
break;
}
}
}

function handleKeyDown(e) {
trackMouse = true;
}

function handleKeyUp(e) {
trackMouse = false;
}

function handleMouseEvent(e) {
if (e.button !== 0) {
return;
}

switch (e.type) {
case "mousedown": {
if (!trackMouse) {
return;
}
startPoint = { x: e.screenX, y: e.screenY };
dragMouse = true;
const current = get(appSettings).gridLayoutShift;
if (current.x === 0 && current.y === 0) {
previousVector = current;
}
handleMouseDown(e);
break;
}
case "mouseup": {
dragMouse = false;
previousVector = get(appSettings).gridLayoutShift;
handleMouseUp(e);
break;
}
}
}

function handleMouseDown(e) {
if (!trackMouse) {
return;
}
startPoint = { x: e.screenX, y: e.screenY };
dragMouse = true;
const current = get(appSettings).gridLayoutShift;
if (current.x === 0 && current.y === 0) {
previousVector = current;
}
}

function handleMouseUp(e) {
dragMouse = false;
previousVector = get(appSettings).gridLayoutShift;
}

function handleMouseMove(e) {
if (!dragMouse) {
return;
Expand Down Expand Up @@ -101,11 +117,17 @@
document.removeEventListener("mousemove", handleMouseMove);
document.removeEventListener("mouseup", handleMouseEvent);
});

function handleMouseLeave(e) {
handleKeyUp(e);
handleMouseUp(e);
}
</script>

<!-- svelte-ignore a11y-no-static-element-interactions -->
<container
class="absolute w-full h-full z-[1]"
on:mouseleave={handleMouseLeave}
class:pointer-events-none={!trackMouse}
class:cursor-grab={trackMouse}
/>
Loading