mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-09 10:16:50 +00:00
Refactor Tooltip Button (#12848)
refactors tooltipbutton, one common implementation, one common shortcut data structure, add tooltip button to text gizmo, consistent shortcut wording Co-authored-by: Hanno Witzleb <hannowitzleb@gmail.com>
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include "slic3r/Utils/UndoRedo.hpp"
|
||||
#include "libslic3r/AppConfig.hpp"
|
||||
#include "libslic3r/TriangleMeshSlicer.hpp"
|
||||
#include "GLGizmoUtils.hpp"
|
||||
|
||||
#include "imgui/imgui_internal.h"
|
||||
#include "slic3r/GUI/Field.hpp"
|
||||
@@ -1186,16 +1187,21 @@ bool GLGizmoCut3D::on_init()
|
||||
// initiate info shortcuts
|
||||
const wxString ctrl = GUI::shortkey_ctrl_prefix();
|
||||
const wxString alt = GUI::shortkey_alt_prefix();
|
||||
const wxString shift = _L("Shift+");
|
||||
const wxString shift = GUI::shortkey_shift_prefix();
|
||||
|
||||
m_shortcuts_cut.push_back(std::make_pair(shift + _L("Drag"), _L("Draw cut line")));
|
||||
m_shortcuts_cut = {
|
||||
{_L("Drag"), _L("Move cut line")},
|
||||
{shift + _L("Drag"), _L("Draw cut line")}
|
||||
};
|
||||
|
||||
m_shortcuts_connector.push_back(std::make_pair(_L("Left click"), _L("Add connector")));
|
||||
m_shortcuts_connector.push_back(std::make_pair(_L("Right click"), _L("Remove connector")));
|
||||
m_shortcuts_connector.push_back(std::make_pair(_L("Drag"), _L("Move connector")));
|
||||
m_shortcuts_connector.push_back(std::make_pair(shift + _L("Left click"), _L("Add connector to selection")));
|
||||
m_shortcuts_connector.push_back(std::make_pair(alt + _L("Left click"), _L("Remove connector from selection")));
|
||||
m_shortcuts_connector.push_back(std::make_pair(ctrl + "A", _L("Select all connectors")));
|
||||
m_shortcuts_connector = {
|
||||
{_L("Left mouse button"), _L("Add connector")},
|
||||
{_L("Right mouse button"), _L("Remove connector")},
|
||||
{_L("Drag"), _L("Move connector")},
|
||||
{shift + _L("Left mouse button"), _L("Add connector to selection")},
|
||||
{alt + _L("Left mouse button"), _L("Remove connector from selection")},
|
||||
{ctrl + "A", _L("Select all connectors")},
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -2313,8 +2319,7 @@ void GLGizmoCut3D::render_connectors_input_window(CutConnectors &connectors, flo
|
||||
ImGui::Separator();
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(6.0f, 10.0f));
|
||||
float get_cur_y = ImGui::GetContentRegionMax().y + ImGui::GetFrameHeight() + y;
|
||||
show_tooltip_information(x, get_cur_y);
|
||||
render_tooltip_button(x, y);
|
||||
|
||||
float f_scale = m_parent.get_gizmos_manager().get_layout_scale();
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(6.0f, 4.0f * f_scale));
|
||||
@@ -2757,7 +2762,7 @@ void GLGizmoCut3D::render_cut_plane_input_window(CutConnectors &connectors, floa
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(6.0f, 10.0f));
|
||||
float get_cur_y = ImGui::GetContentRegionMax().y + ImGui::GetFrameHeight() + y;
|
||||
show_tooltip_information(x, get_cur_y);
|
||||
render_tooltip_button(x, get_cur_y);
|
||||
|
||||
float f_scale = m_parent.get_gizmos_manager().get_layout_scale();
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(6.0f, 4.0f * f_scale));
|
||||
@@ -2917,43 +2922,11 @@ void GLGizmoCut3D::on_render_input_window(float x, float y, float bottom_limit)
|
||||
render_debug_input_window(x);
|
||||
}
|
||||
|
||||
void GLGizmoCut3D::show_tooltip_information(float x, float y)
|
||||
void GLGizmoCut3D::render_tooltip_button(float x, float y)
|
||||
{
|
||||
auto &shortcuts = m_connectors_editing ? m_shortcuts_connector : m_shortcuts_cut;
|
||||
auto& shortcuts = m_connectors_editing ? m_shortcuts_connector : m_shortcuts_cut;
|
||||
|
||||
float caption_max = 0.f;
|
||||
for (const auto &short_cut : shortcuts) {
|
||||
caption_max = std::max(caption_max, m_imgui->calc_text_size(short_cut.first).x);
|
||||
}
|
||||
|
||||
ImTextureID normal_id = m_parent.get_gizmos_manager().get_icon_texture_id(GLGizmosManager::MENU_ICON_NAME::IC_TOOLBAR_TOOLTIP);
|
||||
ImTextureID hover_id = m_parent.get_gizmos_manager().get_icon_texture_id(GLGizmosManager::MENU_ICON_NAME::IC_TOOLBAR_TOOLTIP_HOVER);
|
||||
|
||||
caption_max += m_imgui->calc_text_size(std::string_view{": "}).x + 35.f;
|
||||
|
||||
float scale = m_parent.get_scale();
|
||||
#ifdef WIN32
|
||||
int dpi = get_dpi_for_window(wxGetApp().GetTopWindow());
|
||||
scale *= (float) dpi / (float) DPI_DEFAULT;
|
||||
#endif // WIN32
|
||||
ImVec2 button_size = ImVec2(25 * scale, 25 * scale); // ORCA: Use exact resolution will prevent blur on icon
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, {0, 0}); // ORCA: Dont add padding
|
||||
ImGui::ImageButton3(normal_id, hover_id, button_size);
|
||||
|
||||
if (ImGui::IsItemHovered()) {
|
||||
ImGui::BeginTooltip2(ImVec2(x, y));
|
||||
auto draw_text_with_caption = [this, &caption_max](const wxString &caption, const wxString &text) {
|
||||
m_imgui->text_colored(ImGuiWrapper::COL_ACTIVE, caption);
|
||||
ImGui::SameLine(caption_max);
|
||||
m_imgui->text_colored(ImGuiWrapper::COL_WINDOW_BG, text);
|
||||
};
|
||||
|
||||
for (const auto &short_cut : shortcuts)
|
||||
draw_text_with_caption(short_cut.first + ": ", short_cut.second);
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
ImGui::PopStyleVar(2);
|
||||
GLGizmoUtils::render_tooltip_button(m_imgui, m_parent, shortcuts, x, y);
|
||||
}
|
||||
|
||||
bool GLGizmoCut3D::is_outside_of_cut_contour(size_t idx, const CutConnectors& connectors, const Vec3d cur_pos)
|
||||
|
||||
Reference in New Issue
Block a user