Skip to content

Commit 070f3c8

Browse files
authored
Issue controls panel UI (#81)
* Resizeable controls panel v1 * fixed button color * cleaned code * Refactored resize functionality code * cleaned code * Fix lint check * Fix controls panel resizing * Revert lighting parameters in renderer * Improve controls panel UI resize feature * Make joint names overflow correctly * Lint CSS code
1 parent 8c0a605 commit 070f3c8

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed

src/controls.ts

+56
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ export class URDFControls extends GUI {
4040
this.domElement.style.right = '5px';
4141
this.domElement.setAttribute('class', 'dg main urdf-gui');
4242

43+
// Add resize functionality
44+
this._setupResizeHandling({
45+
minWidth: 150,
46+
grabZoneWidth: 12
47+
});
48+
49+
// Create folders
4350
this._workspaceFolder = this.addFolder('Workspace');
4451
this._workspaceFolder.domElement.setAttribute(
4552
'class',
@@ -207,4 +214,53 @@ export class URDFControls extends GUI {
207214
}
208215
return this.controls.joints;
209216
}
217+
218+
/**
219+
* Sets up panel resizing functionality
220+
* @param minWidth - Minimum width of the panel
221+
* @param maxWidth - Maximum width of the panel
222+
* @param grabZoneWidth - Width of the area where the mouse can be clicked
223+
*/
224+
private _setupResizeHandling(options: {
225+
minWidth: number;
226+
grabZoneWidth: number;
227+
}): void {
228+
let isResizing = false;
229+
let startX: number;
230+
let startWidth: number;
231+
232+
const { minWidth, grabZoneWidth } = options;
233+
234+
const onMouseMove = (e: MouseEvent) => {
235+
if (!isResizing) {
236+
return;
237+
}
238+
239+
const width = startWidth - (e.clientX - startX);
240+
if (width >= minWidth) {
241+
this.domElement.style.width = `${width}px`;
242+
}
243+
};
244+
245+
const onMouseUp = () => {
246+
isResizing = false;
247+
document.removeEventListener('mousemove', onMouseMove);
248+
document.removeEventListener('mouseup', onMouseUp);
249+
};
250+
251+
this.domElement.addEventListener('mousedown', (e: MouseEvent) => {
252+
if (
253+
e.clientX <
254+
this.domElement.getBoundingClientRect().left + grabZoneWidth
255+
) {
256+
isResizing = true;
257+
startX = e.clientX;
258+
startWidth = parseInt(getComputedStyle(this.domElement).width, 10);
259+
e.preventDefault();
260+
261+
document.addEventListener('mousemove', onMouseMove);
262+
document.addEventListener('mouseup', onMouseUp);
263+
}
264+
});
265+
}
210266
}

style/base.css

+50
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@
2727
color: var(--gui-color-font);
2828
border: none;
2929
box-sizing: border-box;
30+
min-width: 150px;
31+
max-width: 98%;
32+
padding-bottom: 20px;
33+
}
34+
35+
/* Add a resize handle on the left border */
36+
.urdf-gui::before {
37+
content: '';
38+
position: absolute;
39+
width: 12px;
40+
height: 100%;
41+
cursor: ew-resize;
3042
}
3143

3244
.urdf-gui li.folder {
@@ -129,8 +141,46 @@
129141
overflow: scroll;
130142
}
131143

144+
/* Style for Dat.GUI's close button */
145+
.urdf-gui .close-button {
146+
width: 100% !important;
147+
color: white !important;
148+
position: absolute;
149+
}
150+
132151
/* Expand hover area to reach color pickers */
133152
.urdf-gui .cr.color .c:hover {
134153
padding: 15px 0;
135154
margin: -15px 0;
136155
}
156+
157+
.urdf-gui li.cr.number.has-slider .property-name {
158+
flex: 1 1;
159+
padding-right: 15px;
160+
}
161+
162+
.urdf-gui li.cr.number.has-slider .property-name:hover {
163+
overflow-x: auto;
164+
text-overflow: unset;
165+
}
166+
167+
/* Adjust the control container */
168+
.urdf-gui li.cr.number.has-slider .c {
169+
flex: 0 1 180px;
170+
margin-left: auto;
171+
}
172+
173+
li.cr.number.has-slider > div {
174+
display: flex;
175+
}
176+
177+
/* Styling for Chromium based browsers */
178+
.urdf-gui li.cr.number.has-slider .property-name:hover::-webkit-scrollbar {
179+
height: 8px;
180+
}
181+
182+
.urdf-gui
183+
li.cr.number.has-slider
184+
.property-name:hover::-webkit-scrollbar-thumb {
185+
background: #888;
186+
}

0 commit comments

Comments
 (0)