https://kotlinlang.org logo
Title
k

Kebbin

12/01/2021, 1:56 AM
What parameters / metrics / dimensions give each @Composable item it's Clickable area on screen? Can the shape or area be customised? Thanks!
When rotating X or Y axis of an item, the click sensing area for each item is increased massively, and is shifted based on its relative position on the screen. It's like as if there is a substantial invisible Z component that rears up and moves.
r

romainguy

12/01/2021, 2:39 AM
X/Y rotations are 3D rotations
k

Kebbin

12/01/2021, 2:40 AM
Yes, so why does the clickable area shift?
r

romainguy

12/01/2021, 2:40 AM
And unless the default projection has changed compared to Views it will indeed "massively increase" the touch target (but it should be the same as what's visible if you paint the bounds)
Maybe your rotation pivot is not the item's center?
k

Kebbin

12/01/2021, 2:44 AM
I have a small number of items placed across the Surface, spread across the screen, to test these things. They work when Rotating Z, but not X or Y. The rotation point for everything is the centre of the screen. Actually, I think when the tilted objects are panned to the centre, they are more evenly responsive, but still a massive touch target. If I rotate back in X, the target grows in Y.
Even tho the drawn item shrinks in Y as it should.
If I can find what affects the clickable target, I can prob adjust it. When adjusting the view projection using matrices, the targets just remain in their original position, hence trying this way now.
I tried finding a way to draw a custom outline for an object based on different perceived view angles, but only found basic Shape options. I can draw custom shapes on the canvas, but the clickable target remains square for a Box. Maybe I need to try placing a different type of clickable object that's more customisable. Like a button perhaps?
Another thought I had was not to even rotate the X axis, but just simulate it like everything else. Might be easier to control the shapes if they remain flat.
If I can control the clickable targets, or have them match the shapes!
More experimenting. Thanks very much for your time and help again!
r

romainguy

12/01/2021, 4:38 AM
@Nader Jawad couls confirm but rotations should be properly handled with touch events. Either it sounds like a bug or I don't quite understand your description. A video and/or a reproducible example would be extremely helpful
k

Kebbin

12/01/2021, 4:58 AM
Hopefully this shows clearly enough what's happening. The rotations work, but the objects targets don't act as expected.
They work fine until they are rotated in X or Y. These are just clickable Boxes on a Surface, with a grid background Image.
I tried adding a
.clip(GenericShape {
random path shape, but the selection targets didn't change, even just in flat 2D presentation. They still clicked using the underlying Box shape/size.
r

romainguy

12/01/2021, 4:34 PM
Hit tests are only based on boxes, optionally transformed via rotations/scales/shear/etc. but that’s about it
Seems like there’s a bug in the handling of those events when a transform matrix is applied
Could you please file a bug?
n

Nader Jawad

12/01/2021, 5:01 PM
I know that we take into account matrix transformations for touch events on the most recently graphicsLayer that is being transformed. Just to verify can you try running the same code on Android so we can verify if it is a transformation issue on desktop vs Android vs compose in general? cc @George Mount who also worked on touch transformations for matrix transformed layers.
g

George Mount

12/01/2021, 9:18 PM
It should work, and I'm sure we have some tests, but I think the tests are all with easy 90 degree turns. Our tests may not have sufficient coverage for this and it is worth double-checking.
k

Kebbin

12/02/2021, 12:58 AM
Hello all! Thanks so much for your time on this. This is a "hobby" project, for the railway modelling hobby in general, and I'm not set up to do Android testing yet sorry! www.dcc-ex.com to promote the team... I have perspective transforms working by drawing into the Canvas of the Surface using
drawWithContent ... drawContent()
, but that just transforms the "visual", leaving the "base" objects in their original position. Thanks very very much to @Igor Demin for lighting the path to that! I'm now trying some different perspective maths to adjust the actual base object position on screen, and actually just rotate the Surface itself, to try and retain the link between object "base" and "visual". As soon as the X axis is tilted back, the targets go haywire. I'll get back on it again tonight. (~8hrs, I'm in Aus!) Thanks, Colin Grabham, NSW.
Hello all! I prob won't be much help, but can you please show me where to start looking for the code that handles the touch targets, and the rotation adjustments? I'm curious how it works. I've just updated my program to Compose 1.0.0.
@Nader Jawad @George Mount Can you point me to the code that handles the click targets? Thanks!