widgets/editor: add lock property

This commit is contained in:
jean-emmanuel 2022-02-12 12:16:29 +01:00
parent fb223eb08c
commit 46ba4115af
10 changed files with 59 additions and 4 deletions

View file

@ -5,6 +5,9 @@
- bug fixes
- editor: prevent accessing non-editable widgets with right arrow
- widgets
- add `lock` property to all widgets
## 1.14.6
- bug fixes

View file

@ -11,7 +11,7 @@ When osc messages are received, the default behavior is to update the value of a
#### `/EDIT id properties options`
Apply a set of options to an existing widget by replacing the old ones with the new ones.
Apply a set of options to an existing widget by replacing the old ones with the new ones. This ignores the widget's `lock` property.
- `id`: `string`, widget's `id`

View file

@ -42,6 +42,8 @@ Selected widget's properties are displayed and can be modified in the inspector.
Some properties (for example `onValue`) have a special code editor with syntax hilighting and many keyboard shortcuts (available by clicking on the "Help" button). In this properties, pressing `enter` will not submit pending changes and instead insert a new line at the cursor position (as you would expect in a regular editor). To submit pending changes, press ++ctrl+enter++ (or ++cmd+enter== on Mac) or click outside the editor.
Widgets can be locked for edition by enabling their `lock` property. When locked, a widget can't be modified by the editor but it remains possible to delete it or to move it from a container to another in the project tree.
## Project tree
@ -49,6 +51,8 @@ The project tree displays the whole widget structure of the session. Widgets can
The "Filter" input allows filtering displayed widgets by their `id`. It's also possible to only display a single type of widget by typing `type:fader` for example.
Invisible widgets are displayed with a lower opacity and their name in italic. Locked widgets are displayed with a lock icon after their name.
## Widget resizing / dragging
Selected widget can be resized using its south, south-east and east handles. It can be dragged with its north-west handle (holding ++alt++ extends this handle to the widget's size to ease dragging). If the widget's position/size was written in percents, the editor will try to keep using percents.

View file

@ -33,6 +33,11 @@ class Editor {
newWidgets = [],
error = false
if (this.selectedWidgets.some(w=>w.getProp('lock')) && propName !== 'lock') {
this.select(this.selectedWidgets)
return
}
for (var w of this.selectedWidgets) {
let previousValue = w.props[propName]
@ -557,6 +562,16 @@ class Editor {
}
var parent = this.selectedWidgets[0].parent,
parentLock = false
while (parent !== widgetManager) {
if (parent.getProp('lock')) {
this.selectedWidgets = [parent]
parentLock = true
}
parent = parent.parent
}
if (options.fromLasso && !options.lassoEnd) return
this.unselect()
@ -818,6 +833,11 @@ class Editor {
if (!this.selectedWidgets.length) return
if (this.selectedWidgets.some(w=>w.getProp('lock'))) {
this.createSelectionBlock()
return
}
var newWidgets = [],
area = this.widgetDragResize,
changedProps = []
@ -891,6 +911,11 @@ class Editor {
if (!this.selectedWidgets.length) return
if (this.selectedWidgets.some(w=>w.getProp('lock'))) {
this.createSelectionBlock()
return
}
var newWidgets = []
for (var w of this.selectedWidgets) {

View file

@ -17,7 +17,7 @@ class UiInspectorField extends UiWidget {
this.default = options.default
this.tabIndex = options.tabIndex
this.container = html`<osc-inspector-field></osc-inspector-field>`
this.container = html`<osc-inspector-field name="${this.name}"></osc-inspector-field>`
this.label = this.container.appendChild(html`<label>${this.name}</label>`)
if (this.name === 'type' || this.name === 'widgetType') this.createTypeSelect()

View file

@ -117,15 +117,17 @@ class UiInspector extends UiWidget {
this.clearTimeout = null
}
var content = html`<div></div>`
var widget = widgets[0],
lock = widgets.some(w=>w.getProp('lock')),
props = defaults[widget.props.type],
tabIndex = 1000,
codeEditorFields = []
this.widget = widget
var content = html`<div class="${lock ? 'lock' : ''}"></div>`
for (let categoryName in props) {
if (categoryName === 'children') continue

View file

@ -265,7 +265,7 @@ class UiTree extends UiWidget {
id = widget.getProp('id'),
node = html`<li class="${selected ? 'editing' : ''} ${!widget.getProp('visible') ? 'invisible' : ''}"
data-widget="${widget.hash}" data-type="${widget.getProp('type')}">
${raw(icon(widgetIcons[widget.getProp('type')] || 'root'))}${id}</li>`
${raw(icon(widgetIcons[widget.getProp('type')] || 'root'))}${id}${widget.getProp('lock')? raw(icon('lock')) :''}</li>`
node.depth = depth

View file

@ -54,6 +54,7 @@ class Widget extends EventEmitter {
var defaults = {
widget: {
lock: {type: 'boolean', value: false, help: 'Set to `true` to prevent modifying this widget with the editor. This will not prevent deleting the widget or moving it from a container to another.'},
type: {type: 'string', value: 'auto', help: 'Widget type'},
id: {type: 'string', value: 'auto', help: 'Widgets sharing the same `id` will act as clones and update each other\'s value(s) without sending extra osc messages.' },
visible: {type: 'boolean', value: true, help: 'Set to `false` to hide the widget.'},

View file

@ -17,6 +17,19 @@ osc-panel-container.right.editor-breakout {
--widget-padding: -1rem;
.lock {
osc-inspector-field {
filter: saturate(0);
pointer-events: none;
opacity: 0.65;
}
osc-inspector-field[name=lock] {
filter: none;
pointer-events: auto;
opacity: 1.0;
}
}
}
osc-inspector-field {

View file

@ -112,6 +112,13 @@
// right: -12rem;
// }
}
.fa-lock {
position: relative;
margin-left: 4rem;
top:0;
font-size: 80%;
opacity: 0.8;
}
}