Skip to content

Commit

Permalink
fix window settings
Browse files Browse the repository at this point in the history
  • Loading branch information
sproctor committed Dec 19, 2024
1 parent 537646f commit cf82d6a
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 171 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,16 @@ fun ColorPickerDialog(
onColorSelected: (color: WarlockColor) -> Unit,
) {
var currentColor by remember {
mutableStateOf(
HsvColor.from(
initialColor ?: Color.Unspecified
)
)
mutableStateOf(HsvColor.from(initialColor ?: Color.Unspecified))
}
AlertDialog(
title = { Text("Choose color") },
onDismissRequest = onCloseRequest,
confirmButton = {
TextButton(
onClick = { onColorSelected(currentColor.toColor().toWarlockColor()) }
onClick = {
onColorSelected(currentColor.toColor().toWarlockColor())
}
) {
Text("OK")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,9 @@ fun GameTextWindows(
)
}
// Right Column
val rightWindows =
subWindowUiStates.filter { it.window?.location == WindowLocation.RIGHT }.sortedBy { it.window?.position }
val rightWindows = subWindowUiStates
.filter { it.window?.location == WindowLocation.RIGHT }
.sortedBy { it.window?.position }
if (rightWindows.isNotEmpty()) {
val panelState = remember(rightWidth == null) {
ResizablePanelState(initialSize = rightWidth?.dp ?: 0.dp, minSize = 16.dp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.ListItem
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,132 @@
package warlockfe.warlock3.compose.ui.settings

import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import warlockfe.warlock3.compose.components.ColorPickerDialog
import warlockfe.warlock3.compose.util.toColor
import warlockfe.warlock3.core.text.StyleDefinition
import warlockfe.warlock3.core.text.WarlockColor
import warlockfe.warlock3.core.text.ifUnspecified

@Composable
expect fun WindowSettingsDialog(
fun WindowSettingsDialog(
onCloseRequest: () -> Unit,
style: StyleDefinition,
defaultStyle: StyleDefinition,
saveStyle: (StyleDefinition) -> Unit,
)
) {
var editColor by remember { mutableStateOf<Pair<WarlockColor, (WarlockColor) -> Unit>?>(null) }
var editFont by remember { mutableStateOf<Pair<StyleDefinition, (FontUpdate) -> Unit>?>(null) }

if (editColor != null) {
ColorPickerDialog(
initialColor = editColor!!.first.toColor(),
onCloseRequest = { editColor = null },
onColorSelected = { color ->
editColor?.second?.invoke(color)
editColor = null
}
)
}
if (editFont != null) {
FontPickerDialog(
currentStyle = editFont!!.first,
onCloseRequest = { editFont = null },
onSaveClicked = { fontUpdate ->
editFont?.second?.invoke(fontUpdate)
editFont = null
}
)
}

AlertDialog(
onDismissRequest = onCloseRequest,
confirmButton = {
TextButton(onClick = onCloseRequest) {
Text("Close")
}
},
text = {
Column(Modifier.padding(24.dp)) {
val textColor = style.textColor.ifUnspecified(defaultStyle.textColor)
OutlinedButton(
onClick = {
editColor = Pair(textColor) { color ->
saveStyle(style.copy(textColor = color))
}
}
) {
Row {
Text("Content: ")
Box(
Modifier
.size(16.dp)
.background(textColor.toColor())
.border(Dp.Hairline, MaterialTheme.colorScheme.outline)
)
}
}
Spacer(Modifier.width(16.dp))
val backgroundColor = style.backgroundColor.ifUnspecified(defaultStyle.backgroundColor)
OutlinedButton(
onClick = {
editColor = Pair(backgroundColor) { color ->
saveStyle(
style.copy(backgroundColor = color)
)
}
}
) {
Row {
Text("Background: ")
Box(
Modifier
.size(16.dp)
.background(backgroundColor.toColor())
.border(Dp.Hairline, MaterialTheme.colorScheme.outline)
)
}
}
Spacer(Modifier.width(16.dp))
OutlinedButton(
onClick = {
editFont = Pair(style) { fontUpdate ->
saveStyle(style.copy(fontFamily = fontUpdate.fontFamily, fontSize = fontUpdate.size))
}
}
) {
Text("Font: ${style.fontFamily ?: "Default"} ${style.fontSize ?: "Default"}")
}
Spacer(Modifier.width(16.dp))
Button(onClick = {
saveStyle(StyleDefinition())
}) {
Text("Revert to defaults")
}
Spacer(Modifier.width(8.dp))
}
}
)
}

Original file line number Diff line number Diff line change
Expand Up @@ -88,26 +88,29 @@ fun WindowView(
overflow = TextOverflow.Ellipsis,
)
}
var showDropdown by remember { mutableStateOf(false) }
IconButton(
modifier = Modifier.size(24.dp),
onClick = { showDropdown = true }
) {
Icon(
imageVector = Icons.Filled.Settings,
contentDescription = "Settings",
tint = MaterialTheme.colorScheme.onPrimary,

Box {
var showDropdown by remember { mutableStateOf(false) }
IconButton(
modifier = Modifier.size(24.dp),
onClick = { showDropdown = !showDropdown }
) {
Icon(
imageVector = Icons.Filled.Settings,
contentDescription = "Settings",
tint = MaterialTheme.colorScheme.onPrimary,
)
}
WindowViewDropdownMenu(
expanded = showDropdown,
onDismissRequest = { showDropdown = false },
onSettingsClicked = { showWindowSettingsDialog = true },
onMoveClicked = onMoveClicked,
onMoveTowardsStart = onMoveTowardsStart,
onMoveTowardsEnd = onMoveTowardsEnd,
location = uiState.window?.location,
)
}
WindowViewDropdownMenu(
expanded = showDropdown,
onDismissRequest = { showDropdown = false },
onSettingsClicked = { showWindowSettingsDialog = true },
onMoveClicked = onMoveClicked,
onMoveTowardsStart = onMoveTowardsStart,
onMoveTowardsEnd = onMoveTowardsEnd,
location = uiState.window?.location,
)
if (uiState.window?.location != WindowLocation.MAIN) {
IconButton(
modifier = Modifier.size(24.dp),
Expand Down Expand Up @@ -141,6 +144,7 @@ fun WindowView(
fontFamily = window.fontFamily,
fontSize = window.fontSize
),
defaultStyle = uiState.defaultStyle,
saveStyle = saveStyle,
)
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ fun WarlockColor.isSpecified(): Boolean = argb != -1L
fun WarlockColor.specifiedOrNull(): WarlockColor? =
if (isSpecified()) this else null

fun WarlockColor.ifUnspecified(defaultColor: WarlockColor): WarlockColor {
if (isSpecified()) return this
return defaultColor
}

fun WarlockColor.toHexString(): String? {
if (isUnspecified()) return null
return "#" + argb.toString(16)
Expand Down

0 comments on commit cf82d6a

Please sign in to comment.