From 2e8cd7c270328088c1b77073378c3ef9f1f55d56 Mon Sep 17 00:00:00 2001 From: carbon14 <10398567+david-c14@users.noreply.github.com> Date: Thu, 6 Sep 2018 11:55:06 +0100 Subject: [PATCH] Complete shifting algorithm --- src/ModBrowser.cpp | 18 ------------------ src/SubControls.cpp | 24 +++++++++++++++++++++++- src/SubControls.hpp | 2 ++ 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/ModBrowser.cpp b/src/ModBrowser.cpp index ed0d2d9..c72c9be 100755 --- a/src/ModBrowser.cpp +++ b/src/ModBrowser.cpp @@ -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 diff --git a/src/SubControls.cpp b/src/SubControls.cpp index 0f3998c..8fb37f7 100755 --- a/src/SubControls.cpp +++ b/src/SubControls.cpp @@ -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 @@ -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; @@ -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; diff --git a/src/SubControls.hpp b/src/SubControls.hpp index a039856..e495094 100755 --- a/src/SubControls.hpp +++ b/src/SubControls.hpp @@ -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() { }; };