Skip to content

Commit c3d9b7a

Browse files
window buttons in XR (better)
1 parent 55883df commit c3d9b7a

File tree

4 files changed

+64
-22
lines changed

4 files changed

+64
-22
lines changed

com/helloworld-window.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,29 @@ AFRAME.registerComponent('helloworld-window', {
8181
},
8282

8383
DOMready: function(){
84-
this.el.setAttribute("window", `title: XRSH; uid: ${this.el.uid}; attach: #overlay; dom: #${this.el.dom.id}; width:250; height: 360`)
84+
this.el.setAttribute("window", `title: XRSH; uid: ${this.el.uid}; attach: #overlay; dom: #${this.el.dom.id}; class: no-min, no-max; width:250; height: 360`)
8585

8686
// data2event demo
8787
this.el.setAttribute("data2event","")
8888
this.data.myvalue = 1001
8989
this.data.foo = `this.el ${this.el.uid}: `
9090
setInterval( () => this.data.myvalue++, 500 )
9191

92+
// if you want your launch-icon to stick around after
93+
// closing the window, then register it manually
94+
window.launcher.register({
95+
component: "helloworld-window",
96+
...this.manifest,
97+
icon: this.manifest.icons[0].src,
98+
cb: () => {
99+
const el = document.createElement("a-entity")
100+
el.setAttribute("helloworld-window","")
101+
el.setAttribute("pressable","")
102+
el.setAttribute("position","0 1.6 0")
103+
AFRAME.scenes[0].appendChild(el)
104+
setTimeout( () => el.emit('launcher',null,false), 100 )
105+
}
106+
})
92107
},
93108

94109
"window.oncreate": function(){

com/isoterminal.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ if( typeof AFRAME != 'undefined '){
145145
.isoterminal{
146146
padding: ${me.com.data.padding}px;
147147
margin-top:-60px;
148+
padding-bottom:60px;
148149
width:100%;
149150
height:99%;
150151
resize: both;
@@ -257,7 +258,7 @@ if( typeof AFRAME != 'undefined '){
257258
}
258259
259260
.XR .isoterminal{
260-
background: transparent;
261+
background: #000 !important;
261262
}
262263
263264
.isoterminal *{
@@ -346,7 +347,7 @@ if( typeof AFRAME != 'undefined '){
346347
this.term.emit('term_init', {instance, aEntity:this})
347348
//instance.winbox.resize(720,380)
348349
let size = `width: ${this.data.width}; height: ${this.data.height}`
349-
instance.setAttribute("window", `title: ${this.data.title}; uid: ${instance.uid}; attach: #overlay; dom: #${instance.dom.id}; ${size}; min: ${this.data.minimized}; max: ${this.data.maximized}; class: no-full, no-close, no-max, no-resize; grabbable: components.html.el.object3D.children.${this.el.children.length}`)
350+
instance.setAttribute("window", `title: ${this.data.title}; uid: ${instance.uid}; attach: #overlay; dom: #${instance.dom.id}; ${size}; min: ${this.data.minimized}; max: ${this.data.maximized}; class: no-full, no-min, no-close, no-max, no-resize; grabbable: components.html.el.object3D.children.${this.el.children.length}`)
350351
})
351352

352353
instance.addEventListener('window.oncreate', (e) => {
@@ -502,6 +503,7 @@ if( typeof AFRAME != 'undefined '){
502503
"scope": "/",
503504
"theme_color": "#3367D6",
504505
"shortcuts": [
506+
/*
505507
{
506508
"name": "What is the latest news?",
507509
"cli":{
@@ -516,8 +518,9 @@ if( typeof AFRAME != 'undefined '){
516518
"url": "/today?source=pwa",
517519
"icons": [{ "src": "/images/today.png", "sizes": "192x192" }]
518520
}
521+
*/
519522
],
520-
"description": "Hello world information",
523+
"description": "Runs an .iso file",
521524
"screenshots": [
522525
{
523526
"src": "/images/screenshot1.png",
@@ -527,7 +530,7 @@ if( typeof AFRAME != 'undefined '){
527530
}
528531
],
529532
"help":`
530-
Helloworld application
533+
XRSH application
531534
532535
This is a help file which describes the application.
533536
It will be rendered thru troika text, and will contain

com/launcher.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
*
44
* displays app (icons) in 2D and 3D handmenu (enduser can launch desktop-like 'apps')
55
*
6+
* They can be temporary processes (icon disappears after component is removed) or permanent icons
7+
* when registered via .register({...})
8+
*
69
* ```html
710
* <a-entity launcher>
811
* <a-entity launch="component: helloworld; foo: bar"><a-entity>
@@ -340,7 +343,10 @@ AFRAME.registerSystem('launcher',{
340343
];
341344

342345
// collect manually registered launchables
343-
this.registered.map( (launchable) => this.launchables.push(launchable) )
346+
this.registered.map( (launchable) => {
347+
if( launchable.component ) seen[ launchable.component ] = true
348+
this.launchables.push(launchable)
349+
})
344350

345351
// collect launchables in aframe dom elements
346352
this.dom = els.filter( (el) => {
@@ -349,8 +355,11 @@ AFRAME.registerSystem('launcher',{
349355
for( let i in el.components ){
350356
if( el.components[i].events && el.components[i].events[searchEvent] && !seen[i] ){
351357
let com = hasEvent = seen[i] = el.components[i]
352-
com.launcher = () => com.el.emit('launcher',null,false) // important: no bubble
353-
this.launchables.push(com)
358+
let alreadyAdded = this.launchables.find( (l) => l.manifest.name == com.manifest.name )
359+
if( !alreadyAdded ){
360+
com.launcher = () => com.el.emit('launcher',null,false) // important: no bubble
361+
this.launchables.push({manifest: com.manifest, launcher: com.launcher})
362+
}
354363
}
355364
}
356365
}

com/window.js

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,6 @@ AFRAME.registerComponent('window', {
5353
setupWindow: async function(){
5454
await AFRAME.utils.require(this.dependencies)
5555
if( !this.el.dom ) return console.error('window element requires dom-component as dependency')
56-
57-
const close = () => {
58-
let e = {halt:false}
59-
this.el.emit('window.onclose',e)
60-
if( e.halt ) return true
61-
this.data.dom.style.display = 'none';
62-
if( this.el.parentNode ) this.el.remove() //parentElement.remove( this.el )
63-
this.data.dom.parentElement.remove()
64-
return false
65-
}
6656
this.el.addEventListener('close', () => {
6757
close()
6858
this.el.winbox.close()
@@ -94,7 +84,9 @@ AFRAME.registerComponent('window', {
9484

9585
this.patchButtons(e)
9686
},
97-
onclose: close
87+
onminimize: this.onminimize,
88+
onrestore: this.onrestore,
89+
onclose: this.onclose.bind(this),
9890

9991
});
10092
this.data.dom.style.display = '' // show
@@ -116,15 +108,38 @@ AFRAME.registerComponent('window', {
116108
this.el.dom.closest('.winbox').style.display = state ? '' : 'none'
117109
},
118110

111+
onminimize: function(e){
112+
if( AFRAME.scenes[0].renderer.xr.isPresenting ){
113+
this.window.style.display = 'none'
114+
}
115+
},
116+
117+
onrestore: function(e){
118+
if( AFRAME.scenes[0].renderer.xr.isPresenting ){
119+
this.window.style.display = ''
120+
}
121+
},
122+
123+
onclose: function(){
124+
let e = {halt:false}
125+
this.el.emit('window.onclose',e)
126+
if( e.halt ) return true
127+
this.data.dom.style.display = 'none';
128+
if( this.el.parentNode ) this.el.remove() //parentElement.remove( this.el )
129+
this.data.dom.parentElement.remove()
130+
return false
131+
},
132+
133+
119134
// the buttons don't work in XR because HTMLMesh does not understand onclick on divs
120135
patchButtons: function(e){
121136
let wEl = e.mount;
122137
let controls = [...wEl.closest(".winbox").querySelectorAll(".wb-control span")]
123138
controls.map( (c) => {
124-
if( c.className == "wb-close"){
139+
if( c.className.match(/wb-(close|min)/) ){
125140
let btn = document.createElement("button")
126-
btn.className = "xr-close"
127-
btn.innerText = "x"
141+
btn.className = `xr xr-${c.className}`
142+
btn.innerText = c.className == "wb-close" ? "x" : "_"
128143
btn.addEventListener("click", (e) => { } )// this will bubble up (to click ancestor in XR)
129144
c.appendChild(btn)
130145
}

0 commit comments

Comments
 (0)