Skip to content

Commit 305abd5

Browse files
add scenes search to app.html
1 parent 481cfbe commit 305abd5

File tree

1 file changed

+113
-17
lines changed

1 file changed

+113
-17
lines changed

app.html

Lines changed: 113 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,7 @@
611611
interfaceHtml,
612612
labelHtml,
613613
searchSitesJson,
614+
searchScenesJson,
614615
keyboardHighlightCanvasCtx,
615616
keyMap,
616617
fontJson,
@@ -668,6 +669,30 @@
668669
}
669670
};
670671
}),
672+
fetch('scenes.json')
673+
.then(res => res.json())
674+
.then(scenesJson => {
675+
return s => {
676+
console.log("scenes.json");
677+
const maxResults = 12;
678+
if (s) {
679+
const regexps = s.split(/\s/).filter(s => !!s).map(s => new RegExp(escapeRegExp(s), 'i'));
680+
const results = [];
681+
for (let i = 0; i < scenesJson.length; i++) {
682+
const site = scenesJson[i];
683+
if (regexps.some(regexp => regexp.test(site.label) || regexp.test(site.url))) {
684+
results.push(site);
685+
if (results.length >= maxResults) {
686+
break;
687+
}
688+
}
689+
}
690+
return results;
691+
} else {
692+
return scenesJson.slice(0, maxResults);
693+
}
694+
};
695+
}),
671696
new Promise((accept, reject) => {
672697
const img = new Image();
673698
img.crossOrigin = 'Anonymous';
@@ -3276,7 +3301,12 @@
32763301
}
32773302
};
32783303

3279-
const searchResults = searchSitesJson(searchString);
3304+
console.log(" ------ selectedTab = " + selectedTab);
3305+
if (selectedTab === 1) {
3306+
var searchResults = searchSitesJson(searchString);
3307+
} else if (selectedTab === 2) {
3308+
var searchResults = searchScenesJson(searchString);
3309+
}
32803310

32813311
uiIframe.contentWindow.postMessage({
32823312
method: 'render',
@@ -3372,28 +3402,42 @@
33723402

33733403
let items = [];
33743404
let text = 'https://';
3375-
const measures = [];
3376-
let cursor = text.length;
3405+
let sceneText = '';
3406+
const urlMeasures = [];
3407+
const sceneMeasures = [];
3408+
let urlCursor = text.length;
3409+
let sceneCursor = sceneText.length;
33773410
const canvas = document.createElement('canvas');
33783411
canvas.width = uiSize;
33793412
canvas.height = uiSize;
33803413
const ctx = canvas.getContext('2d');
33813414
ctx.font = '300 80px Open Sans';
3382-
const _updateMeasures = () => {
3383-
measures.length = 0;
3384-
measures.push(0);
3415+
const _updateUrlMeasures = () => {
3416+
urlMeasures.length = 0;
3417+
urlMeasures.push(0);
33853418
const {width: barWidth} = ctx.measureText('[');
33863419
for (let i = 1; i <= text.length; i++) {
33873420
const {width} = ctx.measureText('[' + text.slice(0, i) + ']');
3388-
measures.push(width - barWidth*2);
3421+
urlMeasures.push(width - barWidth*2);
3422+
}
3423+
};
3424+
_updateUrlMeasures();
3425+
const _updateSceneMeasures = () => {
3426+
sceneMeasures.length = 0;
3427+
sceneMeasures.push(0);
3428+
const {width: barWidth} = ctx.measureText('[');
3429+
for (let i = 1; i <= sceneText.length; i++) {
3430+
const {width} = ctx.measureText('[' + sceneText.slice(0, i) + ']');
3431+
sceneMeasures.push(width - barWidth*2);
33893432
}
33903433
};
3391-
_updateMeasures();
3434+
_updateSceneMeasures();
33923435

33933436
const urlInputPadding = [40, 53];
3437+
const sceneInputPadding = [40, 53];
33943438
const _updateTextureStatic = () => {
3395-
const urlInputAnchor = anchors.find(anchor => anchor.id === 'url-input');
33963439

3440+
const urlInputAnchor = anchors.find(anchor => anchor.id === 'url-input');
33973441
if (urlInputAnchor) {
33983442
ctx.fillStyle = '#f2f3f5';
33993443
ctx.fillRect(urlInputAnchor.x + urlInputPadding[0] - 4, urlInputAnchor.y + urlInputAnchor.height*0.2, urlInputAnchor.width - urlInputPadding[0]*2 + 4, urlInputAnchor.height*0.6);
@@ -3403,7 +3447,21 @@
34033447
ctx.fillText(text, urlInputAnchor.x + urlInputPadding[0], urlInputAnchor.bottom - urlInputPadding[1]);
34043448

34053449
if (keyboardFocus) {
3406-
ctx.fillRect(urlInputAnchor.x + urlInputPadding[0] + measures[cursor] - 4, urlInputAnchor.y + urlInputAnchor.height*0.2, 6, urlInputAnchor.height*0.6);
3450+
ctx.fillRect(urlInputAnchor.x + urlInputPadding[0] + urlMeasures[urlCursor] - 4, urlInputAnchor.y + urlInputAnchor.height*0.2, 6, urlInputAnchor.height*0.6);
3451+
}
3452+
}
3453+
3454+
const sceneInputAnchor = anchors.find(anchor => anchor.id === 'scene-input');
3455+
if (sceneInputAnchor) {
3456+
ctx.fillStyle = '#f2f3f5';
3457+
ctx.fillRect(sceneInputAnchor.x + sceneInputPadding[0] - 4, sceneInputAnchor.y + sceneInputAnchor.height*0.2, sceneInputAnchor.width - sceneInputPadding[0]*2 + 4, sceneInputAnchor.height*0.6);
3458+
3459+
ctx.fillStyle = 'black';
3460+
ctx.textBaseline = 'bottom';
3461+
ctx.fillText(sceneText, sceneInputAnchor.x + sceneInputPadding[0], sceneInputAnchor.bottom - sceneInputPadding[1]);
3462+
3463+
if (keyboardFocus) {
3464+
ctx.fillRect(sceneInputAnchor.x + sceneInputPadding[0] + sceneMeasures[sceneCursor] - 4, sceneInputAnchor.y + sceneInputAnchor.height*0.2, 6, sceneInputAnchor.height*0.6);
34073465
}
34083466
}
34093467

@@ -3612,7 +3670,18 @@
36123670

36133671
const urlInputAnchor = anchors.find(anchor => anchor.id === 'url-input');
36143672
const xOffset = x - urlInputAnchor.x - urlInputPadding[0];
3615-
cursor = measures.map((measure, index) => [Math.abs(xOffset - measure), index]).sort((a, b) => a[0] - b[0])[0][1];
3673+
urlCursor = urlMeasures.map((measure, index) => [Math.abs(xOffset - measure), index]).sort((a, b) => a[0] - b[0])[0][1];
3674+
} else if (id === 'scene-input') {
3675+
const {x, y} = intersectionSpec;
3676+
3677+
keyboardFocus = {
3678+
textMesh: mesh,
3679+
caretMesh: mesh,
3680+
};
3681+
3682+
const sceneInputAnchor = anchors.find(anchor => anchor.id === 'scene-input');
3683+
const xOffset = x - sceneInputAnchor.x - sceneInputPadding[0];
3684+
sceneCursor = sceneMeasures.map((measure, index) => [Math.abs(xOffset - measure), index]).sort((a, b) => a[0] - b[0])[0][1];
36163685
} else if (id === 'tab-1') {
36173686
_selectTab(1);
36183687
} else if (id === 'tab-2') {
@@ -3702,15 +3771,40 @@
37023771
} */
37033772
};
37043773

3705-
mesh.getText = () => text;
3774+
mesh.getText = () => {
3775+
if (selectedTab === 1){
3776+
return text;
3777+
} else if (selectedTab === 2) {
3778+
return sceneText;
3779+
}
3780+
}
37063781
mesh.setText = newText => {
3707-
text = newText;
3708-
_updateMeasures();
3782+
if (selectedTab === 1){
3783+
text = newText;
3784+
_updateUrlMeasures();
3785+
} else if (selectedTab === 2) {
3786+
sceneText = newText;
3787+
_updateSceneMeasures();
3788+
}
37093789
_updateTextureDynamic();
37103790
};
3711-
mesh.getValue = () => cursor;
3791+
mesh.getValue = () => {
3792+
if (selectedTab === 1){
3793+
console.log("getValue of urlCursor = " + urlCursor);
3794+
return urlCursor;
3795+
} else if (selectedTab === 2) {
3796+
console.log("getValue of sceneCursor = " + sceneCursor);
3797+
return sceneCursor;
3798+
}
3799+
};
37123800
mesh.setValue = newValue => {
3713-
cursor = newValue;
3801+
if (selectedTab === 1){
3802+
urlCursor = newValue;
3803+
console.log("set urlCursor = " + newValue);
3804+
} else if (selectedTab === 2) {
3805+
sceneCursor = newValue;
3806+
console.log("set sceneCursor = " + newValue);
3807+
}
37143808
_updateTextureStatic();
37153809
};
37163810
mesh.refresh = _updateTextureStatic;
@@ -3868,7 +3962,9 @@
38683962

38693963
return object;
38703964
})();
3871-
mesh.add(keyboardMesh);
3965+
if (fakeXrDisplay) {
3966+
mesh.add(keyboardMesh);
3967+
}
38723968

38733969
const appIconMeshes = new THREE.Object3D();
38743970
scene.add(appIconMeshes);

0 commit comments

Comments
 (0)