From 7831b4bd0736bc163cef9cf395a333b85a2b1341 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Tue, 26 Jul 2022 14:28:56 +0200 Subject: [PATCH] Notifications: hovering eject button will show tooltip even with idle mouse --- src/slic3r/GUI/NotificationManager.cpp | 25 ++++++++++++++++++++++--- src/slic3r/GUI/NotificationManager.hpp | 3 +++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/slic3r/GUI/NotificationManager.cpp b/src/slic3r/GUI/NotificationManager.cpp index 737b8aa6c..2e74270da 100644 --- a/src/slic3r/GUI/NotificationManager.cpp +++ b/src/slic3r/GUI/NotificationManager.cpp @@ -789,6 +789,7 @@ void NotificationManager::ExportFinishedNotification::render_eject_button(ImGuiW ImVec2(win_pos.x - m_line_height * 2.5f, win_pos.y + win_size.y), true)) { + button_text = ImGui::EjectHoverButton; // tooltip long time_now = wxGetLocalTime(); @@ -798,12 +799,21 @@ void NotificationManager::ExportFinishedNotification::render_eject_button(ImGuiW imgui.text(_u8L("Eject drive") + " " + GUI::shortkey_ctrl_prefix() + "T"); ImGui::EndTooltip(); ImGui::PopStyleColor(); + // somehow the tooltip wont show if the render doesnt run twice + if (m_hover_once) { + wxGetApp().plater()->get_current_canvas3D()->schedule_extra_frame(0); + m_hover_once = false; + } } - if (m_hover_time == 0) + if (m_hover_time == 0) { m_hover_time = time_now; - } else + m_hover_once = true; + wxGetApp().plater()->get_current_canvas3D()->schedule_extra_frame(1500); + } + } else { m_hover_time = 0; - + m_hover_once = false; + } ImVec2 button_pic_size = ImGui::CalcTextSize(button_text.c_str()); ImVec2 button_size(button_pic_size.x * 1.25f, button_pic_size.y * 1.25f); ImGui::SetCursorPosX(win_size.x - m_line_height * 5.0f); @@ -828,6 +838,15 @@ void NotificationManager::ExportFinishedNotification::render_eject_button(ImGuiW } ImGui::PopStyleColor(5); } + +bool NotificationManager::ExportFinishedNotification::update_state(bool paused, const int64_t delta) +{ + bool ret = PopNotification::update_state(paused, delta); + if (!ret && m_hover_time != 0 && m_hover_time < wxGetLocalTime()) + return true; + return false; +} + bool NotificationManager::ExportFinishedNotification::on_text_click() { open_folder(m_export_dir_path); diff --git a/src/slic3r/GUI/NotificationManager.hpp b/src/slic3r/GUI/NotificationManager.hpp index d5dd9b48d..cbad18d8a 100644 --- a/src/slic3r/GUI/NotificationManager.hpp +++ b/src/slic3r/GUI/NotificationManager.hpp @@ -668,6 +668,8 @@ private: bool m_to_removable; std::string m_export_path; std::string m_export_dir_path; + + bool update_state(bool paused, const int64_t delta) override; protected: // Reserves space on right for more buttons void count_spaces() override; @@ -687,6 +689,7 @@ private: void on_eject_click(); // local time of last hover for showing tooltip long m_hover_time { 0 }; + bool m_hover_once { false }; bool m_eject_pending { false }; };