Selectable
interface Selectable
androidx.compose.ui.selection.Selectable |
Provides Selection information for a composable to SelectionContainer. Composables who can be selected should subscribe to SelectionRegistrar using this interface.
Summary
Public methods | |
---|---|
abstract Rect |
getBoundingBox(offset: Int) Return the bounding box of the character for given character offset. |
abstract Offset |
getHandlePosition(selection: Selection, isStartHandle: Boolean) Return the Offset of a SelectionHandle. |
abstract LayoutCoordinates? |
Return the LayoutCoordinates of the Selectable. |
abstract Selection? |
getSelection(startPosition: Offset, endPosition: Offset, containerLayoutCoordinates: LayoutCoordinates, longPress: Boolean, previousSelection: Selection? = null, isStartHandle: Boolean = true) Returns Selection information for a selectable composable. |
abstract AnnotatedString |
getText() Return the AnnotatedString of the Selectable. |
Public methods
getBoundingBox
abstract fun getBoundingBox(offset: Int): Rect
Return the bounding box of the character for given character offset. This is currently for text. In future when we implemented other selectable Composables, we can return the bounding box of the wanted rectangle. For example, for an image selectable, this should return the bounding box of the image.
Parameters | |
---|---|
offset: Int | a character offset |
Return | |
---|---|
the bounding box for the character in | Rect. |
getHandlePosition
abstract fun getHandlePosition(
selection: Selection,
isStartHandle: Boolean
): Offset
Return the Offset of a SelectionHandle.
Parameters | |
---|---|
selection: Selection | Selection contains the SelectionHandle |
isStartHandle: Boolean | true if it's the start handle, false if it's the end handle. |
Return | |
---|---|
Offset | of this handle, based on which the SelectionHandle will be drawn. |
getLayoutCoordinates
abstract fun getLayoutCoordinates(): LayoutCoordinates?
Return the LayoutCoordinates of the Selectable.
Return | |
---|---|
LayoutCoordinates | of the Selectable. This could be null if called before composing. |
getSelection
abstract fun getSelection(
startPosition: Offset,
endPosition: Offset,
containerLayoutCoordinates: LayoutCoordinates,
longPress: Boolean,
previousSelection: Selection? = null,
isStartHandle: Boolean = true
): Selection?
Returns Selection information for a selectable composable. If no selection can be provided null should be returned.
Parameters | |
---|---|
startPosition: Offset | graphical position of the start of the selection |
endPosition: Offset | graphical position of the end of the selection |
containerLayoutCoordinates: LayoutCoordinates | LayoutCoordinates of the widget |
longPress: Boolean | true represents that selection is either initiated via a long press or being dragged after long press |
previousSelection: Selection? = null | previous selection result |
isStartHandle: Boolean = true | true if the start handle is being dragged |
Return | |
---|---|
null if no selection will be applied for this composable, | or Selection instance if selection is applied to this composable. |
getText
abstract fun getText(): AnnotatedString
Return the AnnotatedString of the Selectable.
Return | |
---|---|
text content as | AnnotatedString of the Selectable. |