Skip to content

Commit e6e54a7

Browse files
add scenes search to app.html
1 parent d57599e commit e6e54a7

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
@@ -604,6 +604,7 @@
604604
interfaceHtml,
605605
labelHtml,
606606
searchSitesJson,
607+
searchScenesJson,
607608
keyboardHighlightCanvasCtx,
608609
keyMap,
609610
fontJson,
@@ -661,6 +662,30 @@
661662
}
662663
};
663664
}),
665+
fetch('scenes.json')
666+
.then(res => res.json())
667+
.then(scenesJson => {
668+
return s => {
669+
console.log("scenes.json");
670+
const maxResults = 12;
671+
if (s) {
672+
const regexps = s.split(/\s/).filter(s => !!s).map(s => new RegExp(escapeRegExp(s), 'i'));
673+
const results = [];
674+
for (let i = 0; i < scenesJson.length; i++) {
675+
const site = scenesJson[i];
676+
if (regexps.some(regexp => regexp.test(site.label) || regexp.test(site.url))) {
677+
results.push(site);
678+
if (results.length >= maxResults) {
679+
break;
680+
}
681+
}
682+
}
683+
return results;
684+
} else {
685+
return scenesJson.slice(0, maxResults);
686+
}
687+
};
688+
}),
664689
new Promise((accept, reject) => {
665690
const img = new Image();
666691
img.crossOrigin = 'Anonymous';
@@ -3257,7 +3282,12 @@
32573282
}
32583283
};
32593284

3260-
const searchResults = searchSitesJson(searchString);
3285+
console.log(" ------ selectedTab = " + selectedTab);
3286+
if (selectedTab === 1) {
3287+
var searchResults = searchSitesJson(searchString);
3288+
} else if (selectedTab === 2) {
3289+
var searchResults = searchScenesJson(searchString);
3290+
}
32613291

32623292
uiIframe.contentWindow.postMessage({
32633293
method: 'render',
@@ -3350,28 +3380,42 @@
33503380

33513381
let items = [];
33523382
let text = 'https://';
3353-
const measures = [];
3354-
let cursor = text.length;
3383+
let sceneText = '';
3384+
const urlMeasures = [];
3385+
const sceneMeasures = [];
3386+
let urlCursor = text.length;
3387+
let sceneCursor = sceneText.length;
33553388
const canvas = document.createElement('canvas');
33563389
canvas.width = uiSize;
33573390
canvas.height = uiSize;
33583391
const ctx = canvas.getContext('2d');
33593392
ctx.font = '300 80px Open Sans';
3360-
const _updateMeasures = () => {
3361-
measures.length = 0;
3362-
measures.push(0);
3393+
const _updateUrlMeasures = () => {
3394+
urlMeasures.length = 0;
3395+
urlMeasures.push(0);
33633396
const {width: barWidth} = ctx.measureText('[');
33643397
for (let i = 1; i <= text.length; i++) {
33653398
const {width} = ctx.measureText('[' + text.slice(0, i) + ']');
3366-
measures.push(width - barWidth*2);
3399+
urlMeasures.push(width - barWidth*2);
3400+
}
3401+
};
3402+
_updateUrlMeasures();
3403+
const _updateSceneMeasures = () => {
3404+
sceneMeasures.length = 0;
3405+
sceneMeasures.push(0);
3406+
const {width: barWidth} = ctx.measureText('[');
3407+
for (let i = 1; i <= sceneText.length; i++) {
3408+
const {width} = ctx.measureText('[' + sceneText.slice(0, i) + ']');
3409+
sceneMeasures.push(width - barWidth*2);
33673410
}
33683411
};
3369-
_updateMeasures();
3412+
_updateSceneMeasures();
33703413

33713414
const urlInputPadding = [40, 53];
3415+
const sceneInputPadding = [40, 53];
33723416
const _updateTextureStatic = () => {
3373-
const urlInputAnchor = anchors.find(anchor => anchor.id === 'url-input');
33743417

3418+
const urlInputAnchor = anchors.find(anchor => anchor.id === 'url-input');
33753419
if (urlInputAnchor) {
33763420
ctx.fillStyle = '#f2f3f5';
33773421
ctx.fillRect(urlInputAnchor.x + urlInputPadding[0] - 4, urlInputAnchor.y + urlInputAnchor.height*0.2, urlInputAnchor.width - urlInputPadding[0]*2 + 4, urlInputAnchor.height*0.6);
@@ -3381,7 +3425,21 @@
33813425
ctx.fillText(text, urlInputAnchor.x + urlInputPadding[0], urlInputAnchor.bottom - urlInputPadding[1]);
33823426

33833427
if (keyboardFocus) {
3384-
ctx.fillRect(urlInputAnchor.x + urlInputPadding[0] + measures[cursor] - 4, urlInputAnchor.y + urlInputAnchor.height*0.2, 6, urlInputAnchor.height*0.6);
3428+
ctx.fillRect(urlInputAnchor.x + urlInputPadding[0] + urlMeasures[urlCursor] - 4, urlInputAnchor.y + urlInputAnchor.height*0.2, 6, urlInputAnchor.height*0.6);
3429+
}
3430+
}
3431+
3432+
const sceneInputAnchor = anchors.find(anchor => anchor.id === 'scene-input');
3433+
if (sceneInputAnchor) {
3434+
ctx.fillStyle = '#f2f3f5';
3435+
ctx.fillRect(sceneInputAnchor.x + sceneInputPadding[0] - 4, sceneInputAnchor.y + sceneInputAnchor.height*0.2, sceneInputAnchor.width - sceneInputPadding[0]*2 + 4, sceneInputAnchor.height*0.6);
3436+
3437+
ctx.fillStyle = 'black';
3438+
ctx.textBaseline = 'bottom';
3439+
ctx.fillText(sceneText, sceneInputAnchor.x + sceneInputPadding[0], sceneInputAnchor.bottom - sceneInputPadding[1]);
3440+
3441+
if (keyboardFocus) {
3442+
ctx.fillRect(sceneInputAnchor.x + sceneInputPadding[0] + sceneMeasures[sceneCursor] - 4, sceneInputAnchor.y + sceneInputAnchor.height*0.2, 6, sceneInputAnchor.height*0.6);
33853443
}
33863444
}
33873445

@@ -3585,7 +3643,18 @@
35853643

35863644
const urlInputAnchor = anchors.find(anchor => anchor.id === 'url-input');
35873645
const xOffset = x - urlInputAnchor.x - urlInputPadding[0];
3588-
cursor = measures.map((measure, index) => [Math.abs(xOffset - measure), index]).sort((a, b) => a[0] - b[0])[0][1];
3646+
urlCursor = urlMeasures.map((measure, index) => [Math.abs(xOffset - measure), index]).sort((a, b) => a[0] - b[0])[0][1];
3647+
} else if (id === 'scene-input') {
3648+
const {x, y} = intersectionSpec;
3649+
3650+
keyboardFocus = {
3651+
textMesh: mesh,
3652+
caretMesh: mesh,
3653+
};
3654+
3655+
const sceneInputAnchor = anchors.find(anchor => anchor.id === 'scene-input');
3656+
const xOffset = x - sceneInputAnchor.x - sceneInputPadding[0];
3657+
sceneCursor = sceneMeasures.map((measure, index) => [Math.abs(xOffset - measure), index]).sort((a, b) => a[0] - b[0])[0][1];
35893658
} else if (id === 'tab-1') {
35903659
_selectTab(1);
35913660
} else if (id === 'tab-2') {
@@ -3662,15 +3731,40 @@
36623731
} */
36633732
};
36643733

3665-
mesh.getText = () => text;
3734+
mesh.getText = () => {
3735+
if (selectedTab === 1){
3736+
return text;
3737+
} else if (selectedTab === 2) {
3738+
return sceneText;
3739+
}
3740+
}
36663741
mesh.setText = newText => {
3667-
text = newText;
3668-
_updateMeasures();
3742+
if (selectedTab === 1){
3743+
text = newText;
3744+
_updateUrlMeasures();
3745+
} else if (selectedTab === 2) {
3746+
sceneText = newText;
3747+
_updateSceneMeasures();
3748+
}
36693749
_updateTextureDynamic();
36703750
};
3671-
mesh.getValue = () => cursor;
3751+
mesh.getValue = () => {
3752+
if (selectedTab === 1){
3753+
console.log("getValue of urlCursor = " + urlCursor);
3754+
return urlCursor;
3755+
} else if (selectedTab === 2) {
3756+
console.log("getValue of sceneCursor = " + sceneCursor);
3757+
return sceneCursor;
3758+
}
3759+
};
36723760
mesh.setValue = newValue => {
3673-
cursor = newValue;
3761+
if (selectedTab === 1){
3762+
urlCursor = newValue;
3763+
console.log("set urlCursor = " + newValue);
3764+
} else if (selectedTab === 2) {
3765+
sceneCursor = newValue;
3766+
console.log("set sceneCursor = " + newValue);
3767+
}
36743768
_updateTextureStatic();
36753769
};
36763770
mesh.refresh = _updateTextureStatic;
@@ -3828,7 +3922,9 @@
38283922

38293923
return object;
38303924
})();
3831-
mesh.add(keyboardMesh);
3925+
if (fakeXrDisplay) {
3926+
mesh.add(keyboardMesh);
3927+
}
38323928

38333929
const appIconMeshes = new THREE.Object3D();
38343930
scene.add(appIconMeshes);

0 commit comments

Comments
 (0)