When I'm doing a DrawScope that really wants to be...
# compose
t
When I'm doing a DrawScope that really wants to be around the center of the view, I can do a
translate(size.x.half, size.y.half) { ... }
instead of having to constantly add/subtract from the computed center. But when setting up my pointerInput()... I have to do all of the translation math if I want to work relative to the center. Or is there a way one can do something similiar as the translate in DrawScope? I didn't find anything... Also, why can't pointerInput use Size instead of IntSize? I already dislike the highly overloaded use of the term 'size' in graphics code. I wish they would have used extent, or some other different word, so size could generally mean "linear counts of things". I just feel like I end up pushing type conversion code all over with these kinds of things.
r
Size is defined in float which is not the right domain for pointer events.
t
i knew if i whined, i'd get answers to the wrong part of my question 😄
r
I can answer the rest: no there's no equivalent to translate(){}
Because pointer events are delivered to you and don't belong to a stateful object like DrawScope
t
so where does the size property come from in the InputScope?
(if it's not "stateful")
r
The scope has state but the events themselves are delivered to it. Setting transforms on it could be error prone as events are delivered and gestures detected over time (which is not the case for DrawScope)
I guess pointerInput itself could take a transform parameter but I'm not sure how common of a need that is 🤷‍♂️
nod 1
t
as far as IntSize vs just Size, it's an odd argument, because so many of the arguments to the detectors are Offsets (which work in float) as opposed to IntOffset(is there even one?) Either way, I fixed my problem thusly:
Copy code
val PointerInputScope.extent: Size get() = size.toSize()
val PointerInputScope.center: Offset get() = extent.half
r
The size of the input scope is derived from measured size, aka layout bounds, which are expressed as integers on purpose
That's what I meant earlier, sorry I was being too terse
m
If you capture your transforms in a transform Matrix, then you can just apply the inverse transform to the pointer input coordinates.