Skip to content

Commit

Permalink
revert user interface
Browse files Browse the repository at this point in the history
  • Loading branch information
marklundin committed Sep 17, 2024
1 parent 75cac59 commit 6087ea8
Showing 1 changed file with 1 addition and 60 deletions.
61 changes: 1 addition & 60 deletions docs/user-manual/user-interface/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,36 +93,6 @@ this.entity.element.on('click', function (event) {

Calling `stopPropagation` will also stop the event from being handled by the other input devices like `pc.Mouse` or `pc.TouchDevice`. So if for example you are handling mouse input using `app.mouse.wasPressed`, you can call `stopPropagation` on the `mousedown` event to prevent `app.mouse.wasPressed` from returning true. For example:

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

<Tabs defaultValue="legacy" groupId='script-code'>
<TabItem value="esm" label="ESM">

```javascript
import { ScriptType, MOUSEBUTTON_LEFT } from 'playcanvas';

export class InputScript extends Script {
initialize() {
this.entity.element.on('mousedown', (evt) => {
evt.stopPropagation();
}, this);
}

update(dt) {
if (this.app.mouse.wasPressed(MOUSEBUTTON_LEFT)) {
// do something when the left button was pressed.
// this will not be called if the button was pressed on the Element
// because we call stopPropagation
}
}
}

```

</TabItem>
<TabItem value="legacy" label="Legacy">

```javascript
var InputScript = pc.createScript('inputScript');

Expand All @@ -141,9 +111,6 @@ InputScript.prototype.update = function (dt) {
}
```

</TabItem>
</Tabs>

## Mouse and Touch event conflict on Google Chrome

Google Chrome simulates mouse events also on touch devices. By doing so it could cause some unexpected behavior. For example if you hide a button right after the click event, another UI element that lays behind it could also receive an unwanted click event.
Expand All @@ -152,30 +119,7 @@ To prevent this behavior you can call the ```preventDefault()``` method of the n

Here is small script to include once in your scene:

<Tabs defaultValue="legacy" groupId='script-code'>
<TabItem value="esm" label="ESM">

```javascript
import { ScriptType, EVENT_TOUCHEND } from 'playcanvas';

export class TouchFix extends Script {
initialize () {
// Only register touch events if the device supports touch
const touch = this.app.touch;
if (touch) {
touch.on(EVENT_TOUCHEND, function(event) {
// This prevents that a mouse click event will be executed after a touch event.
event.event.preventDefault();
});
}
}
}
```

</TabItem>
<TabItem value="legacy" label="Legacy">

```javascript
```javascript
var TouchFix = pc.createScript('touchFix');

// initialize code called once per entity
Expand All @@ -191,7 +135,4 @@ TouchFix.prototype.initialize = function() {
};
```

</TabItem>
</Tabs>

[1]: /user-manual/scenes/components/element/

0 comments on commit 6087ea8

Please sign in to comment.