Skip to content

Commit c00fc7e

Browse files
committed
(v0.3.8-beta) Smooth Dragging
Fixed the bug where 'the grid snapping was offset from the place where icons snap when u release' originally found by SNXHIT_! The motion is soo smooth now!
1 parent e48a01f commit c00fc7e

File tree

3 files changed

+38
-25
lines changed

3 files changed

+38
-25
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ Your PC has been compromised by a group called the "HackClub". Can you regain co
8080
- [ ] Lock some apps (Hacked yk)
8181
- [ ] Stress test the terminal.
8282
- [X] Add games like MC(https://classic.minecraft.net/) and sm others. (Added v0.3.2)
83-
- [ ] the grid snapping is offset from the place where icons snap when u release (Snxhit_)
83+
- [X] the grid snapping is offset from the place where icons snap when u release (Snxhit_)
8484
- [ ] Cmd opens on login and then the notepad opens automatically, remove the alert thing.
85-
- [ ] WINDOW_DEFAULTS: Now the position of the windows change with the width and height, added the vars in App.js (Done v0.3.7)
85+
- [X] WINDOW_DEFAULTS: Now the position of the windows change with the width and height, added the vars in App.js (Done v0.3.7)
8686

8787

8888
Playtesters & Contributors: Flux3tor, Snxhit_, Matthias, Nx75, Keyboard1000n17, abtheinnovator, redac1ed, TruthEntity, SeradedStripes

src/routes/desktop.jsx

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ import * as React from "react";
1515

1616

1717
function Desktop() {
18+
const GRID_WIDTH = 5.35 * 16; // in rem cuz yes sybau
19+
const GRID_HEIGHT = 6 * 16;
20+
const GRID_GAP = 0.5 * 16;
21+
22+
1823
const [isOpenProgressPanel, setIsOpenProgressPanel] = useState(false);
1924
const [isStartMenuActive, setIsStartMenuActive] = useState(false);
2025

@@ -76,7 +81,6 @@ function Desktop() {
7681
});
7782

7883
const lastPos = useRef({ x: 100, y: 100 });
79-
const OFFSET = 20;
8084

8185
const nodeRefs = useMemo(() => {
8286
return Object.keys(APP_REGISTRY).reduce((acc, key) => {
@@ -94,23 +98,33 @@ function Desktop() {
9498
const [draggingIcon, setDraggingIcon] = useState(null);
9599

96100
const handleIconStop = (e, data, id) => {
97-
const gridX = 5.35 * 16;
98-
const gridY = 6 * 16;
101+
setDraggingIcon(null);
102+
103+
const maxCols = Math.floor(window.innerWidth / (GRID_WIDTH + GRID_GAP));
104+
const maxRows = Math.floor((window.innerHeight - 48) / (GRID_HEIGHT + GRID_GAP));
105+
106+
const movedCols = Math.round(data.x / (GRID_WIDTH + GRID_GAP));
107+
const movedRows = Math.round(data.y / (GRID_HEIGHT + GRID_GAP));
99108

100-
const newCol = Math.max(1, Math.round(data.x / gridX) + iconPositions[id].col) ;
101-
const newRow = Math.max(1, Math.round(data.y / gridY) + iconPositions[id].row);
109+
const newCol = Math.min(
110+
Math.max(1, iconPositions[id].col + movedCols),
111+
maxCols
112+
);
113+
const newRow = Math.min(
114+
Math.max(1, iconPositions[id].row + movedRows),
115+
maxRows
116+
);
102117

103118
const isOccupied = Object.entries(iconPositions).some(([appId, pos]) => {
104119
return appId !== id && pos.col === newCol && pos.row === newRow;
105120
});
106121

107-
if (isOccupied) {
108-
return;
122+
if (!isOccupied) {
123+
setIconPositions(prev => ({
124+
...prev,
125+
[id]: { col: newCol, row: newRow }
126+
}));
109127
}
110-
setIconPositions(prev => ({
111-
...prev,
112-
[id]: { col: newCol, row: newRow }
113-
}));
114128
};
115129

116130
function openApp(name) {
@@ -211,7 +225,6 @@ function Desktop() {
211225
key={id}
212226
nodeRef={nodeRefs[id]}
213227
position={{ x: 0, y: 0 }}
214-
grid={[window.innerWidth / 14, (window.innerHeight - 48) / 6]}
215228
onStart={(e) => {
216229
e.stopPropagation();
217230
setSelectedIcon(id);
@@ -236,8 +249,8 @@ function Desktop() {
236249
gridRow: iconPositions[id].row,
237250

238251
zIndex: draggingIcon === id ? 99999 : 1,
239-
opacity: draggingIcon === id ? 1 : undefined,
240-
position: 'relative'
252+
opacity: draggingIcon === id ? 0.6 : 1,
253+
position: 'relative',
241254
}}
242255
>
243256
<img className="app-icon" src={APP_REGISTRY[id].imgSrc} draggable="false" alt="icon" />

src/styles/routes/desktop.css

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
height: calc(100vh - 3rem);
1919
width: 100vw;
2020
display: grid;
21-
21+
inset: 0;
2222
grid-template-columns: repeat(auto-fill, 5.35rem);
2323
grid-template-rows: repeat(auto-fill, 6rem);
2424

@@ -42,21 +42,21 @@
4242
height: 100%;
4343
width: 100%;
4444
gap: 0.25rem;
45-
}
46-
47-
.grid-app-item:hover {
48-
background-color: var(--border);
49-
}
5045

51-
.grid-app-item {
52-
transition: background 0.1s;
46+
transition:
47+
opacity var(--hover-animation) var(--hover-animation-type),
48+
background 0.15s var(--hover-animation-type);
5349
border: 1px solid transparent;
5450
border-radius: 0.25rem;
5551
touch-action: none;
5652
user-select: none;
5753
cursor: pointer;
5854
}
5955

56+
.grid-app-item:hover {
57+
background-color: var(--border);
58+
}
59+
6060
.grid-app-item.selected {
6161
background-color: rgba(0, 120, 215, 0.2);
6262
border: 1px solid var(--blue);
@@ -94,7 +94,7 @@
9494
position: fixed;
9595
width: 100vw;
9696
height: 3rem;
97-
backdrop-filter: blur(2rem) brightness(0.2);
97+
backdrop-filter: blur(2rem) brightness(0.75);
9898
transition: var(--animation-time) var(--hover-animation-type);
9999

100100
display: flex;

0 commit comments

Comments
 (0)