Skip to content

Commit 9095f83

Browse files
committed
example: Display HEX color value
1 parent d207809 commit 9095f83

File tree

3 files changed

+35
-14
lines changed

3 files changed

+35
-14
lines changed

composeApp/src/commonMain/kotlin/component/OtherComponent.kt

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import androidx.compose.animation.core.animateFloat
55
import androidx.compose.animation.core.infiniteRepeatable
66
import androidx.compose.animation.core.rememberInfiniteTransition
77
import androidx.compose.animation.core.tween
8+
import androidx.compose.foundation.background
89
import androidx.compose.foundation.layout.Arrangement
9-
import androidx.compose.foundation.layout.Column
10+
import androidx.compose.foundation.layout.Box
1011
import androidx.compose.foundation.layout.FlowRow
1112
import androidx.compose.foundation.layout.PaddingValues
1213
import androidx.compose.foundation.layout.Row
1314
import androidx.compose.foundation.layout.Spacer
1415
import androidx.compose.foundation.layout.fillMaxWidth
16+
import androidx.compose.foundation.layout.height
1517
import androidx.compose.foundation.layout.padding
1618
import androidx.compose.foundation.layout.size
1719
import androidx.compose.foundation.layout.width
@@ -24,6 +26,7 @@ import androidx.compose.runtime.remember
2426
import androidx.compose.runtime.setValue
2527
import androidx.compose.ui.Alignment
2628
import androidx.compose.ui.Modifier
29+
import androidx.compose.ui.draw.clip
2730
import androidx.compose.ui.platform.LocalFocusManager
2831
import androidx.compose.ui.text.font.FontWeight
2932
import androidx.compose.ui.text.input.ImeAction
@@ -87,6 +90,7 @@ import top.yukonga.miuix.kmp.icon.icons.useful.Undo
8790
import top.yukonga.miuix.kmp.icon.icons.useful.Unstick
8891
import top.yukonga.miuix.kmp.icon.icons.useful.Update
8992
import top.yukonga.miuix.kmp.theme.MiuixTheme
93+
import top.yukonga.miuix.kmp.utils.SmoothRoundedCornerShape
9094
import kotlin.math.round
9195

9296
@Composable
@@ -111,7 +115,7 @@ fun OtherComponent(padding: PaddingValues) {
111115
)
112116
val progressValues = remember { listOf(0.0f, 0.25f, 0.5f, 0.75f, 1.0f, null) }
113117
val progressDisable by remember { mutableStateOf(0.5f) }
114-
val tabTexts = listOf("tab1", "tab2", "tab3", "tab4", "tab5", "tab6")
118+
val tabTexts = listOf("Tab 1", "Tab 2", "Tab 3", "Tab 4", "Tab 5", "Tab 6")
115119
var selectedTabIndex by remember { mutableStateOf(0) }
116120
var selectedTabIndex1 by remember { mutableStateOf(0) }
117121
val miuixIconsNormal = listOf(
@@ -366,22 +370,40 @@ fun OtherComponent(padding: PaddingValues) {
366370
.padding(bottom = 6.dp),
367371
insideMargin = PaddingValues(16.dp)
368372
) {
369-
Column {
373+
Row(
374+
modifier = Modifier.padding(bottom = 12.dp),
375+
verticalAlignment = Alignment.CenterVertically
376+
) {
370377
Text(
371-
text = "Color: RGBA(" +
378+
text = "Selected Color:\nRGBA: " +
372379
"${(selectedColor.red * 255).toInt()}," +
373380
"${(selectedColor.green * 255).toInt()}," +
374381
"${(selectedColor.blue * 255).toInt()}," +
375-
"${(round(selectedColor.alpha * 100) / 100.0)})",
376-
modifier = Modifier.padding(bottom = 12.dp)
382+
"${(round(selectedColor.alpha * 100) / 100.0)}" +
383+
"\nHEX: #" +
384+
(selectedColor.alpha * 255).toInt().toString(16).padStart(2, '0').uppercase() +
385+
(selectedColor.red * 255).toInt().toString(16).padStart(2, '0').uppercase() +
386+
(selectedColor.green * 255).toInt().toString(16).padStart(2, '0').uppercase() +
387+
(selectedColor.blue * 255).toInt().toString(16).padStart(2, '0').uppercase(),
388+
modifier = Modifier.weight(1f)
377389
)
378-
379-
ColorPicker(
380-
initialColor = selectedColor,
381-
onColorChanged = { selectedColor = it },
382-
hapticEffect = SliderDefaults.SliderHapticEffect.Step
390+
Spacer(Modifier.width(12.dp))
391+
Box(
392+
modifier = Modifier
393+
.height(60.dp)
394+
.width(120.dp)
395+
.align(Alignment.CenterVertically)
396+
.clip(SmoothRoundedCornerShape(12.dp))
397+
.background(selectedColor)
383398
)
384399
}
400+
401+
ColorPicker(
402+
initialColor = selectedColor,
403+
onColorChanged = { selectedColor = it },
404+
showPreview = false,
405+
hapticEffect = SliderDefaults.SliderHapticEffect.Step
406+
)
385407
}
386408

387409
SmallTitle(text = "Card")

composeApp/src/commonMain/kotlin/component/TextComponent.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ fun TextComponent(
220220
checked = miuixSuperRightCheckboxState.value,
221221
rightActions = {
222222
Text(
223+
modifier = Modifier.padding(end = 6.dp),
223224
text = miuixSuperRightCheckbox.value,
224225
color = MiuixTheme.colorScheme.onSurfaceVariantActions
225226
)

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/extra/SuperCheckbox.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ fun SuperCheckbox(
5555
val checkbox: @Composable () -> Unit = {
5656
Checkbox(
5757
modifier = Modifier.padding(
58-
start = if (checkboxLocation == CheckboxLocation.Right) {
59-
insideMargin.calculateLeftPadding(LayoutDirection.Ltr)
60-
} else 0.dp, end = if (checkboxLocation == CheckboxLocation.Left) {
58+
end = if (checkboxLocation == CheckboxLocation.Left) {
6159
insideMargin.calculateLeftPadding(LayoutDirection.Ltr)
6260
} else 0.dp
6361
),

0 commit comments

Comments
 (0)