window buttons in XR (better)
This commit is contained in:
parent
55883df288
commit
c3d9b7aaed
4 changed files with 64 additions and 22 deletions
|
|
@ -81,7 +81,7 @@ AFRAME.registerComponent('helloworld-window', {
|
||||||
},
|
},
|
||||||
|
|
||||||
DOMready: function(){
|
DOMready: function(){
|
||||||
this.el.setAttribute("window", `title: XRSH; uid: ${this.el.uid}; attach: #overlay; dom: #${this.el.dom.id}; width:250; height: 360`)
|
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`)
|
||||||
|
|
||||||
// data2event demo
|
// data2event demo
|
||||||
this.el.setAttribute("data2event","")
|
this.el.setAttribute("data2event","")
|
||||||
|
|
@ -89,6 +89,21 @@ AFRAME.registerComponent('helloworld-window', {
|
||||||
this.data.foo = `this.el ${this.el.uid}: `
|
this.data.foo = `this.el ${this.el.uid}: `
|
||||||
setInterval( () => this.data.myvalue++, 500 )
|
setInterval( () => this.data.myvalue++, 500 )
|
||||||
|
|
||||||
|
// if you want your launch-icon to stick around after
|
||||||
|
// closing the window, then register it manually
|
||||||
|
window.launcher.register({
|
||||||
|
component: "helloworld-window",
|
||||||
|
...this.manifest,
|
||||||
|
icon: this.manifest.icons[0].src,
|
||||||
|
cb: () => {
|
||||||
|
const el = document.createElement("a-entity")
|
||||||
|
el.setAttribute("helloworld-window","")
|
||||||
|
el.setAttribute("pressable","")
|
||||||
|
el.setAttribute("position","0 1.6 0")
|
||||||
|
AFRAME.scenes[0].appendChild(el)
|
||||||
|
setTimeout( () => el.emit('launcher',null,false), 100 )
|
||||||
|
}
|
||||||
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
"window.oncreate": function(){
|
"window.oncreate": function(){
|
||||||
|
|
|
||||||
|
|
@ -145,6 +145,7 @@ if( typeof AFRAME != 'undefined '){
|
||||||
.isoterminal{
|
.isoterminal{
|
||||||
padding: ${me.com.data.padding}px;
|
padding: ${me.com.data.padding}px;
|
||||||
margin-top:-60px;
|
margin-top:-60px;
|
||||||
|
padding-bottom:60px;
|
||||||
width:100%;
|
width:100%;
|
||||||
height:99%;
|
height:99%;
|
||||||
resize: both;
|
resize: both;
|
||||||
|
|
@ -257,7 +258,7 @@ if( typeof AFRAME != 'undefined '){
|
||||||
}
|
}
|
||||||
|
|
||||||
.XR .isoterminal{
|
.XR .isoterminal{
|
||||||
background: transparent;
|
background: #000 !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.isoterminal *{
|
.isoterminal *{
|
||||||
|
|
@ -346,7 +347,7 @@ if( typeof AFRAME != 'undefined '){
|
||||||
this.term.emit('term_init', {instance, aEntity:this})
|
this.term.emit('term_init', {instance, aEntity:this})
|
||||||
//instance.winbox.resize(720,380)
|
//instance.winbox.resize(720,380)
|
||||||
let size = `width: ${this.data.width}; height: ${this.data.height}`
|
let size = `width: ${this.data.width}; height: ${this.data.height}`
|
||||||
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}`)
|
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}`)
|
||||||
})
|
})
|
||||||
|
|
||||||
instance.addEventListener('window.oncreate', (e) => {
|
instance.addEventListener('window.oncreate', (e) => {
|
||||||
|
|
@ -502,6 +503,7 @@ if( typeof AFRAME != 'undefined '){
|
||||||
"scope": "/",
|
"scope": "/",
|
||||||
"theme_color": "#3367D6",
|
"theme_color": "#3367D6",
|
||||||
"shortcuts": [
|
"shortcuts": [
|
||||||
|
/*
|
||||||
{
|
{
|
||||||
"name": "What is the latest news?",
|
"name": "What is the latest news?",
|
||||||
"cli":{
|
"cli":{
|
||||||
|
|
@ -516,8 +518,9 @@ if( typeof AFRAME != 'undefined '){
|
||||||
"url": "/today?source=pwa",
|
"url": "/today?source=pwa",
|
||||||
"icons": [{ "src": "/images/today.png", "sizes": "192x192" }]
|
"icons": [{ "src": "/images/today.png", "sizes": "192x192" }]
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
],
|
],
|
||||||
"description": "Hello world information",
|
"description": "Runs an .iso file",
|
||||||
"screenshots": [
|
"screenshots": [
|
||||||
{
|
{
|
||||||
"src": "/images/screenshot1.png",
|
"src": "/images/screenshot1.png",
|
||||||
|
|
@ -527,7 +530,7 @@ if( typeof AFRAME != 'undefined '){
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"help":`
|
"help":`
|
||||||
Helloworld application
|
XRSH application
|
||||||
|
|
||||||
This is a help file which describes the application.
|
This is a help file which describes the application.
|
||||||
It will be rendered thru troika text, and will contain
|
It will be rendered thru troika text, and will contain
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,9 @@
|
||||||
*
|
*
|
||||||
* displays app (icons) in 2D and 3D handmenu (enduser can launch desktop-like 'apps')
|
* displays app (icons) in 2D and 3D handmenu (enduser can launch desktop-like 'apps')
|
||||||
*
|
*
|
||||||
|
* They can be temporary processes (icon disappears after component is removed) or permanent icons
|
||||||
|
* when registered via .register({...})
|
||||||
|
*
|
||||||
* ```html
|
* ```html
|
||||||
* <a-entity launcher>
|
* <a-entity launcher>
|
||||||
* <a-entity launch="component: helloworld; foo: bar"><a-entity>
|
* <a-entity launch="component: helloworld; foo: bar"><a-entity>
|
||||||
|
|
@ -340,7 +343,10 @@ AFRAME.registerSystem('launcher',{
|
||||||
];
|
];
|
||||||
|
|
||||||
// collect manually registered launchables
|
// collect manually registered launchables
|
||||||
this.registered.map( (launchable) => this.launchables.push(launchable) )
|
this.registered.map( (launchable) => {
|
||||||
|
if( launchable.component ) seen[ launchable.component ] = true
|
||||||
|
this.launchables.push(launchable)
|
||||||
|
})
|
||||||
|
|
||||||
// collect launchables in aframe dom elements
|
// collect launchables in aframe dom elements
|
||||||
this.dom = els.filter( (el) => {
|
this.dom = els.filter( (el) => {
|
||||||
|
|
@ -349,8 +355,11 @@ AFRAME.registerSystem('launcher',{
|
||||||
for( let i in el.components ){
|
for( let i in el.components ){
|
||||||
if( el.components[i].events && el.components[i].events[searchEvent] && !seen[i] ){
|
if( el.components[i].events && el.components[i].events[searchEvent] && !seen[i] ){
|
||||||
let com = hasEvent = seen[i] = el.components[i]
|
let com = hasEvent = seen[i] = el.components[i]
|
||||||
com.launcher = () => com.el.emit('launcher',null,false) // important: no bubble
|
let alreadyAdded = this.launchables.find( (l) => l.manifest.name == com.manifest.name )
|
||||||
this.launchables.push(com)
|
if( !alreadyAdded ){
|
||||||
|
com.launcher = () => com.el.emit('launcher',null,false) // important: no bubble
|
||||||
|
this.launchables.push({manifest: com.manifest, launcher: com.launcher})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,16 +53,6 @@ AFRAME.registerComponent('window', {
|
||||||
setupWindow: async function(){
|
setupWindow: async function(){
|
||||||
await AFRAME.utils.require(this.dependencies)
|
await AFRAME.utils.require(this.dependencies)
|
||||||
if( !this.el.dom ) return console.error('window element requires dom-component as dependency')
|
if( !this.el.dom ) return console.error('window element requires dom-component as dependency')
|
||||||
|
|
||||||
const close = () => {
|
|
||||||
let e = {halt:false}
|
|
||||||
this.el.emit('window.onclose',e)
|
|
||||||
if( e.halt ) return true
|
|
||||||
this.data.dom.style.display = 'none';
|
|
||||||
if( this.el.parentNode ) this.el.remove() //parentElement.remove( this.el )
|
|
||||||
this.data.dom.parentElement.remove()
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
this.el.addEventListener('close', () => {
|
this.el.addEventListener('close', () => {
|
||||||
close()
|
close()
|
||||||
this.el.winbox.close()
|
this.el.winbox.close()
|
||||||
|
|
@ -94,7 +84,9 @@ AFRAME.registerComponent('window', {
|
||||||
|
|
||||||
this.patchButtons(e)
|
this.patchButtons(e)
|
||||||
},
|
},
|
||||||
onclose: close
|
onminimize: this.onminimize,
|
||||||
|
onrestore: this.onrestore,
|
||||||
|
onclose: this.onclose.bind(this),
|
||||||
|
|
||||||
});
|
});
|
||||||
this.data.dom.style.display = '' // show
|
this.data.dom.style.display = '' // show
|
||||||
|
|
@ -116,15 +108,38 @@ AFRAME.registerComponent('window', {
|
||||||
this.el.dom.closest('.winbox').style.display = state ? '' : 'none'
|
this.el.dom.closest('.winbox').style.display = state ? '' : 'none'
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onminimize: function(e){
|
||||||
|
if( AFRAME.scenes[0].renderer.xr.isPresenting ){
|
||||||
|
this.window.style.display = 'none'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
onrestore: function(e){
|
||||||
|
if( AFRAME.scenes[0].renderer.xr.isPresenting ){
|
||||||
|
this.window.style.display = ''
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
onclose: function(){
|
||||||
|
let e = {halt:false}
|
||||||
|
this.el.emit('window.onclose',e)
|
||||||
|
if( e.halt ) return true
|
||||||
|
this.data.dom.style.display = 'none';
|
||||||
|
if( this.el.parentNode ) this.el.remove() //parentElement.remove( this.el )
|
||||||
|
this.data.dom.parentElement.remove()
|
||||||
|
return false
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
// the buttons don't work in XR because HTMLMesh does not understand onclick on divs
|
// the buttons don't work in XR because HTMLMesh does not understand onclick on divs
|
||||||
patchButtons: function(e){
|
patchButtons: function(e){
|
||||||
let wEl = e.mount;
|
let wEl = e.mount;
|
||||||
let controls = [...wEl.closest(".winbox").querySelectorAll(".wb-control span")]
|
let controls = [...wEl.closest(".winbox").querySelectorAll(".wb-control span")]
|
||||||
controls.map( (c) => {
|
controls.map( (c) => {
|
||||||
if( c.className == "wb-close"){
|
if( c.className.match(/wb-(close|min)/) ){
|
||||||
let btn = document.createElement("button")
|
let btn = document.createElement("button")
|
||||||
btn.className = "xr-close"
|
btn.className = `xr xr-${c.className}`
|
||||||
btn.innerText = "x"
|
btn.innerText = c.className == "wb-close" ? "x" : "_"
|
||||||
btn.addEventListener("click", (e) => { } )// this will bubble up (to click ancestor in XR)
|
btn.addEventListener("click", (e) => { } )// this will bubble up (to click ancestor in XR)
|
||||||
c.appendChild(btn)
|
c.appendChild(btn)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue