From c4d6a15b5bb60ec879ac2b28b3b4c4060d9b5eca Mon Sep 17 00:00:00 2001 From: Gabriel Herrera R Date: Tue, 31 Jan 2023 03:03:07 -0600 Subject: [PATCH] Make brightness bar optional (#44) * Make brightness bar optional for Harmony Color Picker * change to use a boolean flag for showing brightness bar --------- Co-authored-by: Thad Cox Co-authored-by: Thad Cox --- .../colorpicker/HarmonyColorPickerScreen.kt | 17 ++++++++++- .../colorpicker/harmony/HarmonyColorPicker.kt | 28 ++++++++++++------- 2 files changed, 34 insertions(+), 11 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 e5e4247..1806792 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, + showBrightnessBar = 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 cf357d0..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 @@ -73,11 +73,17 @@ fun HarmonyColorPicker( ) } +/** + * + * Will show a brightness bar if [showBrightnessBar] is true + * otherwise all colors are given the provided brightness value + */ @Composable fun HarmonyColorPicker( modifier: Modifier = Modifier, harmonyMode: ColorHarmonyMode, color: HsvColor, + showBrightnessBar: Boolean = true, onColorChanged: (HsvColor) -> Unit ) { BoxWithConstraints(modifier) { @@ -101,16 +107,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 (showBrightnessBar) { + BrightnessBar( + modifier = Modifier + .padding(top = 16.dp) + .fillMaxWidth() + .weight(0.2f), + onValueChange = { value -> + updatedOnValueChanged(updatedColor.copy(value = value)) + }, + currentColor = updatedColor + ) + } } } }