Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculate Scroll based on Childs relative position to ScrolledPanel #1950

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion wx/lib/scrolledpanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
spp = self.GetScreenPosition()
return wx.Rect(cr.x - spp.x, cr.y - spp.y, cr.width, cr.height)


def ScrollChildIntoView(self, child):
"""
Scroll the panel so that the specified child window is in view.
Expand All @@ -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

Expand Down