From 3af0fa3c741b9c8a0f871c84eacbbf7c8f4c68b4 Mon Sep 17 00:00:00 2001 From: buddsean Date: Fri, 16 Apr 2021 14:27:17 +1000 Subject: [PATCH 1/2] calculate scroll based on childs relative position to scrolledpanel --- wx/lib/scrolledpanel.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/wx/lib/scrolledpanel.py b/wx/lib/scrolledpanel.py index e4c482af93..c2839ff188 100644 --- a/wx/lib/scrolledpanel.py +++ b/wx/lib/scrolledpanel.py @@ -173,6 +173,23 @@ def OnChildFocus(self, evt): evt.Skip() + def GetChildRectRelativeToSelf(self, child: wx.Window): + """ + Same as `child.GetRect()` except the position returned is relative + to this ScrolledPanel rather than the child's parent. + + :param wx.Window `child`: any :class:`wx.Window` - derived control. + + .. note:: window.GetRect returns the size of a window, and its position + relative to its parent. When calculating ScrollChildIntoView, the + position relative to its parent is not relevant unless the parent + is the ScrolledPanel itself. + """ + cr = child.GetScreenRect() + spr = self.GetScreenPosition() + return wx.Rect(cr.x - spr.x, cr.y - spr.y, cr.width, cr.height) + + def ScrollChildIntoView(self, child): """ Scroll the panel so that the specified child window is in view. @@ -187,7 +204,7 @@ def ScrollChildIntoView(self, child): sppu_x, sppu_y = self.GetScrollPixelsPerUnit() vs_x, vs_y = self.GetViewStart() - cr = child.GetRect() + cr = self.GetChildRectRelativeToSelf(child) clntsz = self.GetClientSize() new_vs_x, new_vs_y = -1, -1 From 22e4dc3e89d95bf900f6ea23aff113f9ed410f46 Mon Sep 17 00:00:00 2001 From: Sean Budd Date: Tue, 20 Apr 2021 14:23:42 +1000 Subject: [PATCH 2/2] change from spr to spp --- wx/lib/scrolledpanel.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wx/lib/scrolledpanel.py b/wx/lib/scrolledpanel.py index c2839ff188..d320ae401e 100644 --- a/wx/lib/scrolledpanel.py +++ b/wx/lib/scrolledpanel.py @@ -186,8 +186,8 @@ def GetChildRectRelativeToSelf(self, child: wx.Window): is the ScrolledPanel itself. """ cr = child.GetScreenRect() - spr = self.GetScreenPosition() - return wx.Rect(cr.x - spr.x, cr.y - spr.y, cr.width, cr.height) + spp = self.GetScreenPosition() + return wx.Rect(cr.x - spp.x, cr.y - spp.y, cr.width, cr.height) def ScrollChildIntoView(self, child):