omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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?

    Pythonista
    hierarchy view transformation
    2
    3
    2082
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • shinyformica
      shinyformica last edited by shinyformica

      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.

      1 Reply Last reply Reply Quote 0
      • JonB
        JonB last edited by

        convert_point works for me.
        https://gist.github.com/040a32c7b8bd90611113065dd4dd194f

        touch 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.....

        1 Reply Last reply Reply Quote 0
        • shinyformica
          shinyformica last edited by

          @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.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors