editor: allow multi widget drag/resize (#190)
This commit is contained in:
parent
475998fe63
commit
c85b59629f
5 changed files with 68 additions and 48 deletions
|
|
@ -11,6 +11,8 @@
|
|||
- mac: disabled unsupported pinch zoom
|
||||
- themes
|
||||
- alt-buttons: modal font-weight & color fix
|
||||
- editor
|
||||
- allow multi widget resizing/dragging
|
||||
|
||||
## 0.25.0
|
||||
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ Properties are written in JSON, with some flexibility brought by the [JSON5](htt
|
|||
|
||||
## 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.
|
||||
Selected widget can be resized using its south, south-east and east handles. It can be dragged with its north-west handle. Using this feature will convert position and size values to plain number values, thus breaking previously set percent or inherited values.
|
||||
|
||||
## Bulk editing
|
||||
|
||||
|
|
@ -49,4 +49,4 @@ When holding the `ctrl` key, multiple widgets can be selected for edition:
|
|||
|
||||
- they must share the same parent widget
|
||||
- context-menu actions and properties changes apply to all selected widgets
|
||||
- resizing / dragging will not be available
|
||||
- resizing / dragging will affect all selected widgets, relatively to the first selected widget
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ var updateWidget = function(widget, options = {}) {
|
|||
}
|
||||
}
|
||||
|
||||
if (!options.remote || editing) {
|
||||
if (!options.preventSelect && editing) {
|
||||
editor.select(newWidget)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ module.exports = function editField(editor, widget, propName, defaultValue){
|
|||
var newWidgets = []
|
||||
for (var w of editor.selectedWidgets) {
|
||||
w.props[propName] = v !== '' ? v : JSON.parse(JSON.stringify(defaultValue))
|
||||
newWidgets.push(updateWidget(w))
|
||||
newWidgets.push(updateWidget(w, {preventSelect: editor.selectedWidgets.length > 1}))
|
||||
}
|
||||
if (newWidgets.length > 1) editor.select(newWidgets)
|
||||
|
||||
|
|
|
|||
|
|
@ -233,56 +233,74 @@ var Editor = class Editor {
|
|||
})
|
||||
}
|
||||
|
||||
if (this.selectedWidgets.length == 1) {
|
||||
var widget = this.selectedWidgets[0]
|
||||
if (widget.props.height !== undefined || widget.props.width !== undefined) {
|
||||
var widget = this.selectedWidgets[0]
|
||||
|
||||
var handleTarget
|
||||
var $container = $(widget.container)
|
||||
$container.resizable({
|
||||
handles: 's, e, se',
|
||||
helper: "ui-helper",
|
||||
start: (event, ui)=>{
|
||||
handleTarget = $(event.originalEvent.target)
|
||||
},
|
||||
resize: (event, ui)=>{
|
||||
ui.size.height = Math.round(ui.size.height / (GRIDWIDTH * PXSCALE)) * GRIDWIDTH * PXSCALE
|
||||
ui.size.width = Math.round(ui.size.width / (GRIDWIDTH * PXSCALE)) * GRIDWIDTH * PXSCALE
|
||||
},
|
||||
stop: (event, ui)=>{
|
||||
if (handleTarget.hasClass('ui-resizable-se') || handleTarget.hasClass('ui-resizable-s')) widget.props.height = Math.round((Math.max(ui.size.height,1)) / (GRIDWIDTH * PXSCALE)) * GRIDWIDTH
|
||||
if (handleTarget.hasClass('ui-resizable-se') || handleTarget.hasClass('ui-resizable-e')) widget.props.width = Math.round(ui.size.width / (GRIDWIDTH * PXSCALE)) * GRIDWIDTH
|
||||
updateWidget(widget)
|
||||
},
|
||||
grid: [GRIDWIDTH * PXSCALE, GRIDWIDTH * PXSCALE]
|
||||
})
|
||||
if (widget.props.height !== undefined || widget.props.width !== undefined) {
|
||||
|
||||
}
|
||||
var handleTarget
|
||||
var $container = $(widget.container)
|
||||
$container.resizable({
|
||||
handles: 's, e, se',
|
||||
helper: "ui-helper",
|
||||
start: (event, ui)=>{
|
||||
handleTarget = $(event.originalEvent.target)
|
||||
},
|
||||
resize: (event, ui)=>{
|
||||
ui.size.height = Math.round(ui.size.height / (GRIDWIDTH * PXSCALE)) * GRIDWIDTH * PXSCALE
|
||||
ui.size.width = Math.round(ui.size.width / (GRIDWIDTH * PXSCALE)) * GRIDWIDTH * PXSCALE
|
||||
},
|
||||
stop: (event, ui)=>{
|
||||
|
||||
var deltaH = ui.size.height - ui.originalSize.height,
|
||||
deltaW = ui.size.width - ui.originalSize.width
|
||||
|
||||
if (widget.props.top !== undefined) {
|
||||
var $container = $(widget.container)
|
||||
$container.draggable({
|
||||
cursor:'-webkit-grabbing',
|
||||
drag: (event, ui)=>{
|
||||
ui.position.top = Math.round(ui.position.top / (GRIDWIDTH * PXSCALE)) * GRIDWIDTH * PXSCALE
|
||||
ui.position.left = Math.round(ui.position.left / (GRIDWIDTH * PXSCALE)) * GRIDWIDTH * PXSCALE
|
||||
},
|
||||
stop: (event, ui)=>{
|
||||
event.preventDefault()
|
||||
widget.props.top = (ui.helper.position().top + $container.parent().scrollTop())/PXSCALE
|
||||
widget.props.left = (ui.helper.position().left + $container.parent().scrollLeft())/PXSCALE
|
||||
ui.helper.remove()
|
||||
updateWidget(widget)
|
||||
},
|
||||
handle:'.ui-draggable-handle, > .label',
|
||||
grid: [GRIDWIDTH * PXSCALE, GRIDWIDTH * PXSCALE],
|
||||
helper:()=>{
|
||||
return $('<div class="ui-helper"></div>').css({height:$container.outerHeight(),width:$container.outerWidth()})
|
||||
var newWidgets = []
|
||||
for (var w of this.selectedWidgets) {
|
||||
var originalW = w === widget ? ui.originalSize.width : w.container.offsetWidth,
|
||||
originalH = w === widget ? ui.originalSize.height : w.container.offsetHeight
|
||||
|
||||
if (w.props.width !== undefined) w.props.width = Math.max((originalW + deltaW), GRIDWIDTH) / PXSCALE
|
||||
if (w.props.height !== undefined) w.props.height = Math.max((originalH + deltaH), GRIDWIDTH) / PXSCALE
|
||||
if (w.props.width !== undefined || w.props.height !== undefined) newWidgets.push(updateWidget(w))
|
||||
}
|
||||
}).append('<div class="ui-draggable-handle"></div>')
|
||||
if (newWidgets.length > 1) editor.select(newWidgets, {preventSelect: this.selectedWidgets.length > 1})
|
||||
},
|
||||
grid: [GRIDWIDTH * PXSCALE, GRIDWIDTH * PXSCALE]
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
if (widget.props.top !== undefined) {
|
||||
var $container = $(widget.container)
|
||||
$container.draggable({
|
||||
cursor:'-webkit-grabbing',
|
||||
drag: (event, ui)=>{
|
||||
ui.position.top = Math.round(ui.position.top / (GRIDWIDTH * PXSCALE)) * GRIDWIDTH * PXSCALE
|
||||
ui.position.left = Math.round(ui.position.left / (GRIDWIDTH * PXSCALE)) * GRIDWIDTH * PXSCALE
|
||||
},
|
||||
stop: (event, ui)=>{
|
||||
event.preventDefault()
|
||||
|
||||
var deltaX = (ui.helper.position().left + $container.parent().scrollLeft()) / PXSCALE - widget.container.offsetLeft / PXSCALE,
|
||||
deltaY = (ui.helper.position().top + $container.parent().scrollTop()) / PXSCALE - widget.container.offsetTop / PXSCALE
|
||||
|
||||
var newWidgets = []
|
||||
for (var w of this.selectedWidgets) {
|
||||
w.props.top = w.container.offsetTop / PXSCALE + deltaY
|
||||
w.props.left = w.container.offsetLeft / PXSCALE + deltaX
|
||||
newWidgets.push(updateWidget(w, {preventSelect: this.selectedWidgets.length > 1}))
|
||||
}
|
||||
if (newWidgets.length > 1) editor.select(newWidgets)
|
||||
|
||||
ui.helper.remove()
|
||||
},
|
||||
handle:'.ui-draggable-handle, > .label',
|
||||
grid: [GRIDWIDTH * PXSCALE, GRIDWIDTH * PXSCALE],
|
||||
helper:()=>{
|
||||
return $('<div class="ui-helper"></div>').css({height:$container.outerHeight(),width:$container.outerWidth()})
|
||||
}
|
||||
}).append('<div class="ui-draggable-handle"></div>')
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue