@@ -11,8 +11,12 @@ import androidx.compose.runtime.*
1111import androidx.compose.ui.Alignment
1212import androidx.compose.ui.Modifier
1313import androidx.compose.ui.graphics.Color
14+ import androidx.compose.ui.text.font.FontWeight
1415import androidx.compose.ui.unit.dp
16+ import androidx.compose.ui.unit.sp
1517import com.smarttoolfactory.colorpicker.dialog.*
18+ import com.smarttoolfactory.colorpicker.ui.Blue400
19+ import com.smarttoolfactory.colorpicker.util.colorToHex
1620import com.smarttoolfactory.colorpicker.widget.ColorDisplayRoundedRect
1721import com.smarttoolfactory.composecolorpicker.ui.theme.backgroundColor
1822
@@ -35,12 +39,17 @@ fun ColorPickerDemo() {
3539 mutableStateOf(previousColor.copy())
3640 }
3741
42+ var hexString by remember { mutableStateOf(colorToHex(color)) }
43+
3844 Spacer (modifier = Modifier .height(30 .dp))
3945 ColorDisplayRoundedRect (
4046 modifier = Modifier .fillMaxWidth(.5f ),
4147 initialColor = previousColor,
4248 currentColor = color
4349 )
50+ Spacer (modifier = Modifier .height(10 .dp))
51+ Text (text = hexString, fontSize = 18 .sp, color = Blue400 , fontWeight = FontWeight .Bold )
52+ Spacer (modifier = Modifier .height(10 .dp))
4453
4554 val buttonModifier = Modifier
4655 .fillMaxWidth()
@@ -53,8 +62,9 @@ fun ColorPickerDemo() {
5362 onPreviousColorChange = {
5463 previousColor = it
5564 },
56- onCurrentColorChange = {
57- color = it
65+ onCurrentColorChange = { colorChange, hexChange ->
66+ color = colorChange
67+ hexString = hexChange
5868 }
5969 )
6070
@@ -65,8 +75,9 @@ fun ColorPickerDemo() {
6575 onPreviousColorChange = {
6676 previousColor = it
6777 },
68- onCurrentColorChange = {
69- color = it
78+ onCurrentColorChange = { colorChange, hexChange ->
79+ color = colorChange
80+ hexString = hexChange
7081 }
7182 )
7283
@@ -77,8 +88,9 @@ fun ColorPickerDemo() {
7788 onPreviousColorChange = {
7889 previousColor = it
7990 },
80- onCurrentColorChange = {
81- color = it
91+ onCurrentColorChange = { colorChange, hexChange ->
92+ color = colorChange
93+ hexString = hexChange
8294 }
8395 )
8496
@@ -88,8 +100,9 @@ fun ColorPickerDemo() {
88100 onPreviousColorChange = {
89101 previousColor = it
90102 },
91- onCurrentColorChange = {
92- color = it
103+ onCurrentColorChange = { colorChange, hexChange ->
104+ color = colorChange
105+ hexString = hexChange
93106 }
94107 )
95108
@@ -100,8 +113,9 @@ fun ColorPickerDemo() {
100113 onPreviousColorChange = {
101114 previousColor = it
102115 },
103- onCurrentColorChange = {
104- color = it
116+ onCurrentColorChange = { colorChange, hexChange ->
117+ color = colorChange
118+ hexString = hexChange
105119 }
106120 )
107121
@@ -111,8 +125,9 @@ fun ColorPickerDemo() {
111125 onPreviousColorChange = {
112126 previousColor = it
113127 },
114- onCurrentColorChange = {
115- color = it
128+ onCurrentColorChange = { colorChange, hexChange ->
129+ color = colorChange
130+ hexString = hexChange
116131 }
117132 )
118133
@@ -123,8 +138,9 @@ fun ColorPickerDemo() {
123138 onPreviousColorChange = {
124139 previousColor = it
125140 },
126- onCurrentColorChange = {
127- color = it
141+ onCurrentColorChange = { colorChange, hexChange ->
142+ color = colorChange
143+ hexString = hexChange
128144 }
129145 )
130146
@@ -134,8 +150,9 @@ fun ColorPickerDemo() {
134150 onPreviousColorChange = {
135151 previousColor = it
136152 },
137- onCurrentColorChange = {
138- color = it
153+ onCurrentColorChange = { colorChange, hexChange ->
154+ color = colorChange
155+ hexString = hexChange
139156 }
140157 )
141158
@@ -145,8 +162,9 @@ fun ColorPickerDemo() {
145162 onPreviousColorChange = {
146163 previousColor = it
147164 },
148- onCurrentColorChange = {
149- color = it
165+ onCurrentColorChange = { colorChange, hexChange ->
166+ color = colorChange
167+ hexString = hexChange
150168 }
151169 )
152170
@@ -156,8 +174,9 @@ fun ColorPickerDemo() {
156174 onPreviousColorChange = {
157175 previousColor = it
158176 },
159- onCurrentColorChange = {
160- color = it
177+ onCurrentColorChange = { colorChange, hexChange ->
178+ color = colorChange
179+ hexString = hexChange
161180 }
162181 )
163182 }
@@ -168,9 +187,9 @@ private fun DialogRingDiamondHSL(
168187 modifier : Modifier ,
169188 color : Color ,
170189 onPreviousColorChange : (Color ) -> Unit ,
171- onCurrentColorChange : (Color ) -> Unit ,
190+ onCurrentColorChange : (Color , String ) -> Unit
172191
173- ) {
192+ ) {
174193 var showDialog by remember { mutableStateOf(false ) }
175194
176195 OutlinedButton (
@@ -187,9 +206,9 @@ private fun DialogRingDiamondHSL(
187206 if (showDialog) {
188207 onPreviousColorChange(color.copy())
189208
190- ColorPickerRingDiamondHSLDialog (color) {
209+ ColorPickerRingDiamondHSLDialog (color) { colorChange, hexChange ->
191210 showDialog = ! showDialog
192- onCurrentColorChange(it )
211+ onCurrentColorChange(colorChange, hexChange )
193212 }
194213 }
195214}
@@ -199,9 +218,8 @@ private fun DialogRingRectHSL(
199218 modifier : Modifier ,
200219 color : Color ,
201220 onPreviousColorChange : (Color ) -> Unit ,
202- onCurrentColorChange : (Color ) -> Unit ,
203-
204- ) {
221+ onCurrentColorChange : (Color , String ) -> Unit
222+ ) {
205223 var showDialog by remember { mutableStateOf(false ) }
206224
207225 OutlinedButton (
@@ -218,9 +236,9 @@ private fun DialogRingRectHSL(
218236 if (showDialog) {
219237 onPreviousColorChange(color.copy())
220238
221- ColorPickerRingRectHSLDialog (color) {
239+ ColorPickerRingRectHSLDialog (color) { colorChange, hexChange ->
222240 showDialog = ! showDialog
223- onCurrentColorChange(it )
241+ onCurrentColorChange(colorChange, hexChange )
224242 }
225243 }
226244}
@@ -230,9 +248,8 @@ private fun DialogRingRectHSV(
230248 modifier : Modifier ,
231249 color : Color ,
232250 onPreviousColorChange : (Color ) -> Unit ,
233- onCurrentColorChange : (Color ) -> Unit ,
234-
235- ) {
251+ onCurrentColorChange : (Color , String ) -> Unit
252+ ) {
236253 var showDialog by remember { mutableStateOf(false ) }
237254
238255 OutlinedButton (
@@ -249,9 +266,9 @@ private fun DialogRingRectHSV(
249266 if (showDialog) {
250267 onPreviousColorChange(color.copy())
251268
252- ColorPickerRingRectHSVDialog (color) {
269+ ColorPickerRingRectHSVDialog (color) { colorChange, hexChange ->
253270 showDialog = ! showDialog
254- onCurrentColorChange(it )
271+ onCurrentColorChange(colorChange, hexChange )
255272 }
256273 }
257274}
@@ -261,9 +278,8 @@ private fun DialogCircleHSV(
261278 modifier : Modifier ,
262279 color : Color ,
263280 onPreviousColorChange : (Color ) -> Unit ,
264- onCurrentColorChange : (Color ) -> Unit ,
265-
266- ) {
281+ onCurrentColorChange : (Color , String ) -> Unit
282+ ) {
267283 var showDialog by remember { mutableStateOf(false ) }
268284
269285 OutlinedButton (
@@ -282,9 +298,9 @@ private fun DialogCircleHSV(
282298
283299 ColorPickerCircleHSVDialog (
284300 initialColor = color
285- ) {
301+ ) { colorChange, hexChange ->
286302 showDialog = ! showDialog
287- onCurrentColorChange(it )
303+ onCurrentColorChange(colorChange, hexChange )
288304 }
289305 }
290306}
@@ -294,9 +310,8 @@ private fun DialogRectSaturationValueHSV(
294310 modifier : Modifier ,
295311 color : Color ,
296312 onPreviousColorChange : (Color ) -> Unit ,
297- onCurrentColorChange : (Color ) -> Unit ,
298-
299- ) {
313+ onCurrentColorChange : (Color , String ) -> Unit
314+ ) {
300315 var showDialog by remember { mutableStateOf(false ) }
301316
302317 OutlinedButton (
@@ -315,9 +330,9 @@ private fun DialogRectSaturationValueHSV(
315330
316331 ColorPickerSVRectHSVDialog (
317332 initialColor = color
318- ) {
333+ ) { colorChange, hexChange ->
319334 showDialog = ! showDialog
320- onCurrentColorChange(it )
335+ onCurrentColorChange(colorChange, hexChange )
321336 }
322337 }
323338}
@@ -327,9 +342,8 @@ private fun DialogRectSaturationLightnessHSL(
327342 modifier : Modifier ,
328343 color : Color ,
329344 onPreviousColorChange : (Color ) -> Unit ,
330- onCurrentColorChange : (Color ) -> Unit ,
331-
332- ) {
345+ onCurrentColorChange : (Color , String ) -> Unit
346+ ) {
333347 var showDialog by remember { mutableStateOf(false ) }
334348
335349 OutlinedButton (
@@ -347,9 +361,9 @@ private fun DialogRectSaturationLightnessHSL(
347361
348362 ColorPickerSLRectHSLDialog (
349363 initialColor = color
350- ) {
364+ ) { colorChange, hexChange ->
351365 showDialog = ! showDialog
352- onCurrentColorChange(it )
366+ onCurrentColorChange(colorChange, hexChange )
353367 }
354368 }
355369}
@@ -359,9 +373,8 @@ private fun DialogRectHueSaturationHSV(
359373 modifier : Modifier ,
360374 color : Color ,
361375 onPreviousColorChange : (Color ) -> Unit ,
362- onCurrentColorChange : (Color ) -> Unit ,
363-
364- ) {
376+ onCurrentColorChange : (Color , String ) -> Unit
377+ ) {
365378 var showDialog by remember { mutableStateOf(false ) }
366379
367380 OutlinedButton (
@@ -379,9 +392,9 @@ private fun DialogRectHueSaturationHSV(
379392
380393 ColorPickerHSRectHSVDialog (
381394 initialColor = color
382- ) {
395+ ) { colorChange, hexChange ->
383396 showDialog = ! showDialog
384- onCurrentColorChange(it )
397+ onCurrentColorChange(colorChange, hexChange )
385398 }
386399 }
387400}
@@ -391,9 +404,8 @@ private fun DialogRectHueValueHSV(
391404 modifier : Modifier ,
392405 color : Color ,
393406 onPreviousColorChange : (Color ) -> Unit ,
394- onCurrentColorChange : (Color ) -> Unit ,
395-
396- ) {
407+ onCurrentColorChange : (Color , String ) -> Unit
408+ ) {
397409 var showDialog by remember { mutableStateOf(false ) }
398410
399411 OutlinedButton (
@@ -411,9 +423,9 @@ private fun DialogRectHueValueHSV(
411423
412424 ColorPickerHVRectHSVDialog (
413425 initialColor = color
414- ) {
426+ ) { colorChange, hexChange ->
415427 showDialog = ! showDialog
416- onCurrentColorChange(it )
428+ onCurrentColorChange(colorChange, hexChange )
417429 }
418430 }
419431}
@@ -423,9 +435,8 @@ private fun DialogRectHueSaturationHSL(
423435 modifier : Modifier ,
424436 color : Color ,
425437 onPreviousColorChange : (Color ) -> Unit ,
426- onCurrentColorChange : (Color ) -> Unit ,
427-
428- ) {
438+ onCurrentColorChange : (Color , String ) -> Unit
439+ ) {
429440 var showDialog by remember { mutableStateOf(false ) }
430441
431442 OutlinedButton (
@@ -443,9 +454,9 @@ private fun DialogRectHueSaturationHSL(
443454
444455 ColorPickerHSRectHSLDialog (
445456 initialColor = color
446- ) {
457+ ) { colorChange, hexChange ->
447458 showDialog = ! showDialog
448- onCurrentColorChange(it )
459+ onCurrentColorChange(colorChange, hexChange )
449460 }
450461 }
451462}
@@ -455,9 +466,8 @@ private fun DialogRectHueLightnessHSL(
455466 modifier : Modifier ,
456467 color : Color ,
457468 onPreviousColorChange : (Color ) -> Unit ,
458- onCurrentColorChange : (Color ) -> Unit ,
459-
460- ) {
469+ onCurrentColorChange : (Color , String ) -> Unit
470+ ) {
461471 var showDialog by remember { mutableStateOf(false ) }
462472
463473 OutlinedButton (
@@ -475,9 +485,9 @@ private fun DialogRectHueLightnessHSL(
475485
476486 ColorPickerHLRectHSLDialog (
477487 initialColor = color
478- ) {
488+ ) { colorChange, hexChange ->
479489 showDialog = ! showDialog
480- onCurrentColorChange(it )
490+ onCurrentColorChange(colorChange, hexChange )
481491 }
482492 }
483493}
0 commit comments