Browse Source

Refactor RackWidget::addModuleAtMouse().

tags/v2.1.0
Andrew Belt 2 years ago
parent
commit
9c512458cf
1 changed files with 5 additions and 4 deletions
  1. +5
    -4
      src/app/RackWidget.cpp

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

@@ -691,18 +691,19 @@ void RackWidget::setModulePosNearest(ModuleWidget* mw, math::Vec pos) {
void RackWidget::setModulePosForce(ModuleWidget* mw, math::Vec pos) { void RackWidget::setModulePosForce(ModuleWidget* mw, math::Vec pos) {
mw->setPosition(pos.div(RACK_GRID_SIZE).round().mult(RACK_GRID_SIZE)); mw->setPosition(pos.div(RACK_GRID_SIZE).round().mult(RACK_GRID_SIZE));


// Comparison of center X coordinates
// Comparison of X coordinates
auto cmp = [&](const widget::Widget* a, const widget::Widget* b) { auto cmp = [&](const widget::Widget* a, const widget::Widget* b) {
return a->box.pos.x + a->box.size.x / 2 < b->box.pos.x + b->box.size.x / 2;
return a->box.pos.x < b->box.pos.x;
}; };


// Collect modules to the left and right of `mw` // Collect modules to the left and right of `mw`
std::set<widget::Widget*, decltype(cmp)> leftModules(cmp); std::set<widget::Widget*, decltype(cmp)> leftModules(cmp);
std::set<widget::Widget*, decltype(cmp)> rightModules(cmp); std::set<widget::Widget*, decltype(cmp)> rightModules(cmp);
for (widget::Widget* w2 : internal->moduleContainer->children) { for (widget::Widget* w2 : internal->moduleContainer->children) {
// Skip this module
if (w2 == mw) if (w2 == mw)
continue; continue;
// Set position to old position
// Reset position to old position
auto it = internal->moduleOldPositions.find(w2); auto it = internal->moduleOldPositions.find(w2);
if (it != internal->moduleOldPositions.end()) { if (it != internal->moduleOldPositions.end()) {
w2->box.pos = it->second; w2->box.pos = it->second;
@@ -711,7 +712,7 @@ void RackWidget::setModulePosForce(ModuleWidget* mw, math::Vec pos) {
if (w2->box.getTop() != mw->box.getTop()) if (w2->box.getTop() != mw->box.getTop())
continue; continue;
// Insert into leftModules or rightModules // Insert into leftModules or rightModules
if (cmp(w2, mw))
if (w2->box.getCenter().x < mw->box.getCenter().x)
leftModules.insert(w2); leftModules.insert(w2);
else else
rightModules.insert(w2); rightModules.insert(w2);


Loading…
Cancel
Save