PointerInputChange
-
Cmn
class PointerInputChange
Describes a change that has occurred for a particular pointer, as well as how much of the change has been consumed (meaning, used by a node in the UI).
The position represents the position of the pointer relative to the element that this PointerInputChange is being dispatched to.
Note 1: A PointerEvent's PointerEventType is the cause of an event and the associated PointerInputChange's properties reflecting that. Most of those are exclusive, in other words, a Press/Release PointerEventType will not cause a scrollDelta change and a Scroll PointerEventType will not cause a pressed or previousPressed change. However, either a a Scroll or a Press/Release may contain a position change in its PointerInputChanges. (You can imagine one finger moving while another is lifted up.)
Examples of PointerEventType and the associated PointerInputChange property changes:
-
Press -> press will change (position may change) but scroll delta will not.
-
Release -> press will change (position may change) but scroll delta will not.
-
Move -> position will change but press and scroll delta will not.
-
Scroll -> scroll delta will change (position may change) but press will not.
Note 2: The position values can be outside the actual bounds of the element itself meaning the numbers can be negative or larger than the element bounds.
The previousPosition represents the position of the pointer offset to the current position of the pointer relative to the screen.
This means that position and previousPosition can always be used to understand how much a pointer has moved relative to an element, even if that element is moving along with the changes to the pointer. For example, if a pointer touches a 1x1 pixel box in the middle, position will report a position of (0, 0) when dispatched to it. If the next event moves x position 5 pixels, position will report (5, 0) and previousPosition will report (0, 0). If the box moves all 5 pixels, and the next event represents the pointer moving along the x axis for 5 more pixels, position will again report (5, 0) and previousPosition will report (0, 0).
Summary
Public constructors |
|
|---|---|
|
Cmn
|
|
|
Cmn
|
Public functions |
||
|---|---|---|
Unit |
consume()Consume change event, claiming all the corresponding change info to the caller. |
Cmn
|
PointerInputChange |
copy(Make a shallow copy of the |
Cmn
|
PointerInputChange |
copy(Make a shallow copy of the |
Cmn
|
PointerInputChange |
This function is deprecated. Partial consumption has been deprecated. |
Cmn
|
PointerInputChange |
@ExperimentalComposeUiApiMake a shallow copy of the |
Cmn
|
PointerInputChange |
copy(Make a shallow copy of the |
Cmn
|
PointerInputChange |
copy(Make a shallow copy of the |
Cmn
|
open String |
toString() |
Cmn
|
Public properties |
||
|---|---|---|
ConsumedData |
This property is deprecated. use isConsumed and consume() pair of methods instead |
Cmn
|
List<HistoricalChange> |
Optional high-frequency pointer moves in between the last two dispatched events. |
Cmn
|
PointerId |
The unique id of the pointer associated with this |
Cmn
|
Boolean |
Indicates whether the change was consumed or not. |
Cmn
|
Offset |
An |
Cmn
|
Offset |
The |
Cmn
|
Boolean |
|
Cmn
|
Float |
The pressure of the of the pointer event |
Cmn
|
Offset |
The |
Cmn
|
Boolean |
|
Cmn
|
Long |
The |
Cmn
|
Float |
A multiplicative scale factor indicating the amount of scale to perform as part of this pointer input change. |
Cmn
|
Offset |
The change in scroll position along the horizontal and vertical axes. |
Cmn
|
PointerType |
The device type that produced the event, such as |
Cmn
|
Long |
The time of the current pointer event, in milliseconds. |
Cmn
|
Extension functions |
||
|---|---|---|
Boolean |
This function is deprecated. Partial consumption has been deprecated. |
Cmn
|
Boolean |
True if this |
Cmn
|
Boolean |
True if this |
Cmn
|
Boolean |
True if this |
Cmn
|
Boolean |
True if this |
Cmn
|
Unit |
This function is deprecated. Use consume() instead |
Cmn
|
Unit |
This function is deprecated. Partial consumption has been deprecated. |
Cmn
|
Unit |
This function is deprecated. Partial consumption has been deprecated. |
Cmn
|
Boolean |
This function is deprecated. Use isOutOfBounds() that supports minimum touch target |
Cmn
|
Boolean |
PointerInputChange.isOutOfBounds(Returns |
Cmn
|
Offset |
The distance that the pointer has moved on the screen minus any distance that has been consumed. |
Cmn
|
Boolean |
This function is deprecated. Partial consumption has been deprecated. |
Cmn
|
Offset |
The distance that the pointer has moved on the screen, ignoring the fact that it might have been consumed. |
Cmn
|
Boolean |
True if this |
Cmn
|
Boolean |
True if this |
Cmn
|
Public constructors
PointerInputChange
PointerInputChange(
id: PointerId,
uptimeMillis: Long,
position: Offset,
pressed: Boolean,
previousUptimeMillis: Long,
previousPosition: Offset,
previousPressed: Boolean,
isInitiallyConsumed: Boolean,
type: PointerType = PointerType.Touch,
scrollDelta: Offset = Offset.Zero,
scaleFactor: Float = 1.0f,
panOffset: Offset = Offset.Zero
)
PointerInputChange
PointerInputChange(
id: PointerId,
uptimeMillis: Long,
position: Offset,
pressed: Boolean,
pressure: Float,
previousUptimeMillis: Long,
previousPosition: Offset,
previousPressed: Boolean,
isInitiallyConsumed: Boolean,
type: PointerType = PointerType.Touch,
scrollDelta: Offset = Offset.Zero,
scaleFactor: Float = 1.0f,
panOffset: Offset = Offset.Zero
)
| Parameters | |
|---|---|
id: PointerId |
The unique id of the pointer associated with this |
uptimeMillis: Long |
The time of the current pointer event, in milliseconds. The start ( |
position: Offset |
The |
pressed: Boolean |
|
pressure: Float |
The pressure of the of the pointer event |
previousUptimeMillis: Long |
The |
previousPosition: Offset |
The |
previousPressed: Boolean |
|
isInitiallyConsumed: Boolean |
whether the change was consumed from the start or not. This value can change over time as change is propagated through the pointer handlers. To query the actual status of the change use |
type: PointerType = PointerType.Touch |
The device type that produced the event, such as |
scrollDelta: Offset = Offset.Zero |
The change in scroll position along the horizontal and vertical axes. Note that this value is platform-dependent and is not normalized to pixel coordinates: - Desktop & Android: Measured in platform-specific mouse wheel tick units. - Web: Raw delta values directly from the browser's Also consider handling |
scaleFactor: Float = 1.0f |
A multiplicative scale factor indicating the amount of scale to perform as part of this pointer input change. A value of |
panOffset: Offset = Offset.Zero |
An |
Public functions
consume
fun consume(): Unit
Consume change event, claiming all the corresponding change info to the caller. This is usually needed when, button, when being clicked, consumed the "up" event so no other parents of this button could consume this "up" again.
"Consumption" is just an indication of the claim and each pointer input handler implementation must manually check this flag to respect it.
copy
fun copy(
id: PointerId = this.id,
currentTime: Long = this.uptimeMillis,
currentPosition: Offset = this.position,
currentPressed: Boolean = this.pressed,
previousTime: Long = this.previousUptimeMillis,
previousPosition: Offset = this.previousPosition,
previousPressed: Boolean = this.previousPressed,
type: PointerType = this.type,
scrollDelta: Offset = this.scrollDelta
): PointerInputChange
Make a shallow copy of the PointerInputChange
NOTE: Due to the need of the inner contract of the PointerInputChange, this method performs a shallow copy of the PointerInputChange. Any consume call between any of the copies will consume any other copy automatically. Therefore, copy with the new isConsumed is not possible. Consider creating a new PointerInputChange
copy
fun copy(
id: PointerId = this.id,
currentTime: Long = this.uptimeMillis,
currentPosition: Offset = this.position,
currentPressed: Boolean = this.pressed,
pressure: Float = this.pressure,
previousTime: Long = this.previousUptimeMillis,
previousPosition: Offset = this.previousPosition,
previousPressed: Boolean = this.previousPressed,
type: PointerType = this.type,
scrollDelta: Offset = this.scrollDelta
): PointerInputChange
Make a shallow copy of the PointerInputChange
NOTE: Due to the need of the inner contract of the PointerInputChange, this method performs a shallow copy of the PointerInputChange. Any consume call between any of the copies will consume any other copy automatically. Therefore, copy with the new isConsumed is not possible. Consider creating a new PointerInputChange.
copy
funcopy(
id: PointerId = this.id,
currentTime: Long = this.uptimeMillis,
currentPosition: Offset = this.position,
currentPressed: Boolean = this.pressed,
previousTime: Long = this.previousUptimeMillis,
previousPosition: Offset = this.previousPosition,
previousPressed: Boolean = this.previousPressed,
consumed: ConsumedData,
type: PointerType = this.type,
scrollDelta: Offset = this.scrollDelta
): PointerInputChange
copy
@ExperimentalComposeUiApi
fun copy(
id: PointerId = this.id,
currentTime: Long = this.uptimeMillis,
currentPosition: Offset = this.position,
currentPressed: Boolean = this.pressed,
previousTime: Long = this.previousUptimeMillis,
previousPosition: Offset = this.previousPosition,
previousPressed: Boolean = this.previousPressed,
type: PointerType = this.type,
historical: List<HistoricalChange>,
scrollDelta: Offset = this.scrollDelta
): PointerInputChange
Make a shallow copy of the PointerInputChange
NOTE: Due to the need of the inner contract of the PointerInputChange, this method performs a shallow copy of the PointerInputChange. Any consume call between any of the copies will consume any other copy automatically. Therefore, copy with the new isConsumed is not possible. Consider creating a new PointerInputChange.
copy
fun copy(
id: PointerId = this.id,
currentTime: Long = this.uptimeMillis,
currentPosition: Offset = this.position,
currentPressed: Boolean = this.pressed,
pressure: Float = this.pressure,
previousTime: Long = this.previousUptimeMillis,
previousPosition: Offset = this.previousPosition,
previousPressed: Boolean = this.previousPressed,
type: PointerType = this.type,
historical: List<HistoricalChange> = this.historical,
scrollDelta: Offset = this.scrollDelta
): PointerInputChange
Make a shallow copy of the PointerInputChange
NOTE: Due to the need of the inner contract of the PointerInputChange, this method performs a shallow copy of the PointerInputChange. Any consume call between any of the copies will consume any other copy automatically. Therefore, copy with the new isConsumed is not possible. Consider creating a new PointerInputChange.
copy
fun copy(
id: PointerId = this.id,
currentTime: Long = this.uptimeMillis,
currentPosition: Offset = this.position,
currentPressed: Boolean = this.pressed,
pressure: Float = this.pressure,
previousTime: Long = this.previousUptimeMillis,
previousPosition: Offset = this.previousPosition,
previousPressed: Boolean = this.previousPressed,
type: PointerType = this.type,
historical: List<HistoricalChange> = this.historical,
scrollDelta: Offset = this.scrollDelta,
scaleFactor: Float = this.scaleFactor,
panOffset: Offset = this.panOffset
): PointerInputChange
Make a shallow copy of the PointerInputChange
NOTE: Due to the need of the inner contract of the PointerInputChange, this method performs a shallow copy of the PointerInputChange. Any consume call between any of the copies will consume any other copy automatically. Therefore, copy with the new isConsumed is not possible. Consider creating a new PointerInputChange.
Public properties
historical
val historical: List<HistoricalChange>
Optional high-frequency pointer moves in between the last two dispatched events. Can be used for extra accuracy when input rate exceeds framerate.
isConsumed
val isConsumed: Boolean
Indicates whether the change was consumed or not. Note that the change must be consumed in full as there's no partial consumption system provided.
panOffset
val panOffset: Offset
An Offset in pixel coordinates indicating an amount of panning. Also consider handling scrollDelta, which represents a similar action from mouse wheels.
position
val position: Offset
The Offset of the current pointer event, relative to the containing element (values can be negative or larger than the element bounds).
pressed
val pressed: Boolean
true if the pointer event is considered "pressed." For example, finger touching the screen or a mouse button is pressed pressed would be true.
previousPosition
val previousPosition: Offset
The Offset of the previous pointer event, offset to the position and relative to the containing element.
previousPressed
val previousPressed: Boolean
true if the pointer event was considered "pressed." For example , if a finger was touching the screen or a mouse button was pressed, previousPressed would be true.
scaleFactor
val scaleFactor: Float
A multiplicative scale factor indicating the amount of scale to perform as part of this pointer input change. A value of 1f indicates no scale, a value less than 1f indicates a scale down, commonly causing a zoom out, and a value greater than 1f indicates a scale up, commonly causing a zoom in.
scrollDelta
val scrollDelta: Offset
The change in scroll position along the horizontal and vertical axes. Note that this value is platform-dependent and is not normalized to pixel coordinates: - Desktop & Android: Measured in platform-specific mouse wheel tick units. - Web: Raw delta values directly from the browser's WheelEvent. - iOS: Native scroll gesture delta.
Also consider handling panOffset, which represents trackpad scroll gestures.
uptimeMillis
val uptimeMillis: Long
The time of the current pointer event, in milliseconds. The start (0) time is platform-dependent
Extension functions
PointerInputChange.anyChangeConsumed
fun PointerInputChange.anyChangeConsumed(): Boolean
True if any aspect of this PointerInputChange has been consumed.
PointerInputChange.changedToDown
fun PointerInputChange.changedToDown(): Boolean
True if this PointerInputChange represents a pointer coming in contact with the screen and that change has not been consumed.
PointerInputChange.changedToDownIgnoreConsumed
fun PointerInputChange.changedToDownIgnoreConsumed(): Boolean
True if this PointerInputChange represents a pointer coming in contact with the screen, whether or not that change has been consumed.
PointerInputChange.changedToUp
fun PointerInputChange.changedToUp(): Boolean
True if this PointerInputChange represents a pointer breaking contact with the screen and that change has not been consumed.
PointerInputChange.changedToUpIgnoreConsumed
fun PointerInputChange.changedToUpIgnoreConsumed(): Boolean
True if this PointerInputChange represents a pointer breaking contact with the screen, whether or not that change has been consumed.
PointerInputChange.consumeAllChanges
fun PointerInputChange.consumeAllChanges(): Unit
Consumes all changes associated with the PointerInputChange
PointerInputChange.consumeDownChange
fun PointerInputChange.consumeDownChange(): Unit
Consume the up or down change of this PointerInputChange if there is an up or down change to consume.
PointerInputChange.consumePositionChange
fun PointerInputChange.consumePositionChange(): Unit
Consume position change if there is any
PointerInputChange.isOutOfBounds
fun PointerInputChange.isOutOfBounds(size: IntSize): Boolean
Returns true if the pointer has moved outside of the region of (0, 0, size.width, size.height) or false if the current pointer is up or it is inside the given bounds.
PointerInputChange.isOutOfBounds
fun PointerInputChange.isOutOfBounds(
size: IntSize,
extendedTouchPadding: Size
): Boolean
Returns true if the pointer has moved outside of the pointer region. For Touch events, this is (-extendedTouchPadding.width, -extendedTouchPadding.height, size.width + extendedTouchPadding.width, size.height + extendedTouchPadding.height) and for other events, this is (0, 0, size.width, size.height). Returnsfalse if the current pointer is up or it is inside the pointer region.
PointerInputChange.positionChange
fun PointerInputChange.positionChange(): Offset
The distance that the pointer has moved on the screen minus any distance that has been consumed.
PointerInputChange.positionChangeConsumed
fun PointerInputChange.positionChangeConsumed(): Boolean
True if this PointerInputChange's movement has been consumed.
PointerInputChange.positionChangeIgnoreConsumed
fun PointerInputChange.positionChangeIgnoreConsumed(): Offset
The distance that the pointer has moved on the screen, ignoring the fact that it might have been consumed.
PointerInputChange.positionChanged
fun PointerInputChange.positionChanged(): Boolean
True if this PointerInputChange represents a pointer moving on the screen and some of that movement has not been consumed.
PointerInputChange.positionChangedIgnoreConsumed
fun PointerInputChange.positionChangedIgnoreConsumed(): Boolean
True if this PointerInputChange represents a pointer moving on the screen ignoring how much of that movement may have been consumed.