Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Getting untransformed position of a widget in a superview?
-
Here's an overly complicated scenario for you:
I have a widget in a parent ui.View, and that parent view has been transformed, a scale and translation only - no rotation. That view is in turn a subview of another ui.View, and then finally that view is the content view of a ui.ScrollView...like this:
ui.ScrollView +-- subview A +-- subview B (transform applied) +-- widget
So what I'd like to do is somehow get the position of that final widget in the local coordinates of the top scrollview. But just trying to convert the x,y position of the widget via ui.convert_point() doesn't seem to work for me? At least, the resulting point doesn't seem to be in the right place.
Open to suggestions...I feel like I need to use the inverse transform to get a valid starting point for conversion.
-
convert_point works for me.
https://gist.github.com/040a32c7b8bd90611113065dd4dd194ftouch the innermost view, which then converts its local point up the chain, and everybody draws in their local frame. note only the upper left corner of the drawn rect match, since that is the the point drawn by the rect. if you are drawing rects, you need to use convert_rect.
Also, I vaguely remember some bugs related to convert point and fullscreen mode, perhaps when keyboard was present.....
-
@JonB looks like you're right...I was doing something incorrectly, though now I'm not sure what.
If I simply take the widget.bounds() and ui.convert_rect() to the ScrollView, I get a valid rectangle in the ScrollView coordinate space. So all good.
Thanks.