1
0
Fork 0
mirror of https://github.com/gwm17/Specter.git synced 2024-11-26 12:18:51 -05:00

Fixed janky summary spectrum dialog. Now better displays params and allows for multiple selections at once

This commit is contained in:
Gordon McCann 2022-04-26 21:02:14 -04:00
parent deea375007
commit c325e29b73
4 changed files with 55 additions and 15 deletions

View File

@ -18,6 +18,11 @@
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<HistogramParameters>);
}
void EditorLayer::UpdateCutList()
{
m_cutList = SpectrumManager::GetInstance().GetListOfCuts();
std::sort(m_cutList.begin(), m_cutList.end(), SortByName<CutParams>);
}
void EditorLayer::UpdateParameterList()
{
m_paramList = SpectrumManager::GetInstance().GetListOfParameters();
std::sort(m_paramList.begin(), m_paramList.end(), SortByString);
}
//The main function

View File

@ -70,6 +70,12 @@ namespace Navigator {
bool m_exportHistogram;
};
template<typename T>
bool SortByName(const T& p1, const T& p2)
{
return p1.name < p2.name;
}
}
#endif

View File

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

View File

@ -37,6 +37,7 @@ namespace Navigator {
std::vector<std::string> m_subhistos;
ImGuiSelectableFlags selectFlags;
ImGuiTableFlags tableFlags;
};
}