Skip to content

Commit

Permalink
Make brightness bar optional (#44)
Browse files Browse the repository at this point in the history
* Make brightness bar optional for Harmony Color Picker

* change to use a boolean flag for showing brightness bar

---------

Co-authored-by: Thad Cox <[email protected]>
Co-authored-by: Thad Cox <[email protected]>
  • Loading branch information
3 people authored Jan 31, 2023
1 parent 1b057a8 commit c4d6a15
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
}) {
Expand All @@ -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")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
)
}
}
}
}
Expand Down

0 comments on commit c4d6a15

Please sign in to comment.