From b1935669967e6040c7c007a67448eebf71bac0cd Mon Sep 17 00:00:00 2001 From: "liz.li" Date: Thu, 16 Mar 2023 10:01:35 +0800 Subject: [PATCH] FIX:Canvas focus (STUDIO-2384) https://github.com/bambulab/BambuStudio/issues/1465 https://github.com/bambulab/BambuStudio/issues/1339 two enhancement: Moving mouse cursor to GLCanvas shouldn't cause focused parameter textbox lose its focus. When GLCanvas lose focus, the imgui textInput should lose focus too. Change-Id: I616bb98f87c2dc59669220d3b5a6c3e120a8f06f --- src/slic3r/GUI/GLCanvas3D.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index fdeb870aa..e6d740276 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -2778,6 +2778,11 @@ void GLCanvas3D::bind_event_handlers() m_canvas->Bind(wxEVT_RIGHT_DCLICK, &GLCanvas3D::on_mouse, this); m_canvas->Bind(wxEVT_PAINT, &GLCanvas3D::on_paint, this); m_canvas->Bind(wxEVT_SET_FOCUS, &GLCanvas3D::on_set_focus, this); + m_canvas->Bind(wxEVT_KILL_FOCUS, [this](wxFocusEvent& evt) { + ImGui::SetWindowFocus(nullptr); + render(); + evt.Skip(); + }); m_event_handlers_bound = true; m_canvas->Bind(wxEVT_GESTURE_PAN, &GLCanvas3D::on_gesture, this); @@ -3748,6 +3753,8 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) m_mouse.ignore_left_up = true; m_tooltip.set_in_imgui(false); if (imgui->update_mouse_data(evt)) { + if (evt.LeftDown() && m_canvas != nullptr) + m_canvas->SetFocus(); m_mouse.position = evt.Leaving() ? Vec2d(-1.0, -1.0) : pos.cast(); m_tooltip.set_in_imgui(true); render(); @@ -3910,7 +3917,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) p = p->GetParent(); auto *top_level_wnd = dynamic_cast(p); if (top_level_wnd && top_level_wnd->IsActive() && !wxGetApp().get_side_menu_popup_status()) - m_canvas->SetFocus(); + ;// m_canvas->SetFocus(); m_mouse.position = pos.cast(); m_tooltip_enabled = false; // 1) forces a frame render to ensure that m_hover_volume_idxs is updated even when the user right clicks while