From 97101f80fe7065650da050f190cef1897e7709e5 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Tue, 19 Dec 2017 09:46:30 +0100 Subject: [PATCH] image: add repeat option; add docs text: fix default value (retreive value prop) --- CHANGELOG.md | 2 + resources/docs/widgets/plots.md | 47 +++++++++++++++++++++++ src/browser/js/app/parser.js | 3 +- src/browser/js/app/widgets/plots/image.js | 26 +++++++++---- src/browser/js/app/widgets/plots/text.js | 4 +- 5 files changed, 71 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c04ce3a9..36d2059e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/resources/docs/widgets/plots.md b/resources/docs/widgets/plots.md index c7885ca6..9de40718 100644 --- a/resources/docs/widgets/plots.md +++ b/resources/docs/widgets/plots.md @@ -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/...` diff --git a/src/browser/js/app/parser.js b/src/browser/js/app/parser.js index 65ec4334..348bce42 100644 --- a/src/browser/js/app/parser.js +++ b/src/browser/js/app/parser.js @@ -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]=='&') { diff --git a/src/browser/js/app/widgets/plots/image.js b/src/browser/js/app/widgets/plots/image.js index 86e406f4..5095bb5c 100644 --- a/src/browser/js/app/widgets/plots/image.js +++ b/src/browser/js/app/widgets/plots/image.js @@ -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})`) + } } diff --git a/src/browser/js/app/widgets/plots/text.js b/src/browser/js/app/widgets/plots/text.js index c2ab9751..0d04c976 100644 --- a/src/browser/js/app/widgets/plots/text.js +++ b/src/browser/js/app/widgets/plots/text.js @@ -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