diff --git a/Navigator/src/Navigator/Editor/EditorLayer.cpp b/Navigator/src/Navigator/Editor/EditorLayer.cpp index 2e20130..cb34be6 100644 --- a/Navigator/src/Navigator/Editor/EditorLayer.cpp +++ b/Navigator/src/Navigator/Editor/EditorLayer.cpp @@ -17,7 +17,12 @@ #include "IconsFontAwesome5.h" namespace Navigator { - + + bool SortByString(const std::string& p1, const std::string& p2) + { + return p1 < p2; + } + EditorLayer::EditorLayer() : Layer("EditorLayer"), m_removeHistogram(false), m_removeCut(false), m_exportHistogram(false) { @@ -45,16 +50,19 @@ namespace Navigator { void EditorLayer::UpdateHistogramList() { m_histoList = SpectrumManager::GetInstance().GetListOfHistograms(); + std::sort(m_histoList.begin(), m_histoList.end(), SortByName); } void EditorLayer::UpdateCutList() { m_cutList = SpectrumManager::GetInstance().GetListOfCuts(); + std::sort(m_cutList.begin(), m_cutList.end(), SortByName); } void EditorLayer::UpdateParameterList() { m_paramList = SpectrumManager::GetInstance().GetListOfParameters(); + std::sort(m_paramList.begin(), m_paramList.end(), SortByString); } //The main function diff --git a/Navigator/src/Navigator/Editor/EditorLayer.h b/Navigator/src/Navigator/Editor/EditorLayer.h index 9fad635..b93e259 100644 --- a/Navigator/src/Navigator/Editor/EditorLayer.h +++ b/Navigator/src/Navigator/Editor/EditorLayer.h @@ -36,7 +36,7 @@ namespace Navigator { virtual void OnUpdate() override; virtual void OnEvent(Event& event) override; - + private: void RemoveCutDialog(); void RemoveHistogramDialog(); @@ -70,6 +70,12 @@ namespace Navigator { bool m_exportHistogram; }; + template + bool SortByName(const T& p1, const T& p2) + { + return p1.name < p2.name; + } + } #endif diff --git a/Navigator/src/Navigator/Editor/SpectrumDialog.cpp b/Navigator/src/Navigator/Editor/SpectrumDialog.cpp index d8a5668..a36cb99 100644 --- a/Navigator/src/Navigator/Editor/SpectrumDialog.cpp +++ b/Navigator/src/Navigator/Editor/SpectrumDialog.cpp @@ -17,6 +17,7 @@ namespace Navigator { m_openFlag(false), m_openCutFlag(false) { selectFlags = ImGuiSelectableFlags_DontClosePopups; + tableFlags = ImGuiTableFlags_BordersH | ImGuiTableFlags_SizingStretchProp | ImGuiTableFlags_BordersOuterV | ImGuiTableFlags_RowBg; } SpectrumDialog::~SpectrumDialog() @@ -171,7 +172,6 @@ namespace Navigator { void SpectrumDialog::RenderDialogSummary(const std::vector& paramList) { - static std::string selectedParam = ""; if (ImGui::BeginTable("SpecParamsTable", 3)) { ImGui::TableNextRow(); @@ -193,30 +193,55 @@ namespace Navigator { } if (ImGui::Button("Add Parameter")) { - selectedParam = ""; + m_subhistos.clear(); ImGui::OpenPopup("Param List"); } - if (ImGui::BeginPopup("Param List")) + if (ImGui::BeginPopupModal("Param List")) { - if (ImGui::BeginCombo("Parameter", selectedParam.c_str())) - { - for (auto& param : paramList) - { - if (ImGui::Selectable(param.c_str(), param == selectedParam, selectFlags)) - selectedParam = param; - } - ImGui::EndCombo(); - } if (ImGui::Button("Ok")) { - m_subhistos.push_back(selectedParam); ImGui::CloseCurrentPopup(); } ImGui::SameLine(); if (ImGui::Button("Cancel")) { + m_subhistos.clear(); ImGui::CloseCurrentPopup(); } + + auto check_func = [this](const std::string& name) + { + for (auto& par : m_subhistos) + { + if (name == par) + return true; + } + return false; + }; + + if (ImGui::BeginTable("Parameters", 1, tableFlags, ImVec2(-1, -1))) + { + for (auto& param : paramList) + { + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + if (ImGui::Selectable(param.c_str(), check_func(param), selectFlags)) + { + if (!check_func(param)) + { + m_subhistos.push_back(param); + } + else + { + auto iter = std::remove(m_subhistos.begin(), m_subhistos.end(), param); + m_subhistos.erase(iter, m_subhistos.end()); + } + } + } + + ImGui::EndTable(); + } + ImGui::EndPopup(); } } diff --git a/Navigator/src/Navigator/Editor/SpectrumDialog.h b/Navigator/src/Navigator/Editor/SpectrumDialog.h index c8f8770..b6d1396 100644 --- a/Navigator/src/Navigator/Editor/SpectrumDialog.h +++ b/Navigator/src/Navigator/Editor/SpectrumDialog.h @@ -37,6 +37,7 @@ namespace Navigator { std::vector m_subhistos; ImGuiSelectableFlags selectFlags; + ImGuiTableFlags tableFlags; }; }