|
3113 | 3113 |
|
3114 | 3114 | const uiSize = 2048; |
3115 | 3115 | let renderIds = 0; |
3116 | | -const _renderUi = searchString => new Promise((accept, reject) => { |
| 3116 | +const _renderUi = (searchString, selectedTab) => new Promise((accept, reject) => { |
3117 | 3117 | if (renderIds > 0) { |
3118 | 3118 | uiIframe.contentWindow.postMessage({ |
3119 | 3119 | method: 'cancel', |
|
3145 | 3145 | htmlString: interfaceHtml, |
3146 | 3146 | templateData: { |
3147 | 3147 | searchResults, |
| 3148 | + tab1: selectedTab === 1, |
| 3149 | + tab2: selectedTab === 2, |
| 3150 | + tab3: selectedTab === 3, |
| 3151 | + tab4: selectedTab === 4, |
3148 | 3152 | }, |
3149 | 3153 | width: uiSize, |
3150 | 3154 | height: uiSize, |
|
3248 | 3252 | const _updateTextureStatic = () => { |
3249 | 3253 | const urlInputAnchor = anchors.find(anchor => anchor.id === 'url-input'); |
3250 | 3254 |
|
3251 | | - ctx.fillStyle = '#f2f3f5'; |
3252 | | - ctx.fillRect(urlInputAnchor.x + urlInputPadding[0] - 4, urlInputAnchor.y + urlInputAnchor.height*0.2, urlInputAnchor.width - urlInputPadding[0]*2 + 4, urlInputAnchor.height*0.6); |
| 3255 | + if (urlInputAnchor) { |
| 3256 | + ctx.fillStyle = '#f2f3f5'; |
| 3257 | + ctx.fillRect(urlInputAnchor.x + urlInputPadding[0] - 4, urlInputAnchor.y + urlInputAnchor.height*0.2, urlInputAnchor.width - urlInputPadding[0]*2 + 4, urlInputAnchor.height*0.6); |
3253 | 3258 |
|
3254 | | - ctx.fillStyle = 'black'; |
3255 | | - ctx.textBaseline = 'bottom'; |
3256 | | - ctx.fillText(text, urlInputAnchor.x + urlInputPadding[0], urlInputAnchor.bottom - urlInputPadding[1]); |
| 3259 | + ctx.fillStyle = 'black'; |
| 3260 | + ctx.textBaseline = 'bottom'; |
| 3261 | + ctx.fillText(text, urlInputAnchor.x + urlInputPadding[0], urlInputAnchor.bottom - urlInputPadding[1]); |
3257 | 3262 |
|
3258 | | - if (keyboardFocus) { |
3259 | | - ctx.fillRect(urlInputAnchor.x + urlInputPadding[0] + measures[cursor] - 4, urlInputAnchor.y + urlInputAnchor.height*0.2, 6, urlInputAnchor.height*0.6); |
| 3263 | + if (keyboardFocus) { |
| 3264 | + ctx.fillRect(urlInputAnchor.x + urlInputPadding[0] + measures[cursor] - 4, urlInputAnchor.y + urlInputAnchor.height*0.2, 6, urlInputAnchor.height*0.6); |
| 3265 | + } |
3260 | 3266 | } |
3261 | 3267 |
|
3262 | 3268 | texture.image = canvas; |
3263 | 3269 | texture.needsUpdate = true; |
3264 | 3270 | }; |
3265 | 3271 |
|
| 3272 | + let selectedTab = 1; |
3266 | 3273 | let anchors = []; |
3267 | 3274 | const _updateTextureDynamic = async () => { |
3268 | | - const result = await _renderUi(text); |
| 3275 | + const result = await _renderUi(text, selectedTab); |
3269 | 3276 | if (result.data) { |
3270 | 3277 | ctx.putImageData(new ImageData(new Uint8ClampedArray(result.data.buffer, result.data.byteOffset, result.data.byteLength), uiSize, uiSize), 0, 0); |
3271 | 3278 | } |
3272 | 3279 | anchors = result.anchors; |
| 3280 | + material.uniforms.uHover.value.set(0, 0, 0, 0); |
3273 | 3281 | // console.log('got anchors', JSON.stringify(anchors)); |
3274 | 3282 |
|
3275 | 3283 | _updateTextureStatic(); |
|
3438 | 3446 | return null; |
3439 | 3447 | } |
3440 | 3448 | }; |
| 3449 | + const _selectTab = newSelectedTab => { |
| 3450 | + selectedTab = newSelectedTab; |
| 3451 | + keyboardFocus = null; |
| 3452 | + _updateTextureDynamic(); |
| 3453 | + }; |
3441 | 3454 | mesh.click = (intersectionSpec, controllerIndex) => { |
3442 | 3455 | keyboardFocus = null; |
3443 | 3456 |
|
|
3453 | 3466 | const urlInputAnchor = anchors.find(anchor => anchor.id === 'url-input'); |
3454 | 3467 | const xOffset = x - urlInputAnchor.x - urlInputPadding[0]; |
3455 | 3468 | cursor = measures.map((measure, index) => [Math.abs(xOffset - measure), index]).sort((a, b) => a[0] - b[0])[0][1]; |
| 3469 | + } else if (id === 'tab-1') { |
| 3470 | + _selectTab(1); |
| 3471 | + } else if (id === 'tab-2') { |
| 3472 | + _selectTab(2); |
| 3473 | + } else if (id === 'tab-3') { |
| 3474 | + _selectTab(3); |
| 3475 | + } else if (id === 'tab-4') { |
| 3476 | + _selectTab(4); |
3456 | 3477 | } else if (href) { |
3457 | 3478 | const xrIframe = document.createElement('xr-iframe'); |
3458 | 3479 | xrIframe.src = href; |
|
0 commit comments