mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-16 11:17:51 -06:00
Search: Implemented "Option type" checkbox for imGui window on Plater
+ code refactoring
This commit is contained in:
parent
3b88dc2688
commit
83782e59b6
8 changed files with 82 additions and 49 deletions
|
@ -4463,9 +4463,9 @@ bool GLCanvas3D::_render_undo_redo_stack(const bool is_undo, float pos_x) const
|
|||
}
|
||||
|
||||
// Getter for the const char*[] for the search list
|
||||
static bool search_string_getter(int idx, const char** out_text)
|
||||
static bool search_string_getter(int idx, const char** label, const char** tooltip)
|
||||
{
|
||||
return wxGetApp().plater()->search_string_getter(idx, out_text);
|
||||
return wxGetApp().plater()->search_string_getter(idx, label, tooltip);
|
||||
}
|
||||
|
||||
bool GLCanvas3D::_render_search_list(float pos_x) const
|
||||
|
@ -4482,7 +4482,7 @@ bool GLCanvas3D::_render_search_list(float pos_x) const
|
|||
std::string title = L("Search");
|
||||
imgui->begin(_(title), ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse);
|
||||
|
||||
size_t selected = size_t(-1);
|
||||
int selected = -1;
|
||||
bool edited = false;
|
||||
bool check_changed = false;
|
||||
float em = static_cast<float>(wxGetApp().em_unit());
|
||||
|
@ -4497,17 +4497,14 @@ bool GLCanvas3D::_render_search_list(float pos_x) const
|
|||
strcpy(s, search_line.empty() ? _u8L("Type here to search").c_str() : search_line.c_str());
|
||||
|
||||
imgui->search_list(ImVec2(45 * em, 30 * em), &search_string_getter, s,
|
||||
sidebar.get_searcher().category, sidebar.get_searcher().group,
|
||||
m_imgui_search_hovered_pos,
|
||||
sidebar.get_searcher().view_params,
|
||||
selected, edited, check_changed);
|
||||
|
||||
search_line = s;
|
||||
delete [] s;
|
||||
|
||||
if (edited) {
|
||||
if (edited)
|
||||
sidebar.search_and_apply_tab_search_lines();
|
||||
m_imgui_search_hovered_pos = -1;
|
||||
}
|
||||
|
||||
if (check_changed) {
|
||||
if (search_line == _u8L("Type here to search"))
|
||||
|
@ -5068,7 +5065,7 @@ bool GLCanvas3D::_init_main_toolbar()
|
|||
_deactivate_search_toolbar_item();
|
||||
}
|
||||
};
|
||||
item.left.action_callback = [this]() { m_imgui_search_hovered_pos = -1; }; //GLToolbarItem::Default_Action_Callback;
|
||||
item.left.action_callback = GLToolbarItem::Default_Action_Callback;
|
||||
item.visibility_callback = GLToolbarItem::Default_Visibility_Callback;
|
||||
item.enabling_callback = GLToolbarItem::Default_Enabling_Callback;
|
||||
if (!m_main_toolbar.add_item(item))
|
||||
|
|
|
@ -505,7 +505,6 @@ private:
|
|||
#endif // ENABLE_RENDER_STATISTICS
|
||||
|
||||
mutable int m_imgui_undo_redo_hovered_pos{ -1 };
|
||||
mutable size_t m_imgui_search_hovered_pos{ size_t(-1) };
|
||||
int m_selected_extruder;
|
||||
|
||||
Labels m_labels;
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "3DScene.hpp"
|
||||
#include "GUI.hpp"
|
||||
#include "I18N.hpp"
|
||||
#include "Search.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
|
@ -600,8 +601,8 @@ static void process_key_down(ImGuiKey imgui_key, std::function<void()> f)
|
|||
}
|
||||
}
|
||||
|
||||
void ImGuiWrapper::search_list(const ImVec2& size_, bool (*items_getter)(int, const char**), char* search_str,
|
||||
bool& category, bool& group, size_t& hovered_id, size_t& selected, bool& edited, bool& check_changed)
|
||||
void ImGuiWrapper::search_list(const ImVec2& size_, bool (*items_getter)(int, const char** label, const char** tooltip), char* search_str,
|
||||
Search::OptionViewParameters& view_params, int& selected, bool& edited, bool& check_changed)
|
||||
{
|
||||
// ImGui::ListBoxHeader("", size);
|
||||
{
|
||||
|
@ -641,6 +642,8 @@ void ImGuiWrapper::search_list(const ImVec2& size_, bool (*items_getter)(int, co
|
|||
std::string str = search_str;
|
||||
ImGui::InputTextEx("", NULL, search_str, 20, search_size, 0, NULL, NULL);
|
||||
edited = ImGui::IsItemEdited();
|
||||
if (edited)
|
||||
view_params.hovered_id = -1;
|
||||
|
||||
process_key_down(ImGuiKey_Escape, [&selected, search_str, str]() {
|
||||
// use 9999 to mark selection as a Esc key
|
||||
|
@ -652,17 +655,19 @@ void ImGuiWrapper::search_list(const ImVec2& size_, bool (*items_getter)(int, co
|
|||
ImGui::BeginChildFrame(id, frame_bb.GetSize());
|
||||
}
|
||||
|
||||
size_t i = 0;
|
||||
int i = 0;
|
||||
const char* item_text;
|
||||
const char* tooltip;
|
||||
int mouse_hovered = -1;
|
||||
int& hovered_id = view_params.hovered_id;
|
||||
|
||||
while (items_getter(i, &item_text))
|
||||
while (items_getter(i, &item_text, &tooltip))
|
||||
{
|
||||
selectable(item_text, i == hovered_id);
|
||||
|
||||
if (ImGui::IsItemHovered()) {
|
||||
ImGui::SetTooltip("%s", item_text);
|
||||
hovered_id = size_t(-1);
|
||||
ImGui::SetTooltip("%s", /*item_text*/tooltip);
|
||||
view_params.hovered_id = -1;
|
||||
mouse_hovered = i;
|
||||
}
|
||||
|
||||
|
@ -702,22 +707,21 @@ void ImGuiWrapper::search_list(const ImVec2& size_, bool (*items_getter)(int, co
|
|||
|
||||
ImGui::ListBoxFooter();
|
||||
|
||||
auto check_box = [&check_changed, this](const wxString& label, bool& check) {
|
||||
ImGui::SameLine();
|
||||
bool ch = check;
|
||||
checkbox(label, ch);
|
||||
if (ImGui::IsItemClicked()) {
|
||||
check = !check;
|
||||
check_changed = true;
|
||||
}
|
||||
};
|
||||
|
||||
// add checkboxes for show/hide Categories and Groups
|
||||
text(_L("Use for search")+":");
|
||||
ImGui::SameLine();
|
||||
bool cat = category;
|
||||
checkbox(_L("Category"), cat);
|
||||
if (ImGui::IsItemClicked()) {
|
||||
category = !category;
|
||||
check_changed = true;
|
||||
}
|
||||
ImGui::SameLine();
|
||||
bool gr = group;
|
||||
checkbox(_L("Group"), gr);
|
||||
if (ImGui::IsItemClicked()) {
|
||||
group = !group;
|
||||
check_changed = true;
|
||||
}
|
||||
check_box(_L("Type"), view_params.type);
|
||||
check_box(_L("Category"), view_params.category);
|
||||
check_box(_L("Group"), view_params.group);
|
||||
}
|
||||
|
||||
void ImGuiWrapper::disabled_begin(bool disabled)
|
||||
|
|
|
@ -8,6 +8,10 @@
|
|||
|
||||
#include "libslic3r/Point.hpp"
|
||||
|
||||
namespace Slic3r {namespace Search {
|
||||
struct OptionViewParameters;
|
||||
}}
|
||||
|
||||
class wxString;
|
||||
class wxMouseEvent;
|
||||
class wxKeyEvent;
|
||||
|
@ -74,8 +78,8 @@ public:
|
|||
bool slider_float(const wxString& label, float* v, float v_min, float v_max, const char* format = "%.3f", float power = 1.0f);
|
||||
bool combo(const wxString& label, const std::vector<std::string>& options, int& selection); // Use -1 to not mark any option as selected
|
||||
bool undo_redo_list(const ImVec2& size, const bool is_undo, bool (*items_getter)(const bool, int, const char**), int& hovered, int& selected);
|
||||
void search_list(const ImVec2& size, bool (*items_getter)(int, const char**), char* search_str,
|
||||
bool& category, bool& group, size_t& hovered_id, size_t& selected, bool& edited, bool& check_changed);
|
||||
void search_list(const ImVec2& size, bool (*items_getter)(int, const char** label, const char** tooltip), char* search_str,
|
||||
Search::OptionViewParameters& view_params, int& selected, bool& edited, bool& check_changed);
|
||||
|
||||
void disabled_begin(bool disabled);
|
||||
void disabled_end();
|
||||
|
|
|
@ -5343,12 +5343,12 @@ void Plater::undo_redo_topmost_string_getter(const bool is_undo, std::string& ou
|
|||
out_text = "";
|
||||
}
|
||||
|
||||
bool Plater::search_string_getter(int idx, const char** out_text)
|
||||
bool Plater::search_string_getter(int idx, const char** label, const char** tooltip)
|
||||
{
|
||||
const Search::OptionsSearcher& search_list = p->sidebar->get_searcher();
|
||||
|
||||
if (0 <= idx && (size_t)idx < search_list.size()) {
|
||||
search_list[idx].get_marked_label(out_text);
|
||||
search_list[idx].get_marked_label_and_tooltip(label, tooltip);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -243,7 +243,7 @@ public:
|
|||
void redo_to(int selection);
|
||||
bool undo_redo_string_getter(const bool is_undo, int idx, const char** out_text);
|
||||
void undo_redo_topmost_string_getter(const bool is_undo, std::string& out_text);
|
||||
bool search_string_getter(int idx, const char **out_text);
|
||||
bool search_string_getter(int idx, const char** label, const char** tooltip);
|
||||
// For the memory statistics.
|
||||
const Slic3r::UndoRedo::Stack& undo_redo_stack_main() const;
|
||||
// Enter / leave the Gizmos specific Undo / Redo stack. To be used by the SLA support point editing gizmo.
|
||||
|
|
|
@ -23,6 +23,14 @@ using GUI::into_u8;
|
|||
|
||||
namespace Search {
|
||||
|
||||
static std::map<Preset::Type, std::string> NameByType = {
|
||||
{ Preset::TYPE_PRINT, L("Print") },
|
||||
{ Preset::TYPE_FILAMENT, L("Filament") },
|
||||
{ Preset::TYPE_SLA_MATERIAL, L("Material") },
|
||||
{ Preset::TYPE_SLA_PRINT, L("Print") },
|
||||
{ Preset::TYPE_PRINTER, L("Printer") }
|
||||
};
|
||||
|
||||
FMFlag Option::fuzzy_match_simple(char const * search_pattern) const
|
||||
{
|
||||
return fts::fuzzy_match_simple(search_pattern, label_local.utf8_str()) ? fmLabelLocal :
|
||||
|
@ -86,9 +94,10 @@ void FoundOption::get_label(const char** out_text) const
|
|||
*out_text = label.utf8_str();
|
||||
}
|
||||
|
||||
void FoundOption::get_marked_label(const char** out_text) const
|
||||
void FoundOption::get_marked_label_and_tooltip(const char** label_, const char** tooltip_) const
|
||||
{
|
||||
*out_text = marked_label.utf8_str();
|
||||
*label_ = marked_label.utf8_str();
|
||||
*tooltip_ = tooltip.utf8_str();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
|
@ -214,24 +223,34 @@ bool OptionsSearcher::search(const std::string& search, bool force/* = false*/)
|
|||
found.clear();
|
||||
|
||||
bool full_list = search.empty();
|
||||
wxString sep = " : ";
|
||||
|
||||
auto get_label = [this](const Option& opt)
|
||||
auto get_label = [this, sep](const Option& opt)
|
||||
{
|
||||
wxString label;
|
||||
if (category)
|
||||
label += opt.category_local + " > ";
|
||||
if (group)
|
||||
label += opt.group_local + " > ";
|
||||
if (view_params.type)
|
||||
label += _(NameByType[opt.type]) + sep;
|
||||
if (view_params.category)
|
||||
label += opt.category_local + sep;
|
||||
if (view_params.group)
|
||||
label += opt.group_local + sep;
|
||||
label += opt.label_local;
|
||||
return label;
|
||||
};
|
||||
|
||||
auto get_tooltip = [this, sep](const Option& opt)
|
||||
{
|
||||
return _(NameByType[opt.type]) + sep +
|
||||
opt.category_local + sep +
|
||||
opt.group_local + sep + opt.label_local;
|
||||
};
|
||||
|
||||
for (size_t i=0; i < options.size(); i++)
|
||||
{
|
||||
const Option &opt = options[i];
|
||||
if (full_list) {
|
||||
wxString label = get_label(opt);
|
||||
found.emplace_back(FoundOption{ label, label, i, 0 });
|
||||
found.emplace_back(FoundOption{ label, label, get_tooltip(opt), i, 0 });
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -240,7 +259,7 @@ bool OptionsSearcher::search(const std::string& search, bool force/* = false*/)
|
|||
FMFlag fuzzy_match_flag = opt.fuzzy_match(search, score);
|
||||
if (fuzzy_match_flag != fmUndef)
|
||||
{
|
||||
wxString label = get_label(opt); //opt.category_local + " > " + opt.group_local + " > " + opt.label_local;
|
||||
wxString label = get_label(opt);
|
||||
|
||||
if ( fuzzy_match_flag == fmLabel ) label += "(" + opt.label + ")";
|
||||
else if (fuzzy_match_flag == fmGroup ) label += "(" + opt.group + ")";
|
||||
|
@ -251,7 +270,7 @@ bool OptionsSearcher::search(const std::string& search, bool force/* = false*/)
|
|||
mark_string(marked_label, from_u8(search));
|
||||
clear_marked_string(marked_label);
|
||||
|
||||
found.emplace_back(FoundOption{ label, marked_label, i, score });
|
||||
found.emplace_back(FoundOption{ label, marked_label, get_tooltip(opt), i, score });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <wx/combo.h>
|
||||
|
||||
#include <wx/popupwin.h>
|
||||
#include <wx/checkbox.h>
|
||||
|
||||
#include "Preset.hpp"
|
||||
#include "wxExtensions.hpp"
|
||||
|
@ -69,11 +70,21 @@ struct Option {
|
|||
struct FoundOption {
|
||||
wxString label;
|
||||
wxString marked_label;
|
||||
wxString tooltip;
|
||||
size_t option_idx {0};
|
||||
int outScore {0};
|
||||
|
||||
void get_label(const char** out_text) const;
|
||||
void get_marked_label(const char** out_text) const;
|
||||
void get_marked_label_and_tooltip(const char** label, const char** tooltip) const;
|
||||
};
|
||||
|
||||
struct OptionViewParameters
|
||||
{
|
||||
bool type {false};
|
||||
bool category {false};
|
||||
bool group {true };
|
||||
|
||||
int hovered_id {-1};
|
||||
};
|
||||
|
||||
class OptionsSearcher
|
||||
|
@ -99,8 +110,7 @@ class OptionsSearcher
|
|||
size_t found_size() const { return found.size(); }
|
||||
|
||||
public:
|
||||
bool category{ false };
|
||||
bool group{ true };
|
||||
OptionViewParameters view_params;
|
||||
|
||||
void init(std::vector<InputInfo> input_values);
|
||||
void apply(DynamicPrintConfig *config,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue