Implemented workaround for the mouse wheel in Search Window and Undo/Redo lists on the Plater

Workaround is used because of ImGui::GetIO().MouseWheel returns zero always!
This commit is contained in:
YuSanka 2020-04-27 16:00:54 +02:00
parent 93170870e8
commit 60ae7d67e9
4 changed files with 56 additions and 30 deletions

View file

@ -3458,6 +3458,15 @@ void GLCanvas3D::on_mouse_wheel(wxMouseEvent& evt)
} }
} }
// If the Search window or Undo/Redo list is opened,
// update them according to the event
if (m_main_toolbar.is_item_pressed("search") ||
m_undoredo_toolbar.is_item_pressed("undo") ||
m_undoredo_toolbar.is_item_pressed("redo")) {
m_mouse_wheel = int((double)evt.GetWheelRotation() / (double)evt.GetWheelDelta());
return;
}
// Inform gizmos about the event so they have the opportunity to react. // Inform gizmos about the event so they have the opportunity to react.
if (m_gizmos.on_mouse_wheel(evt)) if (m_gizmos.on_mouse_wheel(evt))
return; return;
@ -4465,7 +4474,7 @@ bool GLCanvas3D::_render_undo_redo_stack(const bool is_undo, float pos_x) const
em *= m_retina_helper->get_scale_factor(); em *= m_retina_helper->get_scale_factor();
#endif #endif
if (imgui->undo_redo_list(ImVec2(18 * em, 26 * em), is_undo, &string_getter, hovered, selected)) if (imgui->undo_redo_list(ImVec2(18 * em, 26 * em), is_undo, &string_getter, hovered, selected, m_mouse_wheel))
m_imgui_undo_redo_hovered_pos = hovered; m_imgui_undo_redo_hovered_pos = hovered;
else else
m_imgui_undo_redo_hovered_pos = -1; m_imgui_undo_redo_hovered_pos = -1;
@ -4519,7 +4528,7 @@ bool GLCanvas3D::_render_search_list(float pos_x) const
imgui->search_list(ImVec2(45 * em, 30 * em), &search_string_getter, s, imgui->search_list(ImVec2(45 * em, 30 * em), &search_string_getter, s,
sidebar.get_searcher().view_params, sidebar.get_searcher().view_params,
selected, edited); selected, edited, m_mouse_wheel);
search_line = s; search_line = s;
delete [] s; delete [] s;

View file

@ -506,6 +506,7 @@ private:
#endif // ENABLE_RENDER_STATISTICS #endif // ENABLE_RENDER_STATISTICS
mutable int m_imgui_undo_redo_hovered_pos{ -1 }; mutable int m_imgui_undo_redo_hovered_pos{ -1 };
mutable int m_mouse_wheel {0};
int m_selected_extruder; int m_selected_extruder;
Labels m_labels; Labels m_labels;

View file

@ -379,7 +379,40 @@ bool ImGuiWrapper::combo(const wxString& label, const std::vector<std::string>&
return res; return res;
} }
bool ImGuiWrapper::undo_redo_list(const ImVec2& size, const bool is_undo, bool (*items_getter)(const bool , int , const char**), int& hovered, int& selected) // Scroll up for one item
static void scroll_up()
{
ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow;
float item_size_y = window->DC.PrevLineSize.y + g.Style.ItemSpacing.y;
float win_top = window->Scroll.y;
ImGui::SetScrollY(win_top - item_size_y);
}
// Scroll down for one item
static void scroll_down()
{
ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow;
float item_size_y = window->DC.PrevLineSize.y + g.Style.ItemSpacing.y;
float win_top = window->Scroll.y;
ImGui::SetScrollY(win_top + item_size_y);
}
static void process_mouse_wheel(int& mouse_wheel)
{
if (mouse_wheel > 0)
scroll_up();
else if (mouse_wheel < 0)
scroll_down();
mouse_wheel = 0;
}
bool ImGuiWrapper::undo_redo_list(const ImVec2& size, const bool is_undo, bool (*items_getter)(const bool , int , const char**), int& hovered, int& selected, int& mouse_wheel)
{ {
bool is_hovered = false; bool is_hovered = false;
ImGui::ListBoxHeader("", size); ImGui::ListBoxHeader("", size);
@ -401,6 +434,9 @@ bool ImGuiWrapper::undo_redo_list(const ImVec2& size, const bool is_undo, bool (
i++; i++;
} }
if (is_hovered)
process_mouse_wheel(mouse_wheel);
ImGui::ListBoxFooter(); ImGui::ListBoxFooter();
return is_hovered; return is_hovered;
} }
@ -563,30 +599,6 @@ static void scroll_y(int hover_id)
ImGui::SetScrollY(win_top - item_size_y); ImGui::SetScrollY(win_top - item_size_y);
} }
// Scroll up for one item
static void scroll_up()
{
ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow;
float item_size_y = window->DC.PrevLineSize.y + g.Style.ItemSpacing.y;
float win_top = window->Scroll.y;
ImGui::SetScrollY(win_top - item_size_y);
}
// Scroll down for one item
static void scroll_down()
{
ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow;
float item_size_y = window->DC.PrevLineSize.y + g.Style.ItemSpacing.y;
float win_top = window->Scroll.y;
ImGui::SetScrollY(win_top + item_size_y);
}
// Use this function instead of ImGui::IsKeyPressed. // Use this function instead of ImGui::IsKeyPressed.
// ImGui::IsKeyPressed is related for *GImGui.IO.KeysDownDuration[user_key_index] // ImGui::IsKeyPressed is related for *GImGui.IO.KeysDownDuration[user_key_index]
// And after first key pressing IsKeyPressed() return "true" always even if key wasn't pressed // And after first key pressing IsKeyPressed() return "true" always even if key wasn't pressed
@ -602,7 +614,7 @@ 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** label, const char** tooltip), char* search_str, 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) Search::OptionViewParameters& view_params, int& selected, bool& edited, int& mouse_wheel)
{ {
// ImGui::ListBoxHeader("", size); // ImGui::ListBoxHeader("", size);
{ {
@ -678,6 +690,10 @@ void ImGuiWrapper::search_list(const ImVec2& size_, bool (*items_getter)(int, co
scroll_y(mouse_hovered); scroll_y(mouse_hovered);
// Process mouse wheel
if (mouse_hovered > 0)
process_mouse_wheel(mouse_wheel);
// process Up/DownArrows and Enter // process Up/DownArrows and Enter
process_key_down(ImGuiKey_UpArrow, [&hovered_id, mouse_hovered]() { process_key_down(ImGuiKey_UpArrow, [&hovered_id, mouse_hovered]() {
if (mouse_hovered > 0) if (mouse_hovered > 0)

View file

@ -77,9 +77,9 @@ public:
bool slider_float(const std::string& label, float* v, float v_min, float v_max, const char* format = "%.3f", float power = 1.0f); bool slider_float(const std::string& label, float* v, float v_min, float v_max, const char* format = "%.3f", float power = 1.0f);
bool slider_float(const wxString& label, float* v, float v_min, float v_max, const char* format = "%.3f", float power = 1.0f); 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 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); bool undo_redo_list(const ImVec2& size, const bool is_undo, bool (*items_getter)(const bool, int, const char**), int& hovered, int& selected, int& mouse_wheel);
void search_list(const ImVec2& size, bool (*items_getter)(int, const char** label, const char** tooltip), char* search_str, 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); Search::OptionViewParameters& view_params, int& selected, bool& edited, int& mouse_wheel);
void disabled_begin(bool disabled); void disabled_begin(bool disabled);
void disabled_end(); void disabled_end();