From 97d495647b8da5706355d33865ba8a4ef18225d2 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Sat, 3 Mar 2018 10:16:52 +0100 Subject: [PATCH] input/text: add align & wrap props (feature request #176) --- CHANGELOG.md | 2 ++ resources/docs/widgets/inputs.md | 5 +++++ resources/docs/widgets/plots.md | 10 ++++++++++ src/browser/js/app/widgets/inputs/input.js | 8 +++++--- src/browser/js/app/widgets/plots/text.js | 5 +++++ src/browser/scss/widgets/_inputs.scss | 6 ++++++ src/browser/scss/widgets/_plots.scss | 18 ++++++++++++++++-- 7 files changed, 49 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0eaf2390..95d3f4da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ - knob: big knobs design tweaks - **new** `default` property that sets a widgets initial/doubleTap/spring value. The `value` property does no longer serve this purpose. - property inheritance: `@{widget_id.value}`, `@{widget_id}` and `@{widget_id._value}` now all refer to the widget's current value (the latter being kept for backward compatibility) + - text: added `align` and `wrap` properties + - input: added `align` property - editor - allow selecting multiple widgets (`ctrl + click`) if they share the same parent. Context-menu and sidepanel editing actions apply to all selected widgets diff --git a/resources/docs/widgets/inputs.md b/resources/docs/widgets/inputs.md index 8b71b9e3..86d32231 100644 --- a/resources/docs/widgets/inputs.md +++ b/resources/docs/widgets/inputs.md @@ -20,6 +20,11 @@ - default: `false` - usage: set to `true` to display the input horizontally +### `align` +- type: `string` +- default: `''` +- usage: set to `left` or `right` to change text alignment (otherwise `center`) + ### `unit` - type: `string` - default: `empty` diff --git a/resources/docs/widgets/plots.md b/resources/docs/widgets/plots.md index 1cebf0c4..b0465ce3 100644 --- a/resources/docs/widgets/plots.md +++ b/resources/docs/widgets/plots.md @@ -196,6 +196,16 @@ Text displays incoming values (via osc) as text. Sending a message with no argum - default: `false` - usage: set to `true` display vertically +### `wrap` +- type: `boolean` +- default: `false` +- usage: set to `true` to wrap long lines automatically + +### `align` +- type: `string` +- default: `''` +- usage: set to `left` or `right` to change text alignment (otherwise `center`) + ## Meter Meter displays incoming numerical values (via osc) as a gauge level diff --git a/src/browser/js/app/widgets/inputs/input.js b/src/browser/js/app/widgets/inputs/input.js index 61fdd125..6cc0e365 100644 --- a/src/browser/js/app/widgets/inputs/input.js +++ b/src/browser/js/app/widgets/inputs/input.js @@ -28,6 +28,7 @@ module.exports = class Input extends Canvas { _input:'input', vertical:false, + align: '', unit: '', editable:true, @@ -59,9 +60,10 @@ module.exports = class Input extends Canvas { this.stringValue = '' this.focused = false - if (this.getProp('vertical')) { - this.widget.classList.add('vertical') - } + if (this.getProp('vertical')) this.widget.classList.add('vertical') + if (this.getProp('align') === 'left') this.widget.classList.add('left') + if (this.getProp('align') === 'right') this.widget.classList.add('right') + if (this.getProp('editable')) { this.canvas.setAttribute('tabindex', 0) diff --git a/src/browser/js/app/widgets/plots/text.js b/src/browser/js/app/widgets/plots/text.js index 27822b75..f3af847a 100644 --- a/src/browser/js/app/widgets/plots/text.js +++ b/src/browser/js/app/widgets/plots/text.js @@ -27,6 +27,8 @@ module.exports = class Text extends Widget { _text: 'text', vertical:false, + wrap:false, + align:'', _value: 'value', default: '', @@ -50,6 +52,9 @@ module.exports = class Text extends Widget { super({...options, html: '
'}) if (this.getProp('vertical')) this.widget.classList.add('vertical') + if (this.getProp('align') === 'left') this.widget.classList.add('left') + if (this.getProp('align') === 'right') this.widget.classList.add('right') + if (this.getProp('wrap')) this.widget.classList.add('wrap') this.defaultValue = this.getProp('value') || ( this.getProp('label')===false ? this.getProp('id'): diff --git a/src/browser/scss/widgets/_inputs.scss b/src/browser/scss/widgets/_inputs.scss index 03b4998c..fc7cf755 100644 --- a/src/browser/scss/widgets/_inputs.scss +++ b/src/browser/scss/widgets/_inputs.scss @@ -30,6 +30,12 @@ padding:1rem; border: 1rem solid var(--color-bg); background: var(--color-track); + &.right { + text-align: right; + } + &.left { + text-align: left; + } input { display: block; flex:1; diff --git a/src/browser/scss/widgets/_plots.scss b/src/browser/scss/widgets/_plots.scss index dc9c503d..b32c9080 100644 --- a/src/browser/scss/widgets/_plots.scss +++ b/src/browser/scss/widgets/_plots.scss @@ -70,9 +70,19 @@ display: flex; align-items: center; white-space: pre; + word-break: break-all; background: var(--color-track); color:var(--color-custom); border: 1rem solid var(--color-bg); + &.right { + justify-content: flex-end; + } + &.left { + justify-content: flex-start; + } + &.wrap { + white-space: pre-wrap; + } &.vertical { transform: rotate(180deg); text-overflow: ellipsis; @@ -155,11 +165,15 @@ --color-border:transparent; padding: 0rem; .plot, .text, .led, .image, .svg { - padding: 0rem; margin: 1rem; - background-clip: content-box; box-shadow: 0 0 0 1rem var(--color-fg); outline:1rem solid var(--color-light); border: 1rem solid var(--color-bg); } } + +.panel:not(.tab) > .image-container { + .image { + background-clip: content-box; + } +}