aframe-gui icon indicating copy to clipboard operation
aframe-gui copied to clipboard

slider does not emit an event on slider being set.

Open kylebakerio opened this issue 4 years ago • 2 comments

should probably expose a 'mouseup' event on the slider button for easy use, as you probably want to run some code once the slider is set.

happy to contribute this, but don't want to start doing a lot of pull requests while I know a lot of uncommitted code is out there waiting to be merged.

kylebakerio avatar Jan 06 '21 11:01 kylebakerio

for now, I've hacked it in this way:

(await vrgc.getElement('#command-brightness-slider')).addEventListener('mouseup', async function(el) {
  const newPercent = (await vrgc.getElement('#command-brightness-slider')).components['gui-slider'].data.percent;
  (await vrgc.getElement('[light]')).setAttribute('light', 'intensity', newPercent * 3);  // treating 3 as 100%
})

kylebakerio avatar Jan 06 '21 12:01 kylebakerio

after solving it that way, I later realized a more efficient, subtle hack:

				['onclick', `
					console.log('old slider value', this.components['gui-slider'].data.percent, this);
					(async function(el) {
						await vrgc.waitForTime(1) // ms
						console.log('new slider value', el.components['gui-slider'].data.percent, this);
					})(this)
				`],

kylebakerio avatar Jan 18 '21 13:01 kylebakerio