Browse Source

Use nearest free position in RackWidget::fromJson() so resized modules don't overlap.

tags/v2.0.0
Andrew Belt 3 years ago
parent
commit
f87f6af45b
1 changed files with 4 additions and 2 deletions
  1. +4
    -2
      src/app/RackWidget.cpp

+ 4
- 2
src/app/RackWidget.cpp View File

@@ -342,7 +342,8 @@ void RackWidget::fromJson(json_t* rootJ) {
else { else {
pos = pos.mult(RACK_GRID_SIZE); pos = pos.mult(RACK_GRID_SIZE);
} }
mw->box.pos = pos.plus(RACK_OFFSET);
pos = pos.plus(RACK_OFFSET);
setModulePosNearest(mw, pos);


internal->moduleContainer->addChild(mw); internal->moduleContainer->addChild(mw);
} }
@@ -1083,7 +1084,7 @@ void RackWidget::deleteSelectionAction() {
} }


bool RackWidget::requestSelectionPos(math::Vec delta) { bool RackWidget::requestSelectionPos(math::Vec delta) {
// Check intersection with other modules
// Calculate new positions
std::map<widget::Widget*, math::Rect> mwBoxes; std::map<widget::Widget*, math::Rect> mwBoxes;
for (ModuleWidget* mw : getSelectedModules()) { for (ModuleWidget* mw : getSelectedModules()) {
math::Rect mwBox = mw->box; math::Rect mwBox = mw->box;
@@ -1091,6 +1092,7 @@ bool RackWidget::requestSelectionPos(math::Vec delta) {
mwBoxes[mw] = mwBox; mwBoxes[mw] = mwBox;
} }


// Check intersection with other modules
for (widget::Widget* w2 : internal->moduleContainer->children) { for (widget::Widget* w2 : internal->moduleContainer->children) {
// Don't intersect with selected modules // Don't intersect with selected modules
auto it = mwBoxes.find(w2); auto it = mwBoxes.find(w2);


Loading…
Cancel
Save