image: add repeat option; add docs

text: fix default value (retreive value prop)
This commit is contained in:
jean-emmanuel 2017-12-19 09:46:30 +01:00
parent e1e54c038b
commit 1c3389d736
5 changed files with 71 additions and 11 deletions

View file

@ -10,6 +10,8 @@
- added `--instance-name` option to differenciate mulitple instances in zeroconf networks
- widgets
- **new** `range` widget
- **new** `image` widget
- sending an empty message to a `text` widget resets it to its initial value
- misc
- absolute file paths in widgets' background images urls are now properly resolved

View file

@ -227,3 +227,50 @@ Meter displays incoming numerical values (via osc) as a gauge level
### `logScale`
- see fader's [`logScale`](sliders/#fader)
## Image
Image displays an image from a file path/url or from a base64 encoded image string. Sending an empty message resets the widget to its initial `value`.
```js
{
type:'image',
// etc
}
```
### `size`
- type: `string`
- default: `cover`
- usage: css [background-size](https://www.w3schools.com/CSSref/css3_pr_background-size.asp)
### `position`
- type: `string`
- default: `cover`
- usage: css [background-position](https://www.w3schools.com/CSSref/pr_background-position.asp)
### `repeat`
- type: `string`
- default: `no-repeat`
- usage: css [background-repeat](https://www.w3schools.com/CSSref/pr_background-repeat.asp)
### `border`
- type: `boolean`
- default: `false`
- usage: set to `true` to disable the image's borders and background-color.
### `cache`
- type: `boolean`
- default: `true`
- usage: set to `false` to disable image caching (forces file reload when updating or editing the widget). When `true`, sending `'reload'` to the widget reloads its image without changing its value.
### `value`
- type: `string`
- default: `empty`
- usage : initial image
- file url or absolute path
- [base64 encoded image](https://duckduckgo.com/?q=base64+encode+image&ia=web) : `data:image/...`

View file

@ -122,10 +122,11 @@ var Parser = class Parser {
widgetContainer.find('> .label').html(label)
}
// parse scoped css
// parse css
var css = ';' + widgetInner.getProp('css'),
scopedCss = ''
// parse scoped css
css = css.replace(/[;\}\s]*([^;\{]*\{[^\}]*\})/g, (m)=>{
m = m.replace(/^[;\}\s]*/,'')
if (m[0]=='&') {

View file

@ -26,6 +26,7 @@ module.exports = class Led extends _widgets_base {
size: 'cover',
position: 'center',
repeat: 'no-repeat',
border: true,
cache: true,
value:'',
@ -51,26 +52,35 @@ module.exports = class Led extends _widgets_base {
this.widget[0].style.setProperty('background-size', this.getProp('size'))
this.widget[0].style.setProperty('background-position', this.getProp('position'))
this.widget[0].style.setProperty('background-repeat', this.getProp('repeat'))
}
setValue(v) {
var s = '' + v
var s = v==null ? '' : '' + v,
cache_query = ''
this.value = s
if (!s.length) {
this.value = this.getProp('value')
} else if (s != 'reload') {
if (s.length > 1) this.value = s
}
if (this.value.length) {
var cache_query = this.getProp('cache') || s.indexOf('base64') != -1 ? '' : (s.indexOf('?') != -1 ? '&' : '?') + Date.now()
this.widget[0].style.setProperty('background-image', `url(${s}${cache_query})`)
} else {
this.widget[0].style.setProperty('background-image', '')
cache_query = this.getProp('cache') || this.value.indexOf('base64') != -1 ?
'' : (this.value.indexOf('?') != -1 ? '&' : '?') + Date.now()
}
this.widget[0].style.setProperty('background-image', `url(${this.value}${cache_query})`)
}
}

View file

@ -43,11 +43,11 @@ module.exports = class Text extends _widgets_base {
if (this.getProp('vertical')) this.widget.addClass('vertical')
this.defaultValue = this.getProp('label')===false?
this.defaultValue = this.getProp('value') || ( this.getProp('label')===false ?
this.getProp('id'):
this.getProp('label')=='auto'?
this.getProp('id'):
this.getProp('label')
this.getProp('label') )
this.value = this.defaultValue