Initial delay for ImGUI-based tooltip
This commit is contained in:
parent
7a1fa3d847
commit
166389e6a8
@ -68,5 +68,7 @@
|
||||
|
||||
// Enable tooltips for GLCanvas3D using ImGUI
|
||||
#define ENABLE_CANVAS_TOOLTIP_USING_IMGUI (1 && ENABLE_2_2_0_FINAL)
|
||||
#define ENABLE_CANVAS_DELAYED_TOOLTIP_USING_IMGUI (1 && ENABLE_CANVAS_TOOLTIP_USING_IMGUI)
|
||||
|
||||
|
||||
#endif // _technologies_h_
|
||||
|
@ -61,9 +61,11 @@
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include "DoubleSlider.hpp"
|
||||
#if !ENABLE_CANVAS_DELAYED_TOOLTIP_USING_IMGUI
|
||||
#if ENABLE_RENDER_STATISTICS
|
||||
#include <chrono>
|
||||
#endif // ENABLE_RENDER_STATISTICS
|
||||
#endif // !ENABLE_CANVAS_DELAYED_TOOLTIP_USING_IMGUI
|
||||
|
||||
#include <imgui/imgui_internal.h>
|
||||
|
||||
@ -1371,16 +1373,52 @@ void GLCanvas3D::Labels::render(const std::vector<const ModelInstance*>& sorted_
|
||||
}
|
||||
|
||||
#if ENABLE_CANVAS_TOOLTIP_USING_IMGUI
|
||||
void GLCanvas3D::Tooltip::render(const Vec2d& mouse_position) const
|
||||
#if ENABLE_CANVAS_DELAYED_TOOLTIP_USING_IMGUI
|
||||
void GLCanvas3D::Tooltip::set_text(const std::string& text)
|
||||
{
|
||||
if (m_text != text)
|
||||
{
|
||||
if (m_text.empty())
|
||||
m_start_time = std::chrono::high_resolution_clock::now();
|
||||
|
||||
m_text = text;
|
||||
}
|
||||
}
|
||||
#endif // ENABLE_CANVAS_DELAYED_TOOLTIP_USING_IMGUI
|
||||
|
||||
#if ENABLE_CANVAS_DELAYED_TOOLTIP_USING_IMGUI
|
||||
void GLCanvas3D::Tooltip::render(const Vec2d& mouse_position, GLCanvas3D& canvas) const
|
||||
#else
|
||||
void GLCanvas3D::Tooltip::render(const Vec2d& mouse_position) const
|
||||
#endif // ENABLE_CANVAS_DELAYED_TOOLTIP_USING_IMGUI
|
||||
{
|
||||
#if ENABLE_CANVAS_DELAYED_TOOLTIP_USING_IMGUI
|
||||
if (m_text.empty() || std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - m_start_time).count() < 500)
|
||||
{
|
||||
if (!m_text.empty())
|
||||
// request another frame to show up later
|
||||
canvas.request_extra_frame();
|
||||
|
||||
return;
|
||||
}
|
||||
#else
|
||||
if (m_text.empty())
|
||||
return;
|
||||
#endif // ENABLE_CANVAS_DELAYED_TOOLTIP_USING_IMGUI
|
||||
|
||||
ImGuiWrapper& imgui = *wxGetApp().imgui();
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
|
||||
imgui.set_next_window_pos(mouse_position(0), mouse_position(1) + 16, ImGuiCond_Always, 0.0f, 0.0f);
|
||||
imgui.begin(_(L("canvas_tooltip")), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMouseInputs | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoDecoration);
|
||||
ImGui::BringWindowToDisplayFront(ImGui::GetCurrentWindow());
|
||||
imgui.text(m_text);
|
||||
|
||||
#if ENABLE_CANVAS_DELAYED_TOOLTIP_USING_IMGUI
|
||||
// force re-render while the windows gets to its final size (it may take several frames)
|
||||
if (ImGui::GetWindowContentRegionWidth() + 2.0f * ImGui::GetStyle().WindowPadding.x != ImGui::CalcWindowExpectedSize(ImGui::GetCurrentWindow()).x)
|
||||
canvas.request_extra_frame();
|
||||
#endif // ENABLE_CANVAS_DELAYED_TOOLTIP_USING_IMGUI
|
||||
|
||||
imgui.end();
|
||||
ImGui::PopStyleVar();
|
||||
}
|
||||
@ -1977,7 +2015,11 @@ void GLCanvas3D::render()
|
||||
|
||||
set_tooltip(tooltip);
|
||||
|
||||
#if ENABLE_CANVAS_DELAYED_TOOLTIP_USING_IMGUI
|
||||
m_tooltip.render(m_mouse.position, *this);
|
||||
#else
|
||||
m_tooltip.render(m_mouse.position);
|
||||
#endif // ENABLE_CANVAS_DELAYED_TOOLTIP_USING_IMGUI
|
||||
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
|
||||
|
||||
wxGetApp().plater()->get_mouse3d_controller().render_settings_dialog(*this);
|
||||
|
@ -3,6 +3,9 @@
|
||||
|
||||
#include <stddef.h>
|
||||
#include <memory>
|
||||
#if ENABLE_CANVAS_DELAYED_TOOLTIP_USING_IMGUI
|
||||
#include <chrono>
|
||||
#endif // ENABLE_CANVAS_DELAYED_TOOLTIP_USING_IMGUI
|
||||
|
||||
#include "3DScene.hpp"
|
||||
#include "GLToolbar.hpp"
|
||||
@ -393,10 +396,18 @@ private:
|
||||
class Tooltip
|
||||
{
|
||||
std::string m_text;
|
||||
#if ENABLE_CANVAS_DELAYED_TOOLTIP_USING_IMGUI
|
||||
std::chrono::steady_clock::time_point m_start_time;
|
||||
#endif // ENABLE_CANVAS_DELAYED_TOOLTIP_USING_IMGUI
|
||||
|
||||
public:
|
||||
#if ENABLE_CANVAS_DELAYED_TOOLTIP_USING_IMGUI
|
||||
void set_text(const std::string& text);
|
||||
void render(const Vec2d& mouse_position, GLCanvas3D& canvas) const;
|
||||
#else
|
||||
void set_text(const std::string& text) { m_text = text; }
|
||||
void render(const Vec2d& mouse_position) const;
|
||||
#endif // ENABLE_CANVAS_DELAYED_TOOLTIP_USING_IMGUI
|
||||
};
|
||||
#endif // ENABLE_CANVAS_TOOLTIP_USING_IMGUI
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user