From ccdffa3ed45b5be39b7ff240ca93964a5f7073b9 Mon Sep 17 00:00:00 2001 From: squid233 <60126026+squid233@users.noreply.github.com> Date: Sun, 18 Feb 2024 17:06:20 +0800 Subject: [PATCH] Update preset --- composeApp/src/wasmJsMain/kotlin/App.kt | 17 ++++++++++++++--- composeApp/src/wasmJsMain/kotlin/MyIcons.kt | 14 +++++++------- composeApp/src/wasmJsMain/kotlin/Preset.kt | 12 ++++++++++++ 3 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 composeApp/src/wasmJsMain/kotlin/Preset.kt diff --git a/composeApp/src/wasmJsMain/kotlin/App.kt b/composeApp/src/wasmJsMain/kotlin/App.kt index 30a25b4..bd450e4 100644 --- a/composeApp/src/wasmJsMain/kotlin/App.kt +++ b/composeApp/src/wasmJsMain/kotlin/App.kt @@ -98,6 +98,7 @@ private fun Customizer() { val release by remember { mutableStateOf(false) } var joml by remember { mutableStateOf(localStorage.getItem("joml").toBoolean()) } var noVariable by remember { mutableStateOf(localStorage.getItem("noVariable").toBoolean()) } + var selectedPreset by remember { mutableStateOf(Preset.CUSTOM) } fun storeSelectedNatives() { localStorage.setItem( @@ -219,9 +220,18 @@ private fun Customizer() { Column(modifier = Modifier.padding(horizontal = 80.dp)) { // presets optionTitle("Presets") - Row(verticalAlignment = Alignment.CenterVertically) { - RadioButton(selected = true, onClick = null) - Text("Custom") + Preset.entries.forEach { + Row(verticalAlignment = Alignment.CenterVertically) { + RadioButton(selected = it == selectedPreset, onClick = { + selectedPreset = it + if (it.modules != null) { + selectedVersion.modules.forEach { m -> + selectedModules[m] = it.modules.contains(m) + } + } + }, enabled = it != Preset.CUSTOM) + Text(it.text) + } } // addons @@ -247,6 +257,7 @@ private fun Customizer() { checked = if (module.nonSelectable) true else selectedModules[module] ?: false, enabled = !module.nonSelectable, onCheckedChange = { + selectedPreset = Preset.CUSTOM selectedModules[module] = it localStorage.setItem( "selectedModules", diff --git a/composeApp/src/wasmJsMain/kotlin/MyIcons.kt b/composeApp/src/wasmJsMain/kotlin/MyIcons.kt index 5f77a41..35e4c86 100644 --- a/composeApp/src/wasmJsMain/kotlin/MyIcons.kt +++ b/composeApp/src/wasmJsMain/kotlin/MyIcons.kt @@ -44,15 +44,15 @@ val Icons.Filled.Linux: ImageVector } _linux = materialIcon(name = "Filled.Linux") { materialPath { - fun moveTo(x: Float, y: Float) { + inline fun moveTo(x: Float, y: Float) { this.moveTo(x * LINUX_ICON_WIDTH, y * LINUX_ICON_HEIGHT) } - fun moveToRelative(dx: Float, dy: Float) { + inline fun moveToRelative(dx: Float, dy: Float) { this.moveToRelative(dx * LINUX_ICON_WIDTH, dy * LINUX_ICON_HEIGHT) } - fun curveTo(x1: Float, y1: Float, x2: Float, y2: Float, x3: Float, y3: Float) { + inline fun curveTo(x1: Float, y1: Float, x2: Float, y2: Float, x3: Float, y3: Float) { this.curveTo( x1 * LINUX_ICON_WIDTH, y1 * LINUX_ICON_HEIGHT, @@ -63,7 +63,7 @@ val Icons.Filled.Linux: ImageVector ) } - fun curveToRelative(dx1: Float, dy1: Float, dx2: Float, dy2: Float, dx3: Float, dy3: Float) { + inline fun curveToRelative(dx1: Float, dy1: Float, dx2: Float, dy2: Float, dx3: Float, dy3: Float) { this.curveToRelative( dx1 * LINUX_ICON_WIDTH, dy1 * LINUX_ICON_HEIGHT, @@ -74,7 +74,7 @@ val Icons.Filled.Linux: ImageVector ) } - fun reflectiveCurveToRelative(dx1: Float, dy1: Float, dx2: Float, dy2: Float) { + inline fun reflectiveCurveToRelative(dx1: Float, dy1: Float, dx2: Float, dy2: Float) { this.reflectiveCurveToRelative( dx1 * LINUX_ICON_WIDTH, dy1 * LINUX_ICON_HEIGHT, @@ -83,11 +83,11 @@ val Icons.Filled.Linux: ImageVector ) } - fun verticalLineToRelative(dy: Float) { + inline fun verticalLineToRelative(dy: Float) { this.verticalLineToRelative(dy * LINUX_ICON_HEIGHT) } - fun lineToRelative(dx: Float, dy: Float) { + inline fun lineToRelative(dx: Float, dy: Float) { this.lineToRelative(dx * LINUX_ICON_HEIGHT, dy * LINUX_ICON_WIDTH) } diff --git a/composeApp/src/wasmJsMain/kotlin/Preset.kt b/composeApp/src/wasmJsMain/kotlin/Preset.kt new file mode 100644 index 0000000..21b608d --- /dev/null +++ b/composeApp/src/wasmJsMain/kotlin/Preset.kt @@ -0,0 +1,12 @@ +import Binding.* + +/** + * @author squid233 + * @since 0.3.0 + */ +enum class Preset(val text: String, val modules: List?) { + NONE("None", listOf(CORE)), + CUSTOM("Custom", null), + EVERYTHING("Everything", Binding.entries), + MINIMAL_OPENGL("Minimal OpenGL", listOf(CORE, GLFW, OPENGL, STB)) +}