Skip to content

Commit ac69981

Browse files
committed
Refactored resize functionality code
1 parent c5b8f42 commit ac69981

File tree

2 files changed

+51
-37
lines changed

2 files changed

+51
-37
lines changed

src/controls.ts

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -41,34 +41,13 @@ export class URDFControls extends GUI {
4141
this.domElement.setAttribute('class', 'dg main urdf-gui');
4242

4343
// Add resize functionality
44-
let isResizing = false;
45-
let startX: number;
46-
let startWidth: number;
47-
48-
this.domElement.addEventListener('mousedown', (e: MouseEvent) => {
49-
// Only trigger on left border
50-
if (e.clientX < this.domElement.getBoundingClientRect().left + 6) {
51-
isResizing = true;
52-
startX = e.clientX;
53-
startWidth = parseInt(getComputedStyle(this.domElement).width, 10);
54-
}
44+
this._setupResizeHandling({
45+
minWidth: 150,
46+
maxWidth: 500,
47+
grabZoneWidth: 12
5548
});
5649

57-
document.addEventListener('mousemove', (e: MouseEvent) => {
58-
if (!isResizing) return;
59-
60-
const width = startWidth - (e.clientX - startX);
61-
if (width >= 250 && width <= 500) {
62-
this.domElement.style.width = `${width}px`;
63-
}
64-
});
65-
66-
document.addEventListener('mouseup', () => {
67-
isResizing = false;
68-
});
69-
70-
//
71-
50+
// Create folders
7251
this._workspaceFolder = this.addFolder('Workspace');
7352
this._workspaceFolder.domElement.setAttribute(
7453
'class',
@@ -236,4 +215,48 @@ export class URDFControls extends GUI {
236215
}
237216
return this.controls.joints;
238217
}
218+
219+
/**
220+
* Sets up panel resizing functionality
221+
*/
222+
private _setupResizeHandling(options: {
223+
minWidth: number;
224+
maxWidth: number;
225+
grabZoneWidth: number;
226+
}): void {
227+
let isResizing = false;
228+
let startX: number;
229+
let startWidth: number;
230+
231+
const { minWidth, maxWidth, grabZoneWidth } = options;
232+
233+
const onMouseMove = (e: MouseEvent) => {
234+
if (!isResizing) return;
235+
236+
const width = startWidth - (e.clientX - startX);
237+
if (width >= minWidth && width <= maxWidth) {
238+
this.domElement.style.width = `${width}px`;
239+
}
240+
};
241+
242+
const onMouseUp = () => {
243+
isResizing = false;
244+
document.removeEventListener('mousemove', onMouseMove);
245+
document.removeEventListener('mouseup', onMouseUp);
246+
};
247+
248+
this.domElement.addEventListener('mousedown', (e: MouseEvent) => {
249+
if (e.clientX < this.domElement.getBoundingClientRect().left + grabZoneWidth) {
250+
isResizing = true;
251+
startX = e.clientX;
252+
startWidth = parseInt(getComputedStyle(this.domElement).width, 10);
253+
e.preventDefault();
254+
255+
document.addEventListener('mousemove', onMouseMove);
256+
document.addEventListener('mouseup', onMouseUp);
257+
}
258+
});
259+
}
260+
239261
}
262+

style/base.css

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,9 @@
3636
.urdf-gui::before {
3737
content: "";
3838
position: absolute;
39-
left: -3px; /* Align with the left border */
40-
top: 0;
41-
width: 12px; /* Wider hit area for easier grabbing */
39+
width: 12px;
4240
height: 100%;
43-
cursor: ew-resize; /* Show resize cursor on the left edge */
41+
cursor: ew-resize;
4442
}
4543

4644
.urdf-gui li.folder {
@@ -148,11 +146,4 @@
148146
width: 100% !important;
149147
color: white !important; /* This doesn't used a predefined color */
150148
position: absolute;
151-
bottom: 0;
152-
left: 0;
153149
}
154-
155-
/* Style for when panel is closed */
156-
.urdf-gui.closed .close-button {
157-
position: relative; /* Reset position when panel is closed */
158-
}

0 commit comments

Comments
 (0)