Skip to content

Commit

Permalink
Complete shifting algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
david-c14 committed Sep 6, 2018
1 parent 2b82acd commit 2e8cd7c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
18 changes: 0 additions & 18 deletions src/ModBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,24 +589,6 @@ struct ModBrowserWidget : SubControls::SizeableModuleWidget {
ModuleWidget::step();
}

json_t *toJson() override {
json_t *rootJ = ModuleWidget::toJson();

// // width
json_object_set_new(rootJ, "width", json_real(moduleWidth));

return rootJ;
}

void fromJson(json_t *rootJ) override {
ModuleWidget::fromJson(rootJ);

// width
json_t *widthJ = json_object_get(rootJ, "width");
if (widthJ)
moduleWidth = json_number_value(widthJ);
Minimize(moduleWidth < 0);
}
};

// Icon onAction
Expand Down
24 changes: 23 additions & 1 deletion src/SubControls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ struct RowShifter {
return;
}
// Have we got enough space to shuffle up before the multi-row element
float space = endPoint - baseWidget->box.pos.x + baseWidget->box.pos.y;
float space = endPoint - baseWidget->box.pos.x - baseWidget->box.size.x;
debug("Space %f", space);
for (Widget *w : gRackWidget->moduleContainer->children) {
if (w->box.pos.y != row->position.y)
continue; // This is not the row we are looking for
Expand All @@ -128,7 +129,9 @@ struct RowShifter {
if (w->box.pos.x >= endPoint)
continue; // This is to the right of the region we are looking at
space -= w->box.size.x;
debug("Space adjusted to %f", space);
}
debug("Space %f delta %f", space, delta);
if (space >= delta) {
shortShiftRight(endPoint); // Just shift upto the endPoint
return;
Expand Down Expand Up @@ -257,6 +260,25 @@ void SizeableModuleWidget::Minimize(unsigned int minimize) {
}
}

json_t *SizeableModuleWidget::toJson() {
json_t *rootJ = ModuleWidget::toJson();

// moduleWidth
json_object_set_new (rootJ, "width", json_real(moduleWidth));

return rootJ;
}

void SizeableModuleWidget::fromJson(json_t *rootJ) {
ModuleWidget::fromJson(rootJ);

// width
json_t *widthJ = json_object_get(rootJ, "width");
if (widthJ)
moduleWidth = json_number_value(widthJ);
Minimize(moduleWidth < 0);
}

void ModuleDragHandle::onDragStart(EventDragStart &e) {
dragX = gRackWidget->lastMousePos.x;
originalBox = smw->box;
Expand Down
2 changes: 2 additions & 0 deletions src/SubControls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ struct SizeableModuleWidget : ModuleWidget {
void Resize();
void Minimize(unsigned int minimize);
void ShiftOthers(float delta);
json_t *toJson() override;
void fromJson(json_t *rootJ) override;

virtual void onResize() { };
};
Expand Down

0 comments on commit 2e8cd7c

Please sign in to comment.