diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 8220db8d7..2f6808c04 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -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. if (m_gizmos.on_mouse_wheel(evt)) 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(); #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; else 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, sidebar.get_searcher().view_params, - selected, edited); + selected, edited, m_mouse_wheel); search_line = s; delete [] s; diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 73ec88a13..e36a0bee5 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -506,6 +506,7 @@ private: #endif // ENABLE_RENDER_STATISTICS mutable int m_imgui_undo_redo_hovered_pos{ -1 }; + mutable int m_mouse_wheel {0}; int m_selected_extruder; Labels m_labels; diff --git a/src/slic3r/GUI/ImGuiWrapper.cpp b/src/slic3r/GUI/ImGuiWrapper.cpp index bbe7c088b..ea8b2afd3 100644 --- a/src/slic3r/GUI/ImGuiWrapper.cpp +++ b/src/slic3r/GUI/ImGuiWrapper.cpp @@ -379,7 +379,40 @@ bool ImGuiWrapper::combo(const wxString& label, const std::vector& 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; ImGui::ListBoxHeader("", size); @@ -401,6 +434,9 @@ bool ImGuiWrapper::undo_redo_list(const ImVec2& size, const bool is_undo, bool ( i++; } + if (is_hovered) + process_mouse_wheel(mouse_wheel); + ImGui::ListBoxFooter(); return is_hovered; } @@ -563,30 +599,6 @@ static void scroll_y(int hover_id) 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. // 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 @@ -602,7 +614,7 @@ static void process_key_down(ImGuiKey imgui_key, std::function f) } 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); { @@ -678,6 +690,10 @@ void ImGuiWrapper::search_list(const ImVec2& size_, bool (*items_getter)(int, co scroll_y(mouse_hovered); + // Process mouse wheel + if (mouse_hovered > 0) + process_mouse_wheel(mouse_wheel); + // process Up/DownArrows and Enter process_key_down(ImGuiKey_UpArrow, [&hovered_id, mouse_hovered]() { if (mouse_hovered > 0) diff --git a/src/slic3r/GUI/ImGuiWrapper.hpp b/src/slic3r/GUI/ImGuiWrapper.hpp index a5195ad39..6a1e27dcb 100644 --- a/src/slic3r/GUI/ImGuiWrapper.hpp +++ b/src/slic3r/GUI/ImGuiWrapper.hpp @@ -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 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& 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, - 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_end();