@@ -2,16 +2,15 @@ package com.smarttoolfactory.colorpicker.widget
22
33import androidx.compose.foundation.clickable
44import androidx.compose.foundation.interaction.MutableInteractionSource
5- import androidx.compose.foundation.layout.Arrangement
6- import androidx.compose.foundation.layout.Box
7- import androidx.compose.foundation.layout.Row
8- import androidx.compose.foundation.layout.padding
5+ import androidx.compose.foundation.layout.*
96import androidx.compose.material.Text
107import androidx.compose.runtime.*
8+ import androidx.compose.ui.Alignment
119import androidx.compose.ui.Modifier
1210import androidx.compose.ui.text.font.FontWeight
1311import androidx.compose.ui.unit.dp
1412import androidx.compose.ui.unit.sp
13+ import com.smarttoolfactory.colorpicker.model.ColorMode
1514import com.smarttoolfactory.colorpicker.model.ColorModel
1615import com.smarttoolfactory.colorpicker.ui.Grey400
1716import com.smarttoolfactory.colorpicker.ui.Grey600
@@ -69,4 +68,73 @@ fun ColorModelChangeTabRow(
6968 }
7069}
7170
71+ /* *
72+ * Tab Section for changing between HSL, HSV and RGB color models and Gradient color.
73+ * @param colorMode current color mode.
74+ * @param onColorModeChange callback that is triggered when user touches buttons.
75+ */
76+ @Composable
77+ fun ColorGradientModeChangeTabRow (
78+ modifier : Modifier = Modifier ,
79+ colorMode : ColorMode ,
80+ onColorModeChange : (ColorMode ) -> Unit
81+ ) {
82+ var selectedIndex by remember {
83+ mutableStateOf(
84+ when (colorMode) {
85+ ColorMode .HSL -> 0
86+ ColorMode .HSV -> 1
87+ ColorMode .RGB -> 2
88+ ColorMode .Gradient -> 3
89+ }
90+ )
91+ }
92+
93+ Row (
94+ modifier = modifier
95+ .fillMaxWidth()
96+ .padding(horizontal = 10 .dp),
97+ horizontalArrangement = Arrangement .SpaceEvenly ,
98+ verticalAlignment = Alignment .CenterVertically
99+ ) {
100+ modeList.forEachIndexed { index, s ->
101+ Box (
102+ modifier = Modifier
103+ .clickable(
104+ interactionSource = MutableInteractionSource (),
105+ indication = null ,
106+ onClick = {
107+ selectedIndex = index
108+ val newColorMode = when (selectedIndex) {
109+ 0 -> ColorMode .HSL
110+ 1 -> ColorMode .HSV
111+ 2 -> ColorMode .RGB
112+ else -> ColorMode .Gradient
113+ }
114+ onColorModeChange(newColorMode)
115+ }
116+ )
117+ .padding(10 .dp),
118+ contentAlignment = Alignment .Center
119+ ) {
120+ if (index != 3 ) {
121+ Text (
122+ text = s,
123+ fontWeight = FontWeight .Bold ,
124+ fontSize = 18 .sp,
125+ color = if (index == selectedIndex) Grey400 else Grey600
126+ )
127+ } else {
128+ ColorWheel (
129+ modifier = Modifier .size(18 .dp),
130+ borderColor = if (index == selectedIndex) Grey400 else Grey600
131+ )
132+ }
133+
134+ }
135+ }
136+ }
137+ }
138+
72139private val modelList = listOf (" HSL" , " HSV" , " RGB" )
140+ private val modeList = listOf (" HSL" , " HSV" , " RGB" , " Gradient" )
0 commit comments