Skip to content

Commit 50eb31f

Browse files
Add rounded color display with 2 colors
1 parent 7b6c468 commit 50eb31f

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.smarttoolfactory.colorpicker.widget
2+
3+
import androidx.compose.foundation.background
4+
import androidx.compose.foundation.layout.Box
5+
import androidx.compose.foundation.layout.Row
6+
import androidx.compose.foundation.layout.height
7+
import androidx.compose.foundation.shape.RoundedCornerShape
8+
import androidx.compose.runtime.Composable
9+
import androidx.compose.ui.Modifier
10+
import androidx.compose.ui.graphics.Color
11+
import androidx.compose.ui.unit.dp
12+
13+
/**
14+
* Color display that displays both colors horizontally aligned with half [RoundedCornerShape]
15+
* with [Modifier.drawChecker] to display checker pattern when any color's alpha is less than 1.0f
16+
* @param initialColor color that should be static
17+
* @param currentColor color that is changed based on user actions
18+
*/
19+
@Composable
20+
fun ColorDisplayRoundedRect(
21+
modifier: Modifier = Modifier,
22+
initialColor: Color,
23+
currentColor: Color
24+
) {
25+
Row(modifier = modifier) {
26+
Box(
27+
modifier = Modifier
28+
.weight(1f)
29+
.height(40.dp)
30+
.background(
31+
initialColor,
32+
shape = RoundedCornerShape(topStart = 8.dp, bottomStart = 8.dp)
33+
)
34+
)
35+
Box(
36+
modifier = Modifier
37+
.weight(1f)
38+
.height(40.dp)
39+
.drawChecker(RoundedCornerShape(topEnd = 8.dp, bottomEnd = 8.dp))
40+
.background(
41+
currentColor,
42+
shape = RoundedCornerShape(topEnd = 8.dp, bottomEnd = 8.dp)
43+
)
44+
)
45+
}
46+
}

0 commit comments

Comments
 (0)