I've been trying to create an interface prompts for a Camera Roll pic (photos module) and displays it, which is fairly simple using ImageView()
and ui.Image.from_data(photos.pick_image(raw_data=True))
with ui.CONTENT_SCALE_ASPECT_FIT
. The image will properly fit the bounds of the screen and adapt as you rotate the device.
My problem has been that I want to create touch events, but ImageView()
can't handle those, so I assume I have to create a custom View on top of it, however, since I want the touch events to be available solely within the image displayed below, I must make this "touch view" the same size as the "image view".
Trying ImageView.image.size
will give me the original dimensions, while I want the dimensions after the ui.content_mode
is applied. My best bet right now is to run a function that calculates the outcome from the content_mode
based on the ui.get_screen_size()
, however, this one always delivers the dimensions in portrait mode, meanwhile I don't know a way to get the device current orientation.
The question is: how to make a View with the same width and height of the image within a sibling ImageView?
Basic structure:
container = ui.View()
imageview = ui.ImageView()
imageview.image = ui.Image.from_data(photos.pick_image(raw_data=True))
imageview.flex = 'WH'
imageview.content_mode = `ui.CONTENT_SCALE_ASPECT_FIT`
touchview = ui.View()
touchview.width = ?
touchview.height = ?
Thank you.