@@ -8,15 +8,12 @@ import androidx.compose.animation.core.animateFloat
88import androidx.compose.animation.core.infiniteRepeatable
99import androidx.compose.animation.core.rememberInfiniteTransition
1010import androidx.compose.animation.core.tween
11- import androidx.compose.foundation.background
1211import androidx.compose.foundation.layout.Arrangement
13- import androidx.compose.foundation.layout.Box
1412import androidx.compose.foundation.layout.FlowRow
1513import androidx.compose.foundation.layout.PaddingValues
1614import androidx.compose.foundation.layout.Row
1715import androidx.compose.foundation.layout.Spacer
1816import androidx.compose.foundation.layout.fillMaxWidth
19- import androidx.compose.foundation.layout.height
2017import androidx.compose.foundation.layout.padding
2118import androidx.compose.foundation.layout.size
2219import androidx.compose.foundation.layout.width
@@ -31,9 +28,9 @@ import androidx.compose.runtime.remember
3128import androidx.compose.runtime.setValue
3229import androidx.compose.ui.Alignment
3330import androidx.compose.ui.Modifier
34- import androidx.compose.ui.draw.clip
3531import androidx.compose.ui.focus.FocusManager
3632import androidx.compose.ui.graphics.Color
33+ import androidx.compose.ui.graphics.toArgb
3734import androidx.compose.ui.graphics.vector.ImageVector
3835import androidx.compose.ui.hapticfeedback.HapticFeedbackType
3936import androidx.compose.ui.platform.LocalHapticFeedback
@@ -61,8 +58,9 @@ import top.yukonga.miuix.kmp.basic.TextField
6158import top.yukonga.miuix.kmp.icon.MiuixIcons
6259import top.yukonga.miuix.kmp.icon.icons.useful.Like
6360import top.yukonga.miuix.kmp.theme.MiuixTheme
61+ import top.yukonga.miuix.kmp.utils.ColorUtils.colorToHsv
62+ import top.yukonga.miuix.kmp.utils.ColorUtils.colorToOkLab
6463import top.yukonga.miuix.kmp.utils.PressFeedbackType
65- import top.yukonga.miuix.kmp.utils.SmoothRoundedCornerShape
6664import kotlin.math.round
6765
6866fun LazyListScope.otherComponent (
@@ -313,8 +311,8 @@ fun LazyListScope.otherComponent(
313311 }
314312 }
315313
316- item(key = " colorPicker" ) {
317- SmallTitle (text = " ColorPicker" )
314+ item(key = " colorPicker-hsva " ) {
315+ SmallTitle (text = " ColorPicker (HSVA) " )
318316 val miuixColor = MiuixTheme .colorScheme.primary
319317 var selectedColor by remember { mutableStateOf(miuixColor) }
320318
@@ -329,43 +327,68 @@ fun LazyListScope.otherComponent(
329327 modifier = Modifier .padding(bottom = 12 .dp),
330328 verticalAlignment = Alignment .CenterVertically
331329 ) {
330+ val hsv = colorToHsv(selectedColor)
332331 Text (
333- text = " Selected Color: \n RGBA: " +
334- " ${(selectedColor.red * 255 ).toInt()} ," +
335- " ${(selectedColor.green * 255 ).toInt()} ," +
336- " ${(selectedColor.blue * 255 ).toInt()} ," +
332+ text = " HEX: # ${selectedColor.toArgb().toHexString( HexFormat . UpperCase )} " +
333+ " \n RGBA: ${(selectedColor.red * 255 ).toInt()} , " +
334+ " ${(selectedColor.green * 255 ).toInt()} , " +
335+ " ${(selectedColor.blue * 255 ).toInt()} , " +
337336 " ${(round(selectedColor.alpha * 100 ) / 100.0 )} " +
338- " \n HEX: #" +
339- (selectedColor.alpha * 255 ).toInt().toString(16 ).padStart(2 , ' 0' )
340- .uppercase() +
341- (selectedColor.red * 255 ).toInt().toString(16 ).padStart(2 , ' 0' )
342- .uppercase() +
343- (selectedColor.green * 255 ).toInt().toString(16 ).padStart(2 , ' 0' )
344- .uppercase() +
345- (selectedColor.blue * 255 ).toInt().toString(16 ).padStart(2 , ' 0' )
346- .uppercase(),
337+ " \n HSVA: ${(hsv[0 ]).toInt()} , " +
338+ " ${(hsv[1 ] * 100 ).toInt()} %, " +
339+ " ${(hsv[2 ] * 100 ).toInt()} %, " +
340+ " ${(round(selectedColor.alpha * 100 ) / 100.0 )} " ,
347341 modifier = Modifier .weight(1f )
348342 )
349- Spacer (Modifier .width(12 .dp))
350- Box (
351- modifier = Modifier
352- .height(60 .dp)
353- .width(100 .dp)
354- .align(Alignment .CenterVertically )
355- .clip(SmoothRoundedCornerShape (12 .dp))
356- .background(selectedColor)
357- )
358343 }
359-
360344 ColorPicker (
361345 initialColor = selectedColor,
362346 onColorChanged = { selectedColor = it },
363- showPreview = false ,
364347 hapticEffect = SliderDefaults .SliderHapticEffect .Step
365348 )
366349 }
367350 }
368351
352+ item(key = " colorPicker-okLab" ) {
353+ SmallTitle (text = " ColorPicker (OkLab)" )
354+ val miuixColor = MiuixTheme .colorScheme.primary
355+ var selectedColor by remember { mutableStateOf(miuixColor) }
356+
357+ Card (
358+ modifier = Modifier
359+ .fillMaxWidth()
360+ .padding(horizontal = 12 .dp)
361+ .padding(bottom = 6 .dp),
362+
363+ insideMargin = PaddingValues (16 .dp)
364+ ) {
365+ Row (
366+ modifier = Modifier .padding(bottom = 12 .dp),
367+ verticalAlignment = Alignment .CenterVertically
368+ ) {
369+ val okLab = colorToOkLab(selectedColor)
370+ Text (
371+ text = " HEX: #${selectedColor.toArgb().toHexString(HexFormat .UpperCase )} " +
372+ " \n RGBA: ${(selectedColor.red * 255 ).toInt()} , " +
373+ " ${(selectedColor.green * 255 ).toInt()} , " +
374+ " ${(selectedColor.blue * 255 ).toInt()} , " +
375+ " ${(round(selectedColor.alpha * 100 ) / 100.0 )} " +
376+ " \n OkLab: ${(okLab[0 ] * 1000 ).toInt() / 1000f } , " +
377+ " ${(okLab[1 ] * 1000 ).toInt() / 1000f } , " +
378+ " ${(okLab[2 ] * 1000 ).toInt() / 1000f } / " +
379+ " ${(round(selectedColor.alpha * 100 ) / 100.0 )} " ,
380+ modifier = Modifier .weight(1f )
381+ )
382+ }
383+ ColorPicker (
384+ initialColor = selectedColor,
385+ onColorChanged = { selectedColor = it },
386+ hapticEffect = SliderDefaults .SliderHapticEffect .Step ,
387+ useOkLab = true
388+ )
389+ }
390+ }
391+
369392 item(key = " card" ) {
370393 SmallTitle (text = " Card" )
371394 Card (
0 commit comments