canvas: expose touch events for extra elements added with the html propery
This commit is contained in:
parent
6b76631003
commit
4ce9506e91
6 changed files with 27 additions and 12 deletions
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
- widgets
|
||||
- canvas: expose touch pressure (as `event.force`) in the `touch` script.
|
||||
- canvas: expose touch events for extra elements added with the `html` propery
|
||||
|
||||
## 1.13.1
|
||||
|
||||
|
|
|
|||
|
|
@ -33,18 +33,24 @@ This script is executed when the widget is touched, when it is released, and dur
|
|||
This script has access to the same variables and functions as the `script` property (except the event-specific ones), plus the following:
|
||||
|
||||
- `value`: widget value
|
||||
- `width`: widget width in pixels
|
||||
- `height`: widget height in pixels
|
||||
- `width`: canvas width in pixels
|
||||
- `height`: canvas height in pixels
|
||||
- `event`: object containing the following:
|
||||
- `type`: `"start"`, `"move"` or `"stop"`
|
||||
- `target`: id of the widget under the pointer, `"this"` if it's the canvas widget itself, `null` if no widget is under the pointer
|
||||
- `offsetX`, `offsetY`: touch coordinates in pixels, relative to `target`
|
||||
- `targetName`: name attribute of the html element under the pointer
|
||||
- `targetTagName`: tag name of the html element under the pointer
|
||||
- `offsetX`, `offsetY`: touch coordinates in pixels, relative to the html element under the pointer
|
||||
- `movementX`, `movementY`: movement of the pointer in pixels since the last event
|
||||
- `pointerId`: unique identifier used to differenciate fingers in multitouch situation
|
||||
- `altKey`, `ctrlKey`, `shiftKey`: keyboard modifier states
|
||||
- `force`: amount of pressure applied to the touch surface between `0` and `1` (see [Touch.force](https://developer.mozilla.org/en-US/docs/Web/API/Touch/force)). Equals `0` if the API is not supported or if no pressure information is found.
|
||||
|
||||
|
||||
!!! note "Extra html elements"
|
||||
Elements added using the `html` property can be touched as well, `event.targetName` can be used to determine which element is touched.
|
||||
|
||||
|
||||
### `draw`
|
||||
|
||||
This script is executed when the widget should be redrawn, which is when it's touched and when it receives a value.
|
||||
|
|
@ -52,8 +58,8 @@ This script is executed when the widget should be redrawn, which is when it's to
|
|||
This script has access to the same variables and functions as the `script` property (except the event-specific ones), plus the following:
|
||||
|
||||
- `value`: widget value
|
||||
- `width`: widget width in pixels
|
||||
- `height`: widget height in pixels
|
||||
- `width`: canvas width in pixels
|
||||
- `height`: canvas height in pixels
|
||||
- `ctx`: [canvas rendering context](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D) of the widget
|
||||
- `cssVars`: object containing the computed value of some of the widget's style properties such as `colorWidget`, `alphaFill`, `padding`, etc
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@
|
|||
| <h6 id="alphaFillOn">alphaFillOn<sup><i class="fas fa-bolt" title="dynamic"></i></sup><a class="headerlink" href="#alphaFillOn" title="Permanent link">#</a></h6> | `number` | <code>"auto"</code> | Fill color opacity (on). |
|
||||
| <h6 id="lineWidth">lineWidth<sup><i class="fas fa-bolt" title="dynamic"></i></sup><a class="headerlink" href="#lineWidth" title="Permanent link">#</a></h6> | `number` | <code>"auto"</code> | Stroke width. |
|
||||
| <h6 id="padding">padding<sup><i class="fas fa-bolt" title="dynamic"></i></sup><a class="headerlink" href="#padding" title="Permanent link">#</a></h6> | `number` | <code>"auto"</code> | Inner spacing. |
|
||||
| <h6 id="html">html<sup><i class="fas fa-bolt" title="dynamic"></i></sup><a class="headerlink" href="#html" title="Permanent link">#</a></h6> | `string` | <code>""</code> | Custom html content to be inserted in the widget (before the widget's content). Elements are all unstyled by default, `css` should be used to customize their appearance.<br/><br/>The code is automatically wrapped in <div class="html"></div><br/><br/>Allowed HTML tags:<br/><br/> h1-6, blockquote, p, a, ul, ol, nl, li,<br/><br/> b, i, strong, em, strike, code, hr, br, div,<br/><br/> table, thead, img, caption, tbody, tr, th, td, pre<br/><br/>Allowed attributes:<br/><br/> <*>: class, style, title<br/><br/> <img>: src, width, height |
|
||||
| <h6 id="html">html<sup><i class="fas fa-bolt" title="dynamic"></i></sup><a class="headerlink" href="#html" title="Permanent link">#</a></h6> | `string` | <code>""</code> | Custom html content to be inserted in the widget (before the widget's content). Elements are all unstyled by default, `css` should be used to customize their appearance.<br/><br/>The code is automatically wrapped in <div class="html"></div><br/><br/>Allowed HTML tags:<br/><br/> h1-6, blockquote, p, a, ul, ol, nl, li,<br/><br/> b, i, strong, em, strike, code, hr, br, div,<br/><br/> table, thead, img, caption, tbody, tr, th, td, pre<br/><br/>Allowed attributes:<br/><br/> <*>: class, style, title, name<br/><br/> <img>: src, width, height |
|
||||
| <h6 id="css">css<sup><i class="fas fa-bolt" title="dynamic"></i></sup><a class="headerlink" href="#css" title="Permanent link">#</a></h6> | `string` | <code>""</code> | CSS rules. See <a href="https://openstagecontrol.ammd.net/docs/customization/css-tips/">documentation</a>.<br/><br/>Some style-related properties can be set or read from css using css variables:<br/>- `--color-background`: `colorBg`<br/>- `--color-widget`: `colorWidget`<br/>- `--color-fill`: `colorFill`<br/>- `--color-stroke`: `colorStroke`<br/>- `--color-text`: `colorText`<br/>- `--widget-padding`: `padding`<br/>- `--line-width`: `lineWidth`<br/>- `--alpha-fill-on`: `alphaFillOn`<br/>- `--alpha-fill-off`: `alphaFillOff`<br/>- `--alpha-stroke`: `alphaStroke` |
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ class Widget extends EventEmitter {
|
|||
' b, i, strong, em, strike, code, hr, br, div,',
|
||||
' table, thead, img, caption, tbody, tr, th, td, pre',
|
||||
'Allowed attributes:',
|
||||
' <*>: class, style, title',
|
||||
' <*>: class, style, title, name',
|
||||
' <img>: src, width, height',
|
||||
]},
|
||||
css: {type: 'string', value: '', help: [
|
||||
|
|
@ -1192,7 +1192,7 @@ class Widget extends EventEmitter {
|
|||
Widget.sanitizeHtmlOptions = {
|
||||
allowedTags: sanitizeHtml.defaults.allowedTags.concat(['img', 'h1', 'h2']).filter(x=>x!=='iframe'),
|
||||
allowedAttributes: {
|
||||
'*': [ 'title', 'class', 'style'],
|
||||
'*': [ 'title', 'class', 'style', 'name'],
|
||||
'img': [ 'src' , 'title', 'class', 'style', 'width', 'height'],
|
||||
'a': ['href', 'target']
|
||||
},
|
||||
|
|
|
|||
|
|
@ -75,6 +75,8 @@ class CanvasWidget extends Canvas {
|
|||
|
||||
var event = {...e}
|
||||
delete event.firstTarget
|
||||
event.targetName = event.target.getAttribute('name')
|
||||
event.targetTagName = event.target.tagName
|
||||
var w = widgetManager.getWidgetByElement(event.target)
|
||||
if (w) event.target = w === this ? 'this' : w.getProp('id')
|
||||
else event.target = null
|
||||
|
|
@ -92,15 +94,15 @@ class CanvasWidget extends Canvas {
|
|||
|
||||
this.on('draginit',(e)=>{
|
||||
touchCb(e, 'start')
|
||||
}, {element: this.widget, multitouch: true})
|
||||
}, {element: this.container, multitouch: true})
|
||||
|
||||
this.on('drag',(e)=>{
|
||||
touchCb(e, 'move')
|
||||
}, {element: this.widget, multitouch: true})
|
||||
}, {element: this.container, multitouch: true})
|
||||
|
||||
this.on('dragend',(e)=>{
|
||||
touchCb(e, 'stop')
|
||||
}, {element: this.widget, multitouch: true})
|
||||
}, {element: this.container, multitouch: true})
|
||||
|
||||
if (this.getProp('continuous')) {
|
||||
var freq = parseInt(this.getProp('continuous')) || 30
|
||||
|
|
@ -131,6 +133,8 @@ class CanvasWidget extends Canvas {
|
|||
|
||||
draw() {
|
||||
|
||||
if (!this.getProp('draw')) return
|
||||
|
||||
if (this.getProp('autoClear')) {
|
||||
this.clear()
|
||||
this.ctx.beginPath()
|
||||
|
|
@ -143,6 +147,7 @@ class CanvasWidget extends Canvas {
|
|||
height: this.height,
|
||||
cssVars: this.cssVars
|
||||
}, {sync: false, send: false})
|
||||
|
||||
this.batchDraw()
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -134,7 +134,10 @@
|
|||
--alpha-fill-on: 0.75;
|
||||
--alpha-fill: var(--alpha-fill-off);
|
||||
--widget-padding: 0rem;
|
||||
|
||||
.html {
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
inner {
|
||||
position: relative;
|
||||
flex: 1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue