diff --git a/core/src/gui/main_window.cpp b/core/src/gui/main_window.cpp index 136a77b9..c4521265 100644 --- a/core/src/gui/main_window.cpp +++ b/core/src/gui/main_window.cpp @@ -196,6 +196,21 @@ void MainWindow::init() { tuningMode = core::configManager.conf["centerTuning"] ? tuner::TUNER_MODE_CENTER : tuner::TUNER_MODE_NORMAL; core::configManager.release(); + + // Correct the offset of all VFOs so that they fit on the screen + float finalBwHalf = gui::waterfall.getBandwidth() / 2.0; + for (auto& [_name, _vfo] : gui::waterfall.vfos) { + if (_vfo->lowerOffset < -finalBwHalf) { + sigpath::vfoManager.setCenterOffset(_name, (_vfo->bandwidth/2)-finalBwHalf); + continue; + } + if (_vfo->upperOffset > finalBwHalf) { + sigpath::vfoManager.setCenterOffset(_name, finalBwHalf-(_vfo->bandwidth/2)); + continue; + } + } + + initComplete = true; } void MainWindow::fftHandler(dsp::complex_t* samples, int count, void* ctx) { @@ -233,7 +248,8 @@ void MainWindow::vfoAddedHandler(VFOManager::VFO* vfo, void* ctx) { } double offset = core::configManager.conf["vfoOffsets"][name]; core::configManager.release(); - sigpath::vfoManager.setOffset(name, std::clamp(offset, -_this->bw/2.0, _this->bw/2.0)); + + sigpath::vfoManager.setOffset(name, _this->initComplete ? std::clamp(offset, -_this->bw/2.0, _this->bw/2.0) : offset); } void MainWindow::draw() { diff --git a/core/src/gui/main_window.h b/core/src/gui/main_window.h index 50aca8f2..e6ad6765 100644 --- a/core/src/gui/main_window.h +++ b/core/src/gui/main_window.h @@ -65,6 +65,8 @@ private: bool demoWindow = false; int selectedWindow = 0; + bool initComplete = false; + EventHandler vfoCreatedHandler; }; \ No newline at end of file diff --git a/core/src/gui/widgets/waterfall.cpp b/core/src/gui/widgets/waterfall.cpp index 48edbff0..61087170 100644 --- a/core/src/gui/widgets/waterfall.cpp +++ b/core/src/gui/widgets/waterfall.cpp @@ -1151,8 +1151,8 @@ namespace ImGui { int _right = right; left = std::clamp(left, 0, dataWidth - 1); right = std::clamp(right, 0, dataWidth - 1); - if (left != _left) { leftClamped = true; } - if (right != _right) { rightClamped = true; } + leftClamped = (left != _left); + rightClamped = (right != _right); rectMin = ImVec2(widgetPos.x + 50 + left, widgetPos.y + 10); rectMax = ImVec2(widgetPos.x + 51 + right, widgetPos.y + fftHeight + 10);