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

@ -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;
}
}