Skip to content

Commit 16857ff

Browse files
author
Avaer Kazmer
committed
Add initial tabs support in interface.html
1 parent aacad3c commit 16857ff

File tree

2 files changed

+38
-13
lines changed

2 files changed

+38
-13
lines changed

app.html

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3113,7 +3113,7 @@
31133113

31143114
const uiSize = 2048;
31153115
let renderIds = 0;
3116-
const _renderUi = searchString => new Promise((accept, reject) => {
3116+
const _renderUi = (searchString, selectedTab) => new Promise((accept, reject) => {
31173117
if (renderIds > 0) {
31183118
uiIframe.contentWindow.postMessage({
31193119
method: 'cancel',
@@ -3145,6 +3145,10 @@
31453145
htmlString: interfaceHtml,
31463146
templateData: {
31473147
searchResults,
3148+
tab1: selectedTab === 1,
3149+
tab2: selectedTab === 2,
3150+
tab3: selectedTab === 3,
3151+
tab4: selectedTab === 4,
31483152
},
31493153
width: uiSize,
31503154
height: uiSize,
@@ -3248,28 +3252,32 @@
32483252
const _updateTextureStatic = () => {
32493253
const urlInputAnchor = anchors.find(anchor => anchor.id === 'url-input');
32503254

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);
32533258

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]);
32573262

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+
}
32603266
}
32613267

32623268
texture.image = canvas;
32633269
texture.needsUpdate = true;
32643270
};
32653271

3272+
let selectedTab = 1;
32663273
let anchors = [];
32673274
const _updateTextureDynamic = async () => {
3268-
const result = await _renderUi(text);
3275+
const result = await _renderUi(text, selectedTab);
32693276
if (result.data) {
32703277
ctx.putImageData(new ImageData(new Uint8ClampedArray(result.data.buffer, result.data.byteOffset, result.data.byteLength), uiSize, uiSize), 0, 0);
32713278
}
32723279
anchors = result.anchors;
3280+
material.uniforms.uHover.value.set(0, 0, 0, 0);
32733281
// console.log('got anchors', JSON.stringify(anchors));
32743282

32753283
_updateTextureStatic();
@@ -3438,6 +3446,11 @@
34383446
return null;
34393447
}
34403448
};
3449+
const _selectTab = newSelectedTab => {
3450+
selectedTab = newSelectedTab;
3451+
keyboardFocus = null;
3452+
_updateTextureDynamic();
3453+
};
34413454
mesh.click = (intersectionSpec, controllerIndex) => {
34423455
keyboardFocus = null;
34433456

@@ -3453,6 +3466,14 @@
34533466
const urlInputAnchor = anchors.find(anchor => anchor.id === 'url-input');
34543467
const xOffset = x - urlInputAnchor.x - urlInputPadding[0];
34553468
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);
34563477
} else if (href) {
34573478
const xrIframe = document.createElement('xr-iframe');
34583479
xrIframe.src = href;

interface.html

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,16 @@
115115
<body>
116116
<div class=ui-left>
117117
<!-- <input type=text placeholder="https://" class=url-input id=url-input> -->
118+
{{#tab1}}
118119
<input type=text class=url-input id=url-input>
120+
{{/tab1}}
119121
<div class=radios>
120-
<div class=radio>Actions</div>
121-
<div class="radio selected">WebXR</div>
122-
<div class=radio>Models</div>
123-
<div class=radio>Data</div>
122+
<a id=tab-1 class="radio {{#tab1}}selected{{/tab1}}">WebXR</a>
123+
<a id=tab-2 class="radio {{#tab2}}selected{{/tab2}}">Actions</a>
124+
<a id=tab-3 class="radio {{#tab3}}selected{{/tab3}}">Models</a>
125+
<a id=tab-4 class="radio {{#tab4}}selected{{/tab4}}">Data</a>
124126
</div>
127+
{{#tab1}}
125128
<ul>
126129
{{#searchResults}}
127130
<li>
@@ -135,6 +138,7 @@ <h3>{{label}}</h3>
135138
</li>
136139
{{/searchResults}}
137140
</ul>
141+
{{/tab1}}
138142
</div>
139143
</body>
140144
</html>

0 commit comments

Comments
 (0)