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.


    ui.ImageView contents not cropping to View bounds

    Pythonista
    5
    9
    3841
    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.
    • iAmMortos
      iAmMortos last edited by iAmMortos

      I have a ui.ImageView with content_mode = ui.CONTENT_SCALE_ASPECT_FILL. The documentation implies that using this content mode will crop the parts of the image that fall outside the bounds of the ImageView.

      ui.CONTENT_SCALE_ASPECT_FILL
      Scale the content to fill the size of the view. Some portion of the content may be clipped to fill the view’s bounds.

      However, the excess image simply overflows outside the bounds of the View, spilling over other elements, making me sad.

      Two questions:

      1. Is this a bug? Or is this the expected functionality of ui.CONTENT_SCALE_ASPECT_FILL?
      2. If this is indeed the intended behavior, how do you crop a ui.Image simply?

      Regarding question 2, I've gotten cropping to work using the PIL.Image.crop(), and converting that cropped PIL.Image into a ui.Image, but this is expensive, and I need these images to be loaded quickly in real-time.

      cvp 1 Reply Last reply Reply Quote 0
      • cvp
        cvp @iAmMortos last edited by cvp

        @iAmMortos be careful, you say ...FIT and you give the doc of ...FILL

        But, you are right, this is a new bug, not existing in the past, with ui.CONTENT_SCALE_ASPECT_FILL

        1 Reply Last reply Reply Quote 1
        • iAmMortos
          iAmMortos last edited by iAmMortos

          Oops. I goofed writing the post. But in my code, I am indeed using ui.CONTENT_SCALE_ASPECT_FILL. I've updated my original post.

          cvp 1 Reply Last reply Reply Quote 0
          • cvp
            cvp @iAmMortos last edited by

            @iAmMortos Finally, I think it has always been like that. You need to use an intermediate View

            1 Reply Last reply Reply Quote 1
            • iAmMortos
              iAmMortos last edited by

              This I can do! Thanks for the tip!

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

                There is an attribute, maybe only in objc, clipstoBounds, which defines whether a views contents spill out past the edge of it's bounds. I forget if the python ui.Views have clips_to_bounds.

                cvp 1 Reply Last reply Reply Quote 2
                • cvp
                  cvp @JonB last edited by

                  @JonB never seen in Pythonista UI, not in the doc.

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

                    It’s a uiView property, supposed to regulate the behavior of a view’s subviews.

                    Instance Property
                    clipsToBounds
                    A Boolean value that determines whether subviews are confined to the bounds of the view.
                    
                    1 Reply Last reply Reply Quote 2
                    • mikael
                      mikael @iAmMortos last edited by

                      @iAmMortos, Views clip to their bounds by default, but for some reason ImageView does not, which explains some behaviour I did not understand previously, thanks.

                      As others have said, you can fix this without extra views with:

                      iv.objc_instance.setClipsToBounds_(True)
                      
                      1 Reply Last reply Reply Quote 2
                      • First post
                        Last post
                      Powered by NodeBB Forums | Contributors