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

refactor(ClickGui): smoother Panel animation #4625

Open
wants to merge 1 commit into
base: nextgen
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 21 additions & 36 deletions src-theme/src/routes/clickgui/Panel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import {listen} from "../../integration/ws";
import Module from "./Module.svelte";
import type {ToggleModuleEvent} from "../../integration/events";
import {fly} from "svelte/transition";
import {fade} from "svelte/transition";
import {quintOut} from "svelte/easing";
import {gridSize, highlightModuleName, maxPanelZIndex, showGrid, snappingEnabled} from "./clickgui_store";
import {setItem} from "../../integration/persistent_storage";
Expand All @@ -17,8 +17,6 @@
let panelElement: HTMLElement;
let modulesElement: HTMLElement;

let renderedModules: TModule[] = [];

let moving = false;
let offsetX = 0;
let offsetY = 0;
Expand Down Expand Up @@ -66,10 +64,6 @@
$maxPanelZIndex = config.zIndex;
}

if (config.expanded) {
renderedModules = modules;
}

return config;
}
}
Expand Down Expand Up @@ -117,18 +111,10 @@
}

function toggleExpanded() {
if (panelConfig.expanded) {
renderedModules = [];
} else {
renderedModules = modules;
}

panelConfig.expanded = !panelConfig.expanded;

setTimeout(() => {
fixPosition();
savePanelConfig();
}, 500);
fixPosition();
savePanelConfig();
}

function handleModulesScroll() {
Expand All @@ -149,7 +135,6 @@
if (highlightModule) {
panelConfig.zIndex = ++$maxPanelZIndex;
panelConfig.expanded = true;
renderedModules = modules;
savePanelConfig();
}
});
Expand All @@ -163,22 +148,17 @@

mod.enabled = moduleEnabled;
modules = modules;
if (panelConfig.expanded) {
renderedModules = modules;
}
});

onMount(() => {
setTimeout(() => {
if (!modulesElement) {
return;
}
if (!modulesElement) {
return;
}

modulesElement.scrollTo({
top: panelConfig.scrollTop,
behavior: "smooth"
})
}, 500);
modulesElement.scrollTo({
top: panelConfig.scrollTop,
behavior: "smooth"
});
});

function handleKeydown(e: KeyboardEvent) {
Expand Down Expand Up @@ -206,8 +186,7 @@
class="panel"
style="left: {panelConfig.left}px; top: {panelConfig.top}px; z-index: {panelConfig.zIndex};"
bind:this={panelElement}
in:fly|global={{y: -30, duration: 200, easing: quintOut}}
out:fly|global={{y: -30, duration: 200, easing: quintOut}}
transition:fade|global={{duration: 200, easing: quintOut}}
>
<!-- svelte-ignore a11y-no-static-element-interactions -->
<div
Expand All @@ -227,8 +206,13 @@
</button>
</div>

<div class="modules" on:scroll={handleModulesScroll} bind:this={modulesElement}>
{#each renderedModules as {name, enabled, description, aliases} (name)}
<div
class="modules"
style="max-height: {panelConfig.expanded ? '545px' : '0'}"
on:scroll={handleModulesScroll}
bind:this={modulesElement}
>
{#each modules as {name, enabled, description, aliases} (name)}
<Module {name} {enabled} {description} {aliases}/>
{/each}
</div>
Expand Down Expand Up @@ -266,7 +250,8 @@
}

.modules {
max-height: 545px;
transition: max-height 300ms ease-in-out;
scroll-behavior: smooth;
overflow-y: auto;
overflow-x: hidden;
background-color: rgba($clickgui-base-color, 0.8);
Expand Down Expand Up @@ -321,4 +306,4 @@
}
}
}
</style>
</style>
Loading