From 75012f1d7e1e35578d5cffe19146308bef48e257 Mon Sep 17 00:00:00 2001 From: Thad Cox Date: Mon, 26 Sep 2022 10:26:53 -0400 Subject: [PATCH 1/2] Make brightness bar optional for Harmony Color Picker --- .../colorpicker/HarmonyColorPickerScreen.kt | 17 ++++++++- .../colorpicker/harmony/HarmonyColorPicker.kt | 37 +++++++++++++------ 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/godaddy/android/colorpicker/HarmonyColorPickerScreen.kt b/app/src/main/java/com/godaddy/android/colorpicker/HarmonyColorPickerScreen.kt index 533d0ec..36a12d3 100644 --- a/app/src/main/java/com/godaddy/android/colorpicker/HarmonyColorPickerScreen.kt +++ b/app/src/main/java/com/godaddy/android/colorpicker/HarmonyColorPickerScreen.kt @@ -1,11 +1,13 @@ package com.godaddy.android.colorpicker import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.size import androidx.compose.material.DropdownMenu import androidx.compose.material.DropdownMenuItem +import androidx.compose.material.Switch import androidx.compose.material.Text import androidx.compose.material.TextButton import androidx.compose.material.TopAppBar @@ -47,6 +49,9 @@ fun HarmonyColorPickerScreen(navController: NavController) { var harmonyMode by remember { mutableStateOf(ColorHarmonyMode.ANALOGOUS) } + var showBrightnessBar by remember { + mutableStateOf(true) + } TextButton(onClick = { expanded = true }) { @@ -67,12 +72,22 @@ fun HarmonyColorPickerScreen(navController: NavController) { HarmonyColorPicker( modifier = Modifier.size(400.dp), harmonyMode = harmonyMode, - color = currentColor + color = currentColor, + fixedBrightness = 1f.takeIf { !showBrightnessBar } ) { color -> currentColor = color extraColors = color.getColors(colorHarmonyMode = harmonyMode) } ColorPaletteBar(modifier = Modifier.fillMaxWidth().height(70.dp), colors = extraColors) + Row { + Text("Show Brightness Bar") + Switch( + checked = showBrightnessBar, + onCheckedChange = { checked -> + showBrightnessBar = checked + } + ) + } TextButton(onClick = { currentColor = HsvColor.from(Color.Green) }) { Text("Reset To Green") } diff --git a/color-picker/src/commonMain/kotlin/com/godaddy/android/colorpicker/harmony/HarmonyColorPicker.kt b/color-picker/src/commonMain/kotlin/com/godaddy/android/colorpicker/harmony/HarmonyColorPicker.kt index bec23a3..e938c50 100644 --- a/color-picker/src/commonMain/kotlin/com/godaddy/android/colorpicker/harmony/HarmonyColorPicker.kt +++ b/color-picker/src/commonMain/kotlin/com/godaddy/android/colorpicker/harmony/HarmonyColorPicker.kt @@ -73,11 +73,17 @@ fun HarmonyColorPicker( ) } +/** + * + * Will show a brightness bar if [fixedBrightness] is null + * otherwise all colors are given the provided brightness value + */ @Composable fun HarmonyColorPicker( modifier: Modifier = Modifier, harmonyMode: ColorHarmonyMode, color: HsvColor, + fixedBrightness: Float? = null, onColorChanged: (HsvColor) -> Unit ) { BoxWithConstraints(modifier) { @@ -87,7 +93,14 @@ fun HarmonyColorPicker( .fillMaxHeight() .fillMaxWidth() ) { - val updatedColor by rememberUpdatedState(color) + val adjustedColor = color.run { + if (fixedBrightness != null) { + copy(value = fixedBrightness) + } else { + this + } + } + val updatedColor by rememberUpdatedState(adjustedColor) val updatedOnValueChanged by rememberUpdatedState(onColorChanged) HarmonyColorPickerWithMagnifiers( @@ -101,16 +114,18 @@ fun HarmonyColorPicker( harmonyMode = harmonyMode ) - BrightnessBar( - modifier = Modifier - .padding(top = 16.dp) - .fillMaxWidth() - .weight(0.2f), - onValueChange = { value -> - updatedOnValueChanged(updatedColor.copy(value = value)) - }, - currentColor = updatedColor - ) + if (fixedBrightness == null) { + BrightnessBar( + modifier = Modifier + .padding(top = 16.dp) + .fillMaxWidth() + .weight(0.2f), + onValueChange = { value -> + updatedOnValueChanged(updatedColor.copy(value = value)) + }, + currentColor = updatedColor + ) + } } } } From 11dcd00e6a2bd0ffcdce642b3314e8c8bf5612a4 Mon Sep 17 00:00:00 2001 From: Thad Cox Date: Mon, 30 Jan 2023 11:03:46 -0500 Subject: [PATCH 2/2] change to use a boolean flag for showing brightness bar --- .../colorpicker/HarmonyColorPickerScreen.kt | 2 +- .../colorpicker/harmony/HarmonyColorPicker.kt | 15 ++++----------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/godaddy/android/colorpicker/HarmonyColorPickerScreen.kt b/app/src/main/java/com/godaddy/android/colorpicker/HarmonyColorPickerScreen.kt index 98ae2a1..1806792 100644 --- a/app/src/main/java/com/godaddy/android/colorpicker/HarmonyColorPickerScreen.kt +++ b/app/src/main/java/com/godaddy/android/colorpicker/HarmonyColorPickerScreen.kt @@ -73,7 +73,7 @@ fun HarmonyColorPickerScreen(navController: NavController) { modifier = Modifier.size(400.dp), harmonyMode = harmonyMode, color = currentColor, - fixedBrightness = 1f.takeIf { !showBrightnessBar } + showBrightnessBar = showBrightnessBar ) { color -> currentColor = color extraColors = color.getColors(colorHarmonyMode = harmonyMode) diff --git a/color-picker/src/commonMain/kotlin/com/godaddy/android/colorpicker/harmony/HarmonyColorPicker.kt b/color-picker/src/commonMain/kotlin/com/godaddy/android/colorpicker/harmony/HarmonyColorPicker.kt index f6ad4a4..cb72ea5 100644 --- a/color-picker/src/commonMain/kotlin/com/godaddy/android/colorpicker/harmony/HarmonyColorPicker.kt +++ b/color-picker/src/commonMain/kotlin/com/godaddy/android/colorpicker/harmony/HarmonyColorPicker.kt @@ -75,7 +75,7 @@ fun HarmonyColorPicker( /** * - * Will show a brightness bar if [fixedBrightness] is null + * Will show a brightness bar if [showBrightnessBar] is true * otherwise all colors are given the provided brightness value */ @Composable @@ -83,7 +83,7 @@ fun HarmonyColorPicker( modifier: Modifier = Modifier, harmonyMode: ColorHarmonyMode, color: HsvColor, - fixedBrightness: Float? = null, + showBrightnessBar: Boolean = true, onColorChanged: (HsvColor) -> Unit ) { BoxWithConstraints(modifier) { @@ -93,14 +93,7 @@ fun HarmonyColorPicker( .fillMaxHeight() .fillMaxWidth() ) { - val adjustedColor = color.run { - if (fixedBrightness != null) { - copy(value = fixedBrightness) - } else { - this - } - } - val updatedColor by rememberUpdatedState(adjustedColor) + val updatedColor by rememberUpdatedState(color) val updatedOnValueChanged by rememberUpdatedState(onColorChanged) HarmonyColorPickerWithMagnifiers( @@ -114,7 +107,7 @@ fun HarmonyColorPicker( harmonyMode = harmonyMode ) - if (fixedBrightness == null) { + if (showBrightnessBar) { BrightnessBar( modifier = Modifier .padding(top = 16.dp)