OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::GUI::GLCanvas3D::Tooltip Class Reference
Collaboration diagram for Slic3r::GUI::GLCanvas3D::Tooltip:

Public Member Functions

bool is_empty () const
void set_text (const std::string &text)
void render (const Vec2d &mouse_position, GLCanvas3D &canvas)
void set_in_imgui (bool b)
bool is_in_imgui () const

Private Attributes

std::string m_text
std::chrono::steady_clock::time_point m_start_time
bool m_in_imgui = false

Detailed Description

Member Function Documentation

◆ is_empty()

bool Slic3r::GUI::GLCanvas3D::Tooltip::is_empty ( ) const
inline
555{ return m_text.empty(); }
std::string m_text
Definition GLCanvas3D.hpp:549

References m_text.

◆ is_in_imgui()

bool Slic3r::GUI::GLCanvas3D::Tooltip::is_in_imgui ( ) const
inline
560{ return m_in_imgui; }
bool m_in_imgui
Definition GLCanvas3D.hpp:552

References m_in_imgui.

◆ render()

void Slic3r::GUI::GLCanvas3D::Tooltip::render ( const Vec2d & mouse_position,
GLCanvas3D & canvas )
1339{
1340 static ImVec2 size(0.0f, 0.0f);
1341
1342 auto validate_position = [](const Vec2d& position, const GLCanvas3D& canvas, const ImVec2& wnd_size) {
1343 const Size cnv_size = canvas.get_canvas_size();
1344 const float x = std::clamp((float)position.x(), 0.0f, (float)cnv_size.get_width() - wnd_size.x);
1345 const float y = std::clamp((float)position.y() + 16.0f, 0.0f, (float)cnv_size.get_height() - wnd_size.y);
1346 return Vec2f(x, y);
1347 };
1348
1349 if (m_text.empty()) {
1350 m_start_time = std::chrono::steady_clock::now();
1351 return;
1352 }
1353
1354 // draw the tooltip as hidden until the delay is expired
1355 // use a value of alpha slightly different from 0.0f because newer imgui does not calculate properly the window size if alpha == 0.0f
1356 const float alpha = (std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - m_start_time).count() < 500) ? 0.01f : 1.0f;
1357
1358 const Vec2f position = validate_position(mouse_position, canvas, size);
1359
1360 ImGuiWrapper& imgui = *wxGetApp().imgui();
1361 ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
1362 ImGui::PushStyleVar(ImGuiStyleVar_Alpha, alpha);
1363 imgui.set_next_window_pos(position.x(), position.y(), ImGuiCond_Always, 0.0f, 0.0f);
1364
1365 imgui.begin(wxString("canvas_tooltip"), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMouseInputs | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoFocusOnAppearing);
1366 ImGui::BringWindowToDisplayFront(ImGui::GetCurrentWindow());
1367 ImGui::TextUnformatted(m_text.c_str());
1368
1369 // force re-render while the windows gets to its final size (it may take several frames) or while hidden
1370#if ENABLE_ENHANCED_IMGUI_SLIDER_FLOAT
1371 if (alpha < 1.0f || ImGui::GetWindowContentRegionWidth() + 2.0f * ImGui::GetStyle().WindowPadding.x != ImGui::CalcWindowNextAutoFitSize(ImGui::GetCurrentWindow()).x)
1372 imgui.set_requires_extra_frame();
1373#else
1374 if (alpha < 1.0f || ImGui::GetWindowContentRegionWidth() + 2.0f * ImGui::GetStyle().WindowPadding.x != ImGui::CalcWindowNextAutoFitSize(ImGui::GetCurrentWindow()).x)
1375 canvas.request_extra_frame();
1376#endif // ENABLE_ENHANCED_IMGUI_SLIDER_FLOAT
1377
1378 size = ImGui::GetWindowSize();
1379
1380 imgui.end();
1381 ImGui::PopStyleVar(2);
1382}
std::chrono::steady_clock::time_point m_start_time
Definition GLCanvas3D.hpp:550
GLCanvas3D(wxGLCanvas *canvas, Bed3D &bed)
Definition GLCanvas3D.cpp:1594
Eigen::Matrix< float, 2, 1, Eigen::DontAlign > Vec2f
Definition Point.hpp:64
Eigen::Matrix< double, 2, 1, Eigen::DontAlign > Vec2d
Definition Point.hpp:67

References Slic3r::GUI::GLCanvas3D::GLCanvas3D(), Slic3r::GUI::ImGuiWrapper::begin(), Slic3r::GUI::ImGuiWrapper::end(), Slic3r::GUI::GLCanvas3D::get_canvas_size(), Slic3r::GUI::Size::get_height(), Slic3r::GUI::Size::get_width(), m_start_time, m_text, render(), Slic3r::GUI::GLCanvas3D::request_extra_frame(), Slic3r::GUI::ImGuiWrapper::set_next_window_pos(), and Slic3r::GUI::ImGuiWrapper::set_requires_extra_frame().

Referenced by render().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_in_imgui()

void Slic3r::GUI::GLCanvas3D::Tooltip::set_in_imgui ( bool b)
inline
559{ m_in_imgui = b; }

References m_in_imgui.

◆ set_text()

void Slic3r::GUI::GLCanvas3D::Tooltip::set_text ( const std::string & text)
1333{
1334 // If the mouse is inside an ImGUI dialog, then the tooltip is suppressed.
1335 m_text = m_in_imgui ? std::string() : text;
1336}

References m_in_imgui, m_text, and set_text().

Referenced by set_text().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_in_imgui

bool Slic3r::GUI::GLCanvas3D::Tooltip::m_in_imgui = false
private

Referenced by is_in_imgui(), set_in_imgui(), and set_text().

◆ m_start_time

std::chrono::steady_clock::time_point Slic3r::GUI::GLCanvas3D::Tooltip::m_start_time
private

Referenced by render().

◆ m_text

std::string Slic3r::GUI::GLCanvas3D::Tooltip::m_text
private

Referenced by is_empty(), render(), and set_text().


The documentation for this class was generated from the following files:
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/GLCanvas3D.hpp
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/GLCanvas3D.cpp