Skip to content

Commit cf82d6a

Browse files
committed
fix window settings
1 parent 537646f commit cf82d6a

File tree

8 files changed

+157
-171
lines changed

8 files changed

+157
-171
lines changed

compose/src/androidMain/kotlin/warlockfe/warlock3/compose/ui/settings/WindowSettingsDialog.kt

Lines changed: 0 additions & 26 deletions
This file was deleted.

compose/src/commonMain/kotlin/warlockfe/warlock3/compose/components/ColorPickerDialog.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,16 @@ fun ColorPickerDialog(
2121
onColorSelected: (color: WarlockColor) -> Unit,
2222
) {
2323
var currentColor by remember {
24-
mutableStateOf(
25-
HsvColor.from(
26-
initialColor ?: Color.Unspecified
27-
)
28-
)
24+
mutableStateOf(HsvColor.from(initialColor ?: Color.Unspecified))
2925
}
3026
AlertDialog(
3127
title = { Text("Choose color") },
3228
onDismissRequest = onCloseRequest,
3329
confirmButton = {
3430
TextButton(
35-
onClick = { onColorSelected(currentColor.toColor().toWarlockColor()) }
31+
onClick = {
32+
onColorSelected(currentColor.toColor().toWarlockColor())
33+
}
3634
) {
3735
Text("OK")
3836
}

compose/src/commonMain/kotlin/warlockfe/warlock3/compose/ui/game/GameView.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,9 @@ fun GameTextWindows(
178178
)
179179
}
180180
// Right Column
181-
val rightWindows =
182-
subWindowUiStates.filter { it.window?.location == WindowLocation.RIGHT }.sortedBy { it.window?.position }
181+
val rightWindows = subWindowUiStates
182+
.filter { it.window?.location == WindowLocation.RIGHT }
183+
.sortedBy { it.window?.position }
183184
if (rightWindows.isNotEmpty()) {
184185
val panelState = remember(rightWidth == null) {
185186
ResizablePanelState(initialSize = rightWidth?.dp ?: 0.dp, minSize = 16.dp)

compose/src/commonMain/kotlin/warlockfe/warlock3/compose/ui/settings/AppearanceView.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import androidx.compose.foundation.layout.height
1515
import androidx.compose.foundation.layout.padding
1616
import androidx.compose.foundation.layout.size
1717
import androidx.compose.foundation.layout.width
18-
import androidx.compose.foundation.shape.RoundedCornerShape
1918
import androidx.compose.material3.AlertDialog
2019
import androidx.compose.material3.Button
2120
import androidx.compose.material3.ListItem
Lines changed: 123 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,132 @@
11
package warlockfe.warlock3.compose.ui.settings
22

3+
import androidx.compose.foundation.background
4+
import androidx.compose.foundation.border
5+
import androidx.compose.foundation.layout.Box
6+
import androidx.compose.foundation.layout.Column
7+
import androidx.compose.foundation.layout.Row
8+
import androidx.compose.foundation.layout.Spacer
9+
import androidx.compose.foundation.layout.padding
10+
import androidx.compose.foundation.layout.size
11+
import androidx.compose.foundation.layout.width
12+
import androidx.compose.material3.AlertDialog
13+
import androidx.compose.material3.Button
14+
import androidx.compose.material3.MaterialTheme
15+
import androidx.compose.material3.OutlinedButton
16+
import androidx.compose.material3.Text
17+
import androidx.compose.material3.TextButton
318
import androidx.compose.runtime.Composable
19+
import androidx.compose.runtime.getValue
20+
import androidx.compose.runtime.mutableStateOf
21+
import androidx.compose.runtime.remember
22+
import androidx.compose.runtime.setValue
23+
import androidx.compose.ui.Modifier
24+
import androidx.compose.ui.unit.Dp
25+
import androidx.compose.ui.unit.dp
26+
import warlockfe.warlock3.compose.components.ColorPickerDialog
27+
import warlockfe.warlock3.compose.util.toColor
428
import warlockfe.warlock3.core.text.StyleDefinition
29+
import warlockfe.warlock3.core.text.WarlockColor
30+
import warlockfe.warlock3.core.text.ifUnspecified
531

632
@Composable
7-
expect fun WindowSettingsDialog(
33+
fun WindowSettingsDialog(
834
onCloseRequest: () -> Unit,
935
style: StyleDefinition,
36+
defaultStyle: StyleDefinition,
1037
saveStyle: (StyleDefinition) -> Unit,
11-
)
38+
) {
39+
var editColor by remember { mutableStateOf<Pair<WarlockColor, (WarlockColor) -> Unit>?>(null) }
40+
var editFont by remember { mutableStateOf<Pair<StyleDefinition, (FontUpdate) -> Unit>?>(null) }
41+
42+
if (editColor != null) {
43+
ColorPickerDialog(
44+
initialColor = editColor!!.first.toColor(),
45+
onCloseRequest = { editColor = null },
46+
onColorSelected = { color ->
47+
editColor?.second?.invoke(color)
48+
editColor = null
49+
}
50+
)
51+
}
52+
if (editFont != null) {
53+
FontPickerDialog(
54+
currentStyle = editFont!!.first,
55+
onCloseRequest = { editFont = null },
56+
onSaveClicked = { fontUpdate ->
57+
editFont?.second?.invoke(fontUpdate)
58+
editFont = null
59+
}
60+
)
61+
}
62+
63+
AlertDialog(
64+
onDismissRequest = onCloseRequest,
65+
confirmButton = {
66+
TextButton(onClick = onCloseRequest) {
67+
Text("Close")
68+
}
69+
},
70+
text = {
71+
Column(Modifier.padding(24.dp)) {
72+
val textColor = style.textColor.ifUnspecified(defaultStyle.textColor)
73+
OutlinedButton(
74+
onClick = {
75+
editColor = Pair(textColor) { color ->
76+
saveStyle(style.copy(textColor = color))
77+
}
78+
}
79+
) {
80+
Row {
81+
Text("Content: ")
82+
Box(
83+
Modifier
84+
.size(16.dp)
85+
.background(textColor.toColor())
86+
.border(Dp.Hairline, MaterialTheme.colorScheme.outline)
87+
)
88+
}
89+
}
90+
Spacer(Modifier.width(16.dp))
91+
val backgroundColor = style.backgroundColor.ifUnspecified(defaultStyle.backgroundColor)
92+
OutlinedButton(
93+
onClick = {
94+
editColor = Pair(backgroundColor) { color ->
95+
saveStyle(
96+
style.copy(backgroundColor = color)
97+
)
98+
}
99+
}
100+
) {
101+
Row {
102+
Text("Background: ")
103+
Box(
104+
Modifier
105+
.size(16.dp)
106+
.background(backgroundColor.toColor())
107+
.border(Dp.Hairline, MaterialTheme.colorScheme.outline)
108+
)
109+
}
110+
}
111+
Spacer(Modifier.width(16.dp))
112+
OutlinedButton(
113+
onClick = {
114+
editFont = Pair(style) { fontUpdate ->
115+
saveStyle(style.copy(fontFamily = fontUpdate.fontFamily, fontSize = fontUpdate.size))
116+
}
117+
}
118+
) {
119+
Text("Font: ${style.fontFamily ?: "Default"} ${style.fontSize ?: "Default"}")
120+
}
121+
Spacer(Modifier.width(16.dp))
122+
Button(onClick = {
123+
saveStyle(StyleDefinition())
124+
}) {
125+
Text("Revert to defaults")
126+
}
127+
Spacer(Modifier.width(8.dp))
128+
}
129+
}
130+
)
131+
}
132+

compose/src/commonMain/kotlin/warlockfe/warlock3/compose/ui/window/WindowView.kt

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -88,26 +88,29 @@ fun WindowView(
8888
overflow = TextOverflow.Ellipsis,
8989
)
9090
}
91-
var showDropdown by remember { mutableStateOf(false) }
92-
IconButton(
93-
modifier = Modifier.size(24.dp),
94-
onClick = { showDropdown = true }
95-
) {
96-
Icon(
97-
imageVector = Icons.Filled.Settings,
98-
contentDescription = "Settings",
99-
tint = MaterialTheme.colorScheme.onPrimary,
91+
92+
Box {
93+
var showDropdown by remember { mutableStateOf(false) }
94+
IconButton(
95+
modifier = Modifier.size(24.dp),
96+
onClick = { showDropdown = !showDropdown }
97+
) {
98+
Icon(
99+
imageVector = Icons.Filled.Settings,
100+
contentDescription = "Settings",
101+
tint = MaterialTheme.colorScheme.onPrimary,
102+
)
103+
}
104+
WindowViewDropdownMenu(
105+
expanded = showDropdown,
106+
onDismissRequest = { showDropdown = false },
107+
onSettingsClicked = { showWindowSettingsDialog = true },
108+
onMoveClicked = onMoveClicked,
109+
onMoveTowardsStart = onMoveTowardsStart,
110+
onMoveTowardsEnd = onMoveTowardsEnd,
111+
location = uiState.window?.location,
100112
)
101113
}
102-
WindowViewDropdownMenu(
103-
expanded = showDropdown,
104-
onDismissRequest = { showDropdown = false },
105-
onSettingsClicked = { showWindowSettingsDialog = true },
106-
onMoveClicked = onMoveClicked,
107-
onMoveTowardsStart = onMoveTowardsStart,
108-
onMoveTowardsEnd = onMoveTowardsEnd,
109-
location = uiState.window?.location,
110-
)
111114
if (uiState.window?.location != WindowLocation.MAIN) {
112115
IconButton(
113116
modifier = Modifier.size(24.dp),
@@ -141,6 +144,7 @@ fun WindowView(
141144
fontFamily = window.fontFamily,
142145
fontSize = window.fontSize
143146
),
147+
defaultStyle = uiState.defaultStyle,
144148
saveStyle = saveStyle,
145149
)
146150
}

compose/src/jvmMain/kotlin/warlockfe/warlock3/compose/ui/settings/WindowSettingsDialog.jvm.kt

Lines changed: 0 additions & 116 deletions
This file was deleted.

core/src/commonMain/kotlin/warlockfe/warlock3/core/text/WarlockColor.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ fun WarlockColor.isSpecified(): Boolean = argb != -1L
1818
fun WarlockColor.specifiedOrNull(): WarlockColor? =
1919
if (isSpecified()) this else null
2020

21+
fun WarlockColor.ifUnspecified(defaultColor: WarlockColor): WarlockColor {
22+
if (isSpecified()) return this
23+
return defaultColor
24+
}
25+
2126
fun WarlockColor.toHexString(): String? {
2227
if (isUnspecified()) return null
2328
return "#" + argb.toString(16)

0 commit comments

Comments
 (0)