This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Canvas( | |
| modifier = Modifier | |
| .height(40.dp) | |
| .width(300.dp) | |
| .clip(RoundedCornerShape(50)) | |
| ) { | |
| ... | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val bitmap = Bitmap.createBitmap(size.width.toInt(), size.height.toInt(), Bitmap.Config.ARGB_8888) | |
| val hueCanvas = Canvas(bitmap) | |
| val huePanel = RectF(0f, 0f, bitmap.width.toFloat(), bitmap.height.toFloat()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val hueColors = IntArray((huePanel.width()).toInt()) | |
| var hue = 0f | |
| for (i in hueColors.indices) { | |
| hueColors[i] = AndroidColor.HSVToColor(floatArrayOf(hue, 1f, 1f)) | |
| hue += 360f / hueColors.size | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val linePaint = Paint() | |
| linePaint.strokeWidth = 0F | |
| for (i in hueColors.indices) { | |
| linePaint.color = hueColors[i] | |
| hueCanvas.drawLine(i.toFloat(), 0F, i.toFloat(), huePanel.bottom, linePaint) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| drawIntoCanvas { | |
| it.nativeCanvas.drawBitmap( | |
| bitmap, | |
| null, | |
| panel.toRect(), | |
| null | |
| ) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val pressOffset = remember { | |
| mutableStateOf(Offset.Zero) | |
| } | |
| Canvas( | |
| modifier = Modifier | |
| .height(40.dp) | |
| .width(300.dp) | |
| .clip(RoundedCornerShape(50)) | |
| ) { | |
| ..... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private fun Modifier.emitDragGesture( | |
| interactionSource: MutableInteractionSource | |
| ): Modifier = composed { | |
| val scope = rememberCoroutineScope() | |
| pointerInput(Unit) { | |
| detectDragGestures { input, _ -> | |
| scope.launch { | |
| interactionSource.emit(PressInteraction.Press(input.position)) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| scope.launch { | |
| interactionSource.interactions.collect { interaction -> | |
| when(interaction) { | |
| PressInteraction.Press -> { | |
| val pressPos = pressPosition.x.coerceIn(0f..drawScopeSize.width) | |
| pressOffset.value = Offset(pressPos, 0f) | |
| val selectedHue = pointToHue(pressPos) | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Composable | |
| fun HueBar( | |
| setColor: (Float) -> Unit | |
| ) { | |
| val scope = rememberCoroutineScope() | |
| val interactionSource = remember { | |
| MutableInteractionSource() | |
| } | |
| val pressOffset = remember { | |
| mutableStateOf(Offset.Zero) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val interactionSource = remember { | |
| MutableInteractionSource() | |
| } | |
| val scope = rememberCoroutineScope() | |
| var sat: Float | |
| var value: Float | |
| val pressOffset = remember { | |
| mutableStateOf(Offset.Zero) | |
| } | |
| Canvas( |
OlderNewer