Fixed inexplicable ImGui bug

This commit is contained in:
Ryzerth 2021-04-23 03:58:10 +02:00
parent 1dbdf48e9a
commit b8e4a79188
4 changed files with 30 additions and 7 deletions

View File

@ -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

View File

@ -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<std::mutex> 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();
}

View File

@ -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;
}

View File

@ -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<MenuOption_t> order;