@@ -76,6 +76,9 @@ export class Panel extends View implements Draggable, Partial<HasDraggingMode> {
7676 */
7777 showHighlights = false ;
7878
79+ /** The width of the interactive border, in meters. */
80+ borderWidth = 0.1 ;
81+
7982 /** The background color of the panel, expressed as a CSS color string. */
8083 backgroundColor = '#c2c2c255' ;
8184
@@ -123,8 +126,6 @@ export class Panel extends View implements Draggable, Partial<HasDraggingMode> {
123126 const isDraggable = options . draggable ?? this . draggable ;
124127
125128 const useBorderlessShader = options . useBorderlessShader ?? ! isDraggable ;
126- // Draggable panels have a larger geometry for interaction padding.
127- const panelScale = useBorderlessShader ? 1.0 : 1.3 ;
128129 // Use SpatialPanelShader for SpatialPanel, while developers can choose
129130 // useBorderlessShader=false to disable the interactive border.
130131 const shader = useBorderlessShader ? SquircleShader : SpatialPanelShader ;
@@ -147,8 +148,12 @@ export class Panel extends View implements Draggable, Partial<HasDraggingMode> {
147148 options . useDefaultPosition ?? this . useDefaultPosition ;
148149 this . useBorderlessShader =
149150 options . useBorderlessShader ?? this . useBorderlessShader ;
151+ this . borderWidth = options . borderWidth ?? this . borderWidth ;
150152
151- this . mesh = new PanelMesh ( shader , this . backgroundColor , panelScale ) ;
153+ this . mesh = new PanelMesh ( shader , this . backgroundColor ) ;
154+ if ( this . mesh . uniforms . uBorderWidth ) {
155+ this . mesh . uniforms . uBorderWidth . value = this . borderWidth ;
156+ }
152157 this . add ( this . mesh ) ;
153158
154159 this . updateLayout ( ) ;
@@ -321,13 +326,21 @@ export class Panel extends View implements Draggable, Partial<HasDraggingMode> {
321326 */
322327 override updateLayout ( ) {
323328 super . updateLayout ( ) ;
324- this . mesh . setAspectRatio ( this . aspectRatio ) ;
325329 const parentAspectRatio =
326330 this . isRoot || ! this . parent ? 1.0 : ( this . parent as View ) . aspectRatio ;
327- this . mesh . setWidthHeight (
328- this . width * Math . max ( parentAspectRatio , 1.0 ) ,
329- this . height * Math . max ( 1.0 / parentAspectRatio , 1.0 )
330- ) ;
331+ const layoutWidth = this . width * Math . max ( parentAspectRatio , 1.0 ) ;
332+ const layoutHeight = this . height * Math . max ( 1.0 / parentAspectRatio , 1.0 ) ;
333+
334+ const effectiveBorderWidth = this . useBorderlessShader
335+ ? 0.0
336+ : this . borderWidth ;
337+ const meshWidth = layoutWidth + effectiveBorderWidth ;
338+ const meshHeight = layoutHeight + effectiveBorderWidth ;
339+
340+ const panelScale = Math . min ( layoutWidth , layoutHeight ) ;
341+ this . mesh . scale . set ( meshWidth / panelScale , meshHeight / panelScale , 1.0 ) ;
342+
343+ this . mesh . setWidthHeight ( meshWidth , meshHeight ) ;
331344 this . mesh . renderOrder = this . renderOrder ;
332345 }
333346
0 commit comments