diff --git a/src/slic3r/GUI/ParamsPanel.cpp b/src/slic3r/GUI/ParamsPanel.cpp index 2922f7bc9..15d42631c 100644 --- a/src/slic3r/GUI/ParamsPanel.cpp +++ b/src/slic3r/GUI/ParamsPanel.cpp @@ -275,11 +275,61 @@ ParamsPanel::ParamsPanel( wxWindow* parent, wxWindowID id, const wxPoint& pos, c wxVSCROLL) // hide hori-bar will cause hidden field mis-position { // ShowScrollBar(GetHandle(), SB_BOTH, FALSE); + Bind(wxEVT_SCROLL_CHANGED, [this](auto &e) { + wxWindow *child = dynamic_cast(e.GetEventObject()); + if (child != this) + EnsureVisible(child); + }); } virtual bool ShouldScrollToChildOnFocus(wxWindow *child) { + EnsureVisible(child); return false; } + void EnsureVisible(wxWindow* win) + { + const wxRect viewRect(m_targetWindow->GetClientRect()); + const wxRect winRect(m_targetWindow->ScreenToClient(win->GetScreenPosition()), win->GetSize()); + if (viewRect.Contains(winRect)) { + return; + } + if (winRect.GetWidth() > viewRect.GetWidth() || winRect.GetHeight() > viewRect.GetHeight()) { + return; + } + int stepx, stepy; + GetScrollPixelsPerUnit(&stepx, &stepy); + + int startx, starty; + GetViewStart(&startx, &starty); + // first in vertical direction: + if (stepy > 0) { + int diff = 0; + + if (winRect.GetTop() < 0) { + diff = winRect.GetTop(); + } else if (winRect.GetBottom() > viewRect.GetHeight()) { + diff = winRect.GetBottom() - viewRect.GetHeight() + 1; + // round up to next scroll step if we can't get exact position, + // so that the window is fully visible: + diff += stepy - 1; + } + starty = (starty * stepy + diff) / stepy; + } + // then horizontal: + if (stepx > 0) { + int diff = 0; + if (winRect.GetLeft() < 0) { + diff = winRect.GetLeft(); + } else if (winRect.GetRight() > viewRect.GetWidth()) { + diff = winRect.GetRight() - viewRect.GetWidth() + 1; + // round up to next scroll step if we can't get exact position, + // so that the window is fully visible: + diff += stepx - 1; + } + startx = (startx * stepx + diff) / stepx; + } + Scroll(startx, starty); + } }; m_page_view = new PageScrolledWindow(page_parent); diff --git a/src/slic3r/GUI/Search.cpp b/src/slic3r/GUI/Search.cpp index 6c4034894..85f662cb6 100644 --- a/src/slic3r/GUI/Search.cpp +++ b/src/slic3r/GUI/Search.cpp @@ -644,7 +644,7 @@ void SearchDialog::Dismiss() void SearchDialog::Die() { - Destroy(); + wxPopupTransientWindow::Dismiss(); wxCommandEvent event(wxCUSTOMEVT_EXIT_SEARCH); wxPostEvent(search_line, event); } diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index b2e402d4e..59bf8da70 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -1503,8 +1503,14 @@ void Tab::activate_option(const std::string& opt_key, const wxString& category) Field* field = get_field(opt_key); // focused selected field - if (field) + if (field) { set_focus(field->getWindow()); + if (!field->getWindow()->HasFocus()) { + wxScrollEvent evt(wxEVT_SCROLL_CHANGED); + evt.SetEventObject(field->getWindow()); + wxPostEvent(m_page_view, evt); + } + } //else if (category == "Single extruder MM setup") { // // When we show and hide "Single extruder MM setup" page, // // related options are still in the search list