From c2ac0baa0525808cbca4a015ca2afd5d6dcffb1a Mon Sep 17 00:00:00 2001 From: yw4z Date: Tue, 5 May 2026 19:07:15 +0300 Subject: [PATCH] Fix iconic button sizes on widgets (paint modes and gcode viewer buttons) (#13365) * init * update --- src/slic3r/GUI/GCodeViewer.cpp | 28 +++++------ src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp | 42 ++++++++-------- src/slic3r/GUI/Gizmos/GLGizmoFuzzySkin.cpp | 43 +++++++++-------- .../GUI/Gizmos/GLGizmoMmuSegmentation.cpp | 37 +++++++------- src/slic3r/GUI/Gizmos/GLGizmoSeam.cpp | 44 +++++++++-------- src/slic3r/GUI/ImGuiWrapper.cpp | 48 +++++++++++++++++++ src/slic3r/GUI/ImGuiWrapper.hpp | 1 + 7 files changed, 145 insertions(+), 98 deletions(-) diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index 678a99deb5..b1792c6966 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -516,13 +516,15 @@ void GCodeViewer::SequentialView::Marker::render_position_window(const libvgcode } ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding , 3.f * m_scale); - ImGui::PushStyleVar(ImGuiStyleVar_ButtonTextAlign, ImVec2(.5f, .5f)); + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding , ImVec2(2.f, 2.f) * m_scale); ImGui::PushStyleColor(ImGuiCol_Button , ImVec4(0, 0, 0, 0)); ImGui::PushStyleColor(ImGuiCol_ButtonHovered , ImVec4(84 / 255.f, 84 / 255.f, 90 / 255.f, 1.f)); ImGui::PushStyleColor(ImGuiCol_ButtonActive , ImVec4(84 / 255.f, 84 / 255.f, 90 / 255.f, 1.f)); const float main_wnd_height = ImGui::GetWindowHeight(); - if (ImGui::Button(into_u8(properties_shown ? ImGui::UnfoldButtonIcon : ImGui::FoldButtonIcon).c_str(), ImVec2(24.f, 24.f) * m_scale)) { + // ORCA use glyph based button for fixing button sizes changing depends on used font size on platform + const wchar_t foldIcon = properties_shown ? ImGui::UnfoldButtonIcon : ImGui::FoldButtonIcon; + if (imgui.glyph_button(foldIcon, ImVec2(16.f, 16.f) * m_scale)) { properties_shown = !properties_shown; static float main_wnd_height_temp = ImGui::GetWindowHeight(); static float first_click = true; @@ -537,7 +539,8 @@ void GCodeViewer::SequentialView::Marker::render_position_window(const libvgcode ImGui::SameLine(); - ImGui::SetCursorPosY(ImGui::GetCursorPosY() - ImGui::GetStyle().FramePadding.y); // aligns button with next group + if(!properties_shown) + ImGui::SetCursorPosY(ImGui::GetCursorPosY() - ImGui::GetStyle().FramePadding.y); // aligns button with next group ImGui::BeginGroup(); // group contents to make information area more compact @@ -3327,29 +3330,26 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv ImGui::Dummy({ window_padding, window_padding }); ImGui::Dummy({ window_padding, window_padding }); ImGui::SameLine(window_padding * 2); // ORCA Ignores item spacing to get perfect window margins since since this part uses dummies for window padding - std::wstring btn_name; - if (m_fold) - btn_name = ImGui::UnfoldButtonIcon; - else - btn_name = ImGui::FoldButtonIcon; + ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0)); ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(84 / 255.f, 84 / 255.f, 90 / 255.f, 1.f)); ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(84 / 255.f, 84 / 255.f, 90 / 255.f, 1.f)); - float calc_padding = (ImGui::GetFrameHeight() - 16 * m_scale) / 2; // ORCA calculated padding for 16x16 icon - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(calc_padding, calc_padding)); // ORCA Center icon with frame padding - ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f * m_scale); // ORCA Match button style with combo box + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding , ImVec2(2.f, 2.f) * m_scale); + ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f * m_scale); // ORCA Match button style with combo box - float button_width = 16 * m_scale + calc_padding * 2; // ORCA match buttons height with combo box - if (ImGui::Button(into_u8(btn_name).c_str(), ImVec2(button_width, button_width))) { + // ORCA use glyph based button for fixing button sizes changing depends on used font size on platform + const wchar_t foldIcon = m_fold ? ImGui::UnfoldButtonIcon : ImGui::FoldButtonIcon; + if (imgui.glyph_button(foldIcon, ImVec2(16.f, 16.f) * m_scale)) { m_fold = !m_fold; } ImGui::SameLine(); const wchar_t gCodeToggle = ImGui::gCodeButtonIcon; - if (ImGui::Button(into_u8(gCodeToggle).c_str(), ImVec2(button_width, button_width))) { + if (imgui.glyph_button(gCodeToggle, ImVec2(16.f, 16.f) * m_scale)) { wxGetApp().toggle_show_gcode_window(); wxGetApp().plater()->get_current_canvas3D()->post_event(SimpleEvent(wxEVT_PAINT)); } + ImGui::PopStyleColor(3); ImGui::PopStyleVar(2); diff --git a/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp b/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp index 7aa347b9c2..7af55915d5 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoFdmSupports.cpp @@ -191,6 +191,12 @@ void GLGizmoFdmSupports::on_render_input_window(float x, float y, float bottom_l if (! m_c->selection_info()->model_object()) return; + float scale = m_parent.get_scale(); + #ifdef WIN32 + int dpi = get_dpi_for_window(wxGetApp().GetTopWindow()); + scale *= (float) dpi / (float) DPI_DEFAULT; + #endif // WIN32 + // BBS wchar_t old_tool = m_current_tool; @@ -258,30 +264,24 @@ void GLGizmoFdmSupports::on_render_input_window(float x, float y, float bottom_l std::array tool_tips = { _L("Circle"), _L("Sphere"), _L("Fill"), _L("Gap Fill") }; for (int i = 0; i < tool_ids.size(); i++) { - std::string str_label = std::string("##"); - std::wstring btn_name = icons[i] + boost::nowide::widen(str_label); + //std::string str_label = std::string("##"); + //std::wstring btn_name = icons[i] + boost::nowide::widen(str_label); if (i != 0) ImGui::SameLine((empty_button_width + m_imgui->scaled(1.75f)) * i + m_imgui->scaled(1.3f)); - ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0); - ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.f, 0.f, 0.f, 0.f)); // ORCA Removes button background on dark mode - ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.f, 1.f, 1.f, 1.f)); // ORCA: Fixes icon rendered without colors while using Light theme - if (m_current_tool == tool_ids[i]) { - ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.f, 0.59f, 0.53f, 0.25f)); // ORCA use orca color for selected tool / brush - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.f, 0.59f, 0.53f, 0.25f)); // ORCA use orca color for selected tool / brush - ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.f, 0.59f, 0.53f, 0.30f)); // ORCA use orca color for selected tool / brush - ImGui::PushStyleColor(ImGuiCol_Border, ImGuiWrapper::COL_ORCA); // ORCA use orca color for border on selected tool / brush - ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0); - ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 1.0); - } - bool btn_clicked = ImGui::Button(into_u8(btn_name).c_str()); - if (m_current_tool == tool_ids[i]) - { - ImGui::PopStyleColor(4); - ImGui::PopStyleVar(2); - } - ImGui::PopStyleColor(2); - ImGui::PopStyleVar(1); + bool is_active = m_current_tool == tool_ids[i]; + ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.f); + ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding , 3.f * scale); + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding , ImVec2(4.f * scale, 4.f * scale)); + ImGui::PushStyleColor(ImGuiCol_Text , ImVec4(1,1,1,1)); // ORCA Fixes icon rendered without colors while using Light theme + ImGui::PushStyleColor(ImGuiCol_Button , is_active ? ImVec4(0.f, .59f, .53f, .25f) : ImVec4(0,0,0,0)); // ORCA + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, is_active ? ImVec4(0.f, .59f, .53f, .25f) : ImVec4(.6f,.6f,.6f,.2f)); // ORCA + ImGui::PushStyleColor(ImGuiCol_ButtonActive , is_active ? ImVec4(0.f, .59f, .53f, .30f) : ImVec4(0,0,0,0)); // ORCA + ImGui::PushStyleColor(ImGuiCol_Border , is_active ? ImGuiWrapper::COL_ORCA : ImVec4(0,0,0,0)); // ORCA + ImGui::PushStyleColor(ImGuiCol_BorderActive , is_active ? ImGuiWrapper::COL_ORCA : ImVec4(0,0,0,0)); // ORCA matched color for fixing flicker on click + bool btn_clicked = m_imgui->glyph_button(icons[i], ImVec2(16.f * scale, 16.f * scale)); // ORCA glyph_button for fixing unequal paddings + ImGui::PopStyleColor(6); + ImGui::PopStyleVar(3); if (btn_clicked && m_current_tool != tool_ids[i]) { m_current_tool = tool_ids[i]; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoFuzzySkin.cpp b/src/slic3r/GUI/Gizmos/GLGizmoFuzzySkin.cpp index 80470de7ad..d80687544e 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoFuzzySkin.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoFuzzySkin.cpp @@ -117,6 +117,12 @@ void GLGizmoFuzzySkin::on_render_input_window(float x, float y, float bottom_lim if (!mo) return; + float scale = m_parent.get_scale(); + #ifdef WIN32 + int dpi = get_dpi_for_window(wxGetApp().GetTopWindow()); + scale *= (float) dpi / (float) DPI_DEFAULT; + #endif // WIN32 + const DynamicPrintConfig &obj_cfg = mo->config.get(); const float approx_height = m_imgui->scaled(22.f); @@ -192,29 +198,24 @@ void GLGizmoFuzzySkin::on_render_input_window(float x, float y, float bottom_lim icons = { ImGui::CircleButtonIcon, ImGui::SphereButtonIcon, ImGui::TriangleButtonIcon, ImGui::FillButtonIcon }; std::array tool_tips = { _L("Circle"), _L("Sphere"), _L("Triangle"), _L("Fill") }; for (int i = 0; i < tool_ids.size(); i++) { - std::string str_label = std::string(""); - std::wstring btn_name = icons[i] + boost::nowide::widen(str_label); + //std::string str_label = std::string(""); + //std::wstring btn_name = icons[i] + boost::nowide::widen(str_label); if (i != 0) ImGui::SameLine((empty_button_width + m_imgui->scaled(1.75f)) * i + m_imgui->scaled(1.5f)); - ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0); - ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.f, 0.f, 0.f, 0.f)); // ORCA Removes button background on dark mode - ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.f, 1.f, 1.f, 1.f)); // ORCA Fixes icon rendered without colors while using Light theme - if (m_current_tool == tool_ids[i]) { - ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.f, 0.59f, 0.53f, 0.25f)); // ORCA use orca color for selected tool / brush - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.f, 0.59f, 0.53f, 0.25f)); // ORCA use orca color for selected tool / brush - ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.f, 0.59f, 0.53f, 0.30f)); // ORCA use orca color for selected tool / brush - ImGui::PushStyleColor(ImGuiCol_Border, ImGuiWrapper::COL_ORCA); // ORCA use orca color for border on selected tool / brush - ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0); - ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 1.0); - } - bool btn_clicked = ImGui::Button(into_u8(btn_name).c_str()); - if (m_current_tool == tool_ids[i]) - { - ImGui::PopStyleColor(4); - ImGui::PopStyleVar(2); - } - ImGui::PopStyleColor(2); - ImGui::PopStyleVar(1); + + bool is_active = m_current_tool == tool_ids[i]; + ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.f); + ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding , 3.f * scale); + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding , ImVec2(4.f * scale, 4.f * scale)); + ImGui::PushStyleColor(ImGuiCol_Text , ImVec4(1,1,1,1)); // ORCA Fixes icon rendered without colors while using Light theme + ImGui::PushStyleColor(ImGuiCol_Button , is_active ? ImVec4(0.f, .59f, .53f, .25f) : ImVec4(0,0,0,0)); // ORCA + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, is_active ? ImVec4(0.f, .59f, .53f, .25f) : ImVec4(.6f,.6f,.6f,.2f)); // ORCA + ImGui::PushStyleColor(ImGuiCol_ButtonActive , is_active ? ImVec4(0.f, .59f, .53f, .30f) : ImVec4(0,0,0,0)); // ORCA + ImGui::PushStyleColor(ImGuiCol_Border , is_active ? ImGuiWrapper::COL_ORCA : ImVec4(0,0,0,0)); // ORCA + ImGui::PushStyleColor(ImGuiCol_BorderActive , is_active ? ImGuiWrapper::COL_ORCA : ImVec4(0,0,0,0)); // ORCA matched color for fixing flicker on click + bool btn_clicked = m_imgui->glyph_button(icons[i], ImVec2(16.f * scale, 16.f * scale)); // ORCA glyph_button for fixing unequal paddings + ImGui::PopStyleColor(6); + ImGui::PopStyleVar(3); if (btn_clicked && m_current_tool != tool_ids[i]) { m_current_tool = tool_ids[i]; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp b/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp index de27cd6bc7..72e880f85d 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoMmuSegmentation.cpp @@ -483,29 +483,24 @@ void GLGizmoMmuSegmentation::on_render_input_window(float x, float y, float bott icons = { ImGui::CircleButtonIcon, ImGui::SphereButtonIcon, ImGui::TriangleButtonIcon, ImGui::HeightRangeIcon, ImGui::FillButtonIcon, ImGui::GapFillIcon }; std::array tool_tips = { _L("Circle"), _L("Sphere"), _L("Triangle"), _L("Height Range"), _L("Fill"), _L("Gap Fill") }; for (int i = 0; i < tool_ids.size(); i++) { - std::string str_label = std::string(""); - std::wstring btn_name = icons[i] + boost::nowide::widen(str_label); + //std::string str_label = std::string(""); + //std::wstring btn_name = icons[i] + boost::nowide::widen(str_label); if (i != 0) ImGui::SameLine((empty_button_width + m_imgui->scaled(1.75f)) * i + m_imgui->scaled(1.5f)); - ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0); - ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.f, 0.f, 0.f, 0.f)); // ORCA Removes button background on dark mode - ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.f, 1.f, 1.f, 1.f)); // ORCA Fixes icon rendered without colors while using Light theme - if (m_current_tool == tool_ids[i]) { - ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.f, 0.59f, 0.53f, 0.25f)); // ORCA use orca color for selected tool / brush - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.f, 0.59f, 0.53f, 0.25f)); // ORCA use orca color for selected tool / brush - ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.f, 0.59f, 0.53f, 0.30f)); // ORCA use orca color for selected tool / brush - ImGui::PushStyleColor(ImGuiCol_Border, ImGuiWrapper::COL_ORCA); // ORCA use orca color for border on selected tool / brush - ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0); - ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 1.0); - } - bool btn_clicked = ImGui::Button(into_u8(btn_name).c_str()); - if (m_current_tool == tool_ids[i]) - { - ImGui::PopStyleColor(4); - ImGui::PopStyleVar(2); - } - ImGui::PopStyleColor(2); - ImGui::PopStyleVar(1); + + bool is_active = m_current_tool == tool_ids[i]; + ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.f); + ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding , 3.f * scale); + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding , ImVec2(4.f * scale, 4.f * scale)); + ImGui::PushStyleColor(ImGuiCol_Text , ImVec4(1,1,1,1)); // ORCA Fixes icon rendered without colors while using Light theme + ImGui::PushStyleColor(ImGuiCol_Button , is_active ? ImVec4(0.f, .59f, .53f, .25f) : ImVec4(0,0,0,0)); // ORCA + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, is_active ? ImVec4(0.f, .59f, .53f, .25f) : ImVec4(.6f,.6f,.6f,.2f)); // ORCA + ImGui::PushStyleColor(ImGuiCol_ButtonActive , is_active ? ImVec4(0.f, .59f, .53f, .30f) : ImVec4(0,0,0,0)); // ORCA + ImGui::PushStyleColor(ImGuiCol_Border , is_active ? ImGuiWrapper::COL_ORCA : ImVec4(0,0,0,0)); // ORCA + ImGui::PushStyleColor(ImGuiCol_BorderActive , is_active ? ImGuiWrapper::COL_ORCA : ImVec4(0,0,0,0)); // ORCA matched color for fixing flicker on click + bool btn_clicked = m_imgui->glyph_button(icons[i], ImVec2(16.f * scale, 16.f * scale)); // ORCA glyph_button for fixing unequal paddings + ImGui::PopStyleColor(6); + ImGui::PopStyleVar(3); if (btn_clicked && m_current_tool != tool_ids[i]) { m_current_tool = tool_ids[i]; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSeam.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSeam.cpp index 8790fd430d..1051c5ab3c 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSeam.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSeam.cpp @@ -121,6 +121,12 @@ void GLGizmoSeam::on_render_input_window(float x, float y, float bottom_limit) if (! m_c->selection_info()->model_object()) return; + float scale = m_parent.get_scale(); + #ifdef WIN32 + int dpi = get_dpi_for_window(wxGetApp().GetTopWindow()); + scale *= (float) dpi / (float) DPI_DEFAULT; + #endif // WIN32 + const float approx_height = m_imgui->scaled(12.5f); y = std::min(y, bottom_limit - approx_height); //BBS: GUI refactor: move gizmo to the right @@ -170,29 +176,25 @@ void GLGizmoSeam::on_render_input_window(float x, float y, float bottom_limit) icons = { ImGui::CircleButtonIcon, ImGui::SphereButtonIcon }; std::array tool_tips = { _L("Circle"), _L("Sphere")}; for (int i = 0; i < tool_ids.size(); i++) { - std::string str_label = std::string("##"); - std::wstring btn_name = icons[i] + boost::nowide::widen(str_label); + //std::string str_label = std::string("##"); + //std::wstring btn_name = icons[i] + boost::nowide::widen(str_label); if (i != 0) ImGui::SameLine((empty_button_width + m_imgui->scaled(1.75f)) * i + m_imgui->scaled(1.3f)); - ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0); - ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.f, 0.f, 0.f, 0.f)); // ORCA Removes button background on dark mode - ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.f, 1.f, 1.f, 1.f)); // ORCA: Fixes icon rendered without colors while using Light theme - if (m_current_tool == tool_ids[i]) { - ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.f, 0.59f, 0.53f, 0.25f)); // ORCA use orca color for selected tool / brush - ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.f, 0.59f, 0.53f, 0.25f)); // ORCA use orca color for selected tool / brush - ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.f, 0.59f, 0.53f, 0.30f)); // ORCA use orca color for selected tool / brush - ImGui::PushStyleColor(ImGuiCol_Border, ImGuiWrapper::COL_ORCA); // ORCA use orca color for border on selected tool / brush - ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.0); - ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 1.0); - } - bool btn_clicked = ImGui::Button(into_u8(btn_name).c_str()); - if (m_current_tool == tool_ids[i]) - { - ImGui::PopStyleColor(4); - ImGui::PopStyleVar(2); - } - ImGui::PopStyleColor(2); - ImGui::PopStyleVar(1); + + bool is_active = m_current_tool == tool_ids[i]; + ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 1.f); + ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding , 3.f * scale); + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding , ImVec2(4.f * scale, 4.f * scale)); + ImGui::PushStyleColor(ImGuiCol_Text , ImVec4(1,1,1,1)); // ORCA Fixes icon rendered without colors while using Light theme + ImGui::PushStyleColor(ImGuiCol_Button , is_active ? ImVec4(0.f, .59f, .53f, .25f) : ImVec4(0,0,0,0)); // ORCA + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, is_active ? ImVec4(0.f, .59f, .53f, .25f) : ImVec4(.6f,.6f,.6f,.2f)); // ORCA + ImGui::PushStyleColor(ImGuiCol_ButtonActive , is_active ? ImVec4(0.f, .59f, .53f, .30f) : ImVec4(0,0,0,0)); // ORCA + ImGui::PushStyleColor(ImGuiCol_Border , is_active ? ImGuiWrapper::COL_ORCA : ImVec4(0,0,0,0)); // ORCA + ImGui::PushStyleColor(ImGuiCol_BorderActive , is_active ? ImGuiWrapper::COL_ORCA : ImVec4(0,0,0,0)); // ORCA matched color for fixing flicker on click + bool btn_clicked = m_imgui->glyph_button(icons[i], ImVec2(16.f * scale, 16.f * scale)); // ORCA glyph_button for fixing unequal paddings + ImGui::PopStyleColor(6); + ImGui::PopStyleVar(3); + if (btn_clicked && m_current_tool != tool_ids[i]) { m_current_tool = tool_ids[i]; for (auto& triangle_selector : m_triangle_selectors) { diff --git a/src/slic3r/GUI/ImGuiWrapper.cpp b/src/slic3r/GUI/ImGuiWrapper.cpp index 67f33ce851..85f59d31e5 100644 --- a/src/slic3r/GUI/ImGuiWrapper.cpp +++ b/src/slic3r/GUI/ImGuiWrapper.cpp @@ -908,6 +908,54 @@ bool ImGuiWrapper::button(const wxString& label, const ImVec2 &size, bool enable return (enable) ? res : false; } +// ORCA Glyph based button for correctly rendering icon size based Glyph +// excludes spacings after Glyph and centers icon properly +// compared to image_button this supports styling +bool ImGuiWrapper::glyph_button(wchar_t icon_char, ImVec2 icon_size) +{ + ImDrawList* draw_list = ImGui::GetWindowDrawList(); + ImFont* font = ImGui::GetFont(); + ImGuiStyle& style = ImGui::GetStyle(); + ImVec2 padding = style.FramePadding; + float border_w = style.FrameBorderSize; + float rounding = style.FrameRounding; + std::string icon_str = into_u8(icon_char); + const char* icon = icon_str.c_str(); + + float width = icon_size.x + (padding.x + border_w) * 2.f; + float height = icon_size.y + (padding.y + border_w) * 2.f; + ImVec2 rc_min = ImGui::GetCursorScreenPos(); + ImVec2 rc_max = ImVec2(rc_min.x + width, rc_min.y + height); + + ImGui::Dummy(ImVec2(width, height)); + + ImGuiCol bg_color = ImGuiCol_Button; + ImGuiCol border_color = ImGuiCol_Border; + bool clicked = false; + + if (ImGui::IsMouseHoveringRect(rc_min, rc_max)) { + bg_color = ImGuiCol_ButtonHovered; + if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) { + bg_color = ImGuiCol_ButtonActive; + border_color = ImGuiCol_BorderShadow; + clicked = true; + } + } + + draw_list->AddRectFilled(rc_min, rc_max, ImGui::GetColorU32(bg_color), rounding); + + if (border_w > 0.f) + draw_list->AddRect(rc_min, rc_max, ImGui::GetColorU32(border_color), rounding, 0, border_w); + + ImVec2 text_pos = ImVec2( + rc_min.x + (width - font->FontSize) * .5f, + rc_min.y + (height - font->FontSize) * .5f + ); + draw_list->AddText(font, font->FontSize, text_pos, ImGui::GetColorU32(ImGuiCol_Text), icon); + + return clicked; +} + bool ImGuiWrapper::radio_button(const wxString &label, bool active) { auto label_utf8 = into_u8(label); diff --git a/src/slic3r/GUI/ImGuiWrapper.hpp b/src/slic3r/GUI/ImGuiWrapper.hpp index 21ca91013b..a2b8476c71 100644 --- a/src/slic3r/GUI/ImGuiWrapper.hpp +++ b/src/slic3r/GUI/ImGuiWrapper.hpp @@ -133,6 +133,7 @@ public: bool bbl_button(const wxString &label, const wxString& tooltip = {}); bool button(const wxString& label, float width, float height); bool button(const wxString& label, const ImVec2 &size, bool enable); // default size = ImVec2(0.f, 0.f) + bool glyph_button(wchar_t icon_char, ImVec2 icon_size); // ORCA bool radio_button(const wxString &label, bool active); static ImVec4 to_ImVec4(const ColorRGB &color); bool input_double(const std::string &label, const double &value, const std::string &format = "%.3f");