From 4c0ea68b0e56e196cd2d90eecadc8a7714204eaa Mon Sep 17 00:00:00 2001 From: Aang23 Date: Tue, 1 Apr 2025 19:18:22 +0200 Subject: [PATCH] Bring back search in presets --- .../handler/product/product_handler.cpp | 54 +++++++++++++------ .../handler/product/product_handler.h | 3 +- 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/src-core/products2/handler/product/product_handler.cpp b/src-core/products2/handler/product/product_handler.cpp index a8d7ed937..fc4e93be7 100644 --- a/src-core/products2/handler/product/product_handler.cpp +++ b/src-core/products2/handler/product/product_handler.cpp @@ -4,6 +4,7 @@ #include "nlohmann/json_utils.h" #include "common/utils.h" #include "core/exception.h" +#include "imgui/imgui_stdlib.h" namespace satdump { @@ -39,7 +40,7 @@ namespace satdump { try { - preset_selection_box_str += cfg["name"].get() + '\0'; + preset_selection_box_str.push_back(cfg["name"].get()); } catch (std::exception &e) { @@ -55,26 +56,45 @@ namespace satdump if (ImGui::CollapsingHeader("Presets", ImGuiTreeNodeFlags_DefaultOpen)) { - if (ImGui::Combo("##presetproductcombo", &preset_selection_curr_id, preset_selection_box_str.c_str())) + if (ImGui::BeginCombo("##presetproductcombo", /*TODOREWORK maybe make this generic?*/ + (preset_selection_curr_id > 0 && preset_selection_curr_id < preset_selection_box_str.size()) + ? "" + : preset_selection_box_str[preset_selection_curr_id].c_str())) { - auto preset = instrument_cfg["presets"][preset_selection_curr_id]; - setConfig(preset); - was_changed = true; - preset_selection_curr_id = -1; + ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); + ImGui::InputTextWithHint("##searchpresets", u8"\uf422 Search", &preset_search_str); + for (size_t i = 0; i < preset_selection_box_str.size(); i++) + { + bool show = true; + if (preset_search_str.size() != 0) + show = isStringPresent(preset_selection_box_str[i], preset_search_str); - // Description, optional - if (preset.contains("description")) - { - std::ifstream ifs(resources::getResourcePath(preset["description"])); - std::string desc_markdown((std::istreambuf_iterator(ifs)), (std::istreambuf_iterator())); - markdown_info.set_md(desc_markdown); - has_markdown_description = true; - } - else - { - has_markdown_description = false; + if (show && ImGui::Selectable(preset_selection_box_str[i].c_str(), (int)i == preset_selection_curr_id)) + { + preset_selection_curr_id = i; + + auto preset = instrument_cfg["presets"][preset_selection_curr_id]; + setConfig(preset); + was_changed = true; + preset_selection_curr_id = -1; + + // Description, optional + if (preset.contains("description")) + { + std::ifstream ifs(resources::getResourcePath(preset["description"])); + std::string desc_markdown((std::istreambuf_iterator(ifs)), (std::istreambuf_iterator())); + markdown_info.set_md(desc_markdown); + has_markdown_description = true; + } + else + { + has_markdown_description = false; + } + } } + ImGui::EndCombo(); } + ImGui::SameLine(); if (ImGui::Button("Default")) { diff --git a/src-core/products2/handler/product/product_handler.h b/src-core/products2/handler/product/product_handler.h index ca30e0bb9..3dfd3821c 100644 --- a/src-core/products2/handler/product/product_handler.h +++ b/src-core/products2/handler/product/product_handler.h @@ -30,7 +30,8 @@ namespace satdump private: std::string handler_name; - std::string preset_selection_box_str; + std::string preset_search_str; + std::vector preset_selection_box_str; int preset_selection_curr_id = -1; bool has_markdown_description = false;