diff --git a/core/src/core.cpp b/core/src/core.cpp index e0483d05..effbc393 100644 --- a/core/src/core.cpp +++ b/core/src/core.cpp @@ -147,6 +147,7 @@ int sdrpp_main(int argc, char *argv[]) { defConfig["menuWidth"] = 300; defConfig["min"] = -120.0; + // Module instances defConfig["moduleInstances"]["Radio"] = "radio"; defConfig["moduleInstances"]["Recorder"] = "recorder"; defConfig["moduleInstances"]["SoapySDR Source"] = "soapy_source"; @@ -162,6 +163,7 @@ int sdrpp_main(int argc, char *argv[]) { defConfig["modules"] = json::array(); defConfig["offset"] = 0.0; + defConfig["showMenu"] = true; defConfig["showWaterfall"] = true; defConfig["source"] = ""; defConfig["streams"] = json::object(); @@ -202,6 +204,7 @@ int sdrpp_main(int argc, char *argv[]) { core::configManager.conf.erase(item.key()); } } + core::configManager.release(true); // Setup window diff --git a/core/src/gui/main_window.cpp b/core/src/gui/main_window.cpp index 9f5f4747..064dfdf6 100644 --- a/core/src/gui/main_window.cpp +++ b/core/src/gui/main_window.cpp @@ -42,6 +42,8 @@ float* tempFFT; float* FFTdata; char buf[1024]; bool experimentalZoom = false; +bool firstMenuRender = true; +bool startedWithMenuClosed = false; void fftHandler(dsp::complex_t* samples, int count, void* ctx) { std::lock_guard lck(fft_mtx); @@ -236,6 +238,9 @@ void windowInit() { double frequency = core::configManager.conf["frequency"]; + showMenu = core::configManager.conf["showMenu"]; + startedWithMenuClosed = !showMenu; + gui::freqSelect.setFrequency(frequency); gui::freqSelect.frequencyChanged = false; sigpath::sourceManager.tune(frequency); @@ -443,6 +448,9 @@ void drawWindow() { ImGui::PushID(ImGui::GetID("sdrpp_menu_btn")); if (ImGui::ImageButton(icons::MENU, ImVec2(30, 30), ImVec2(0, 0), ImVec2(1, 1), 5)) { showMenu = !showMenu; + core::configManager.aquire(); + core::configManager.conf["showMenu"] = showMenu; + core::configManager.release(true); } ImGui::PopID(); @@ -554,7 +562,7 @@ void drawWindow() { ImGui::BeginChild("Left Column"); float menuColumnWidth = ImGui::GetContentRegionAvailWidth(); - if (gui::menu.draw()) { + if (gui::menu.draw(firstMenuRender)) { core::configManager.aquire(); json arr = json::array(); for (int i = 0; i < gui::menu.order.size(); i++) { @@ -564,6 +572,12 @@ void drawWindow() { core::configManager.conf["menuElements"] = arr; core::configManager.release(true); } + if (startedWithMenuClosed) { + startedWithMenuClosed = false; + } + else { + firstMenuRender = false; + } if(ImGui::CollapsingHeader("Debug")) { ImGui::Text("Frame time: %.3f ms/frame", 1000.0 / ImGui::GetIO().Framerate); @@ -581,6 +595,11 @@ void drawWindow() { spdlog::error("Will this make the software crash?"); } + if (ImGui::Button("Testing something")) { + gui::menu.order[0].open = true; + firstMenuRender = true; + } + ImGui::Spacing(); } diff --git a/core/src/gui/widgets/menu.cpp b/core/src/gui/widgets/menu.cpp index e73653d5..81091c59 100644 --- a/core/src/gui/widgets/menu.cpp +++ b/core/src/gui/widgets/menu.cpp @@ -24,7 +24,7 @@ void Menu::removeEntry(std::string name) { items.erase(name); } -bool Menu::draw() { +bool Menu::draw(bool updateStates) { bool changed = false; float menuWidth = ImGui::GetContentRegionAvailWidth(); ImGuiWindow* window = ImGui::GetCurrentWindow(); @@ -39,7 +39,8 @@ bool Menu::draw() { window->WorkRect = ImRect(orginalRect.Min, ImVec2(orginalRect.Max.x - ImGui::GetTextLineHeight() - 6, orginalRect.Max.y)); } - if (ImGui::CollapsingHeader(opt.name.c_str(), opt.open ? ImGuiTreeNodeFlags_DefaultOpen : 0)) { + if (updateStates) { ImGui::SetNextItemOpen(opt.open); } + if (ImGui::CollapsingHeader((opt.name + "##sdrpp_main_menu").c_str())) { if (item.inst != NULL) { window->WorkRect = orginalRect; ImVec2 pos = ImGui::GetCursorPos(); @@ -53,7 +54,7 @@ bool Menu::draw() { } // Check if the state changed - if (!opt.open) { + if (!opt.open && !updateStates) { opt.open = true; changed = true; } @@ -72,12 +73,12 @@ bool Menu::draw() { } ImGui::SetCursorPos(pos); - if (opt.open) { + if (opt.open && !updateStates) { opt.open = false; changed = true; } } - else if (opt.open) { + else if (opt.open && !updateStates) { opt.open = false; changed = true; } diff --git a/core/src/gui/widgets/menu.h b/core/src/gui/widgets/menu.h index 7f338e83..7199528c 100644 --- a/core/src/gui/widgets/menu.h +++ b/core/src/gui/widgets/menu.h @@ -21,7 +21,7 @@ public: void registerEntry(std::string name, void (*drawHandler)(void* ctx), void* ctx = NULL, ModuleManager::Instance* inst = NULL); void removeEntry(std::string name); - bool draw(); + bool draw(bool updateStates); std::vector order;