Restructure project
* use modules instead of source sets
* Kotlin JVM instead of multiplatform (for now) to make things simpler
* Warning: GameCell doesn't use mutableState anymore, this needs to be
fixed for the UI to work!
This commit is contained in:
42
desktop/build.gradle.kts
Normal file
42
desktop/build.gradle.kts
Normal file
@@ -0,0 +1,42 @@
|
||||
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
|
||||
|
||||
plugins {
|
||||
alias(libs.plugins.kotlin.jvm)
|
||||
alias(libs.plugins.jetbrainsKotlinCompose)
|
||||
alias(libs.plugins.jetbrainsCompose)
|
||||
}
|
||||
|
||||
kotlin {
|
||||
jvmToolchain(11)
|
||||
|
||||
dependencies {
|
||||
implementation(compose.desktop.currentOs)
|
||||
implementation(compose.material3)
|
||||
implementation(compose.components.resources)
|
||||
implementation(projects.commonUI)
|
||||
implementation(compose.components.uiToolingPreview)
|
||||
|
||||
testImplementation(libs.kotlin.test)
|
||||
testImplementation(libs.atrium)
|
||||
testImplementation(compose.desktop.uiTestJUnit4)
|
||||
testImplementation(compose.desktop.currentOs)
|
||||
}
|
||||
}
|
||||
|
||||
compose.desktop {
|
||||
application {
|
||||
mainClass = "MainKt"
|
||||
|
||||
nativeDistributions {
|
||||
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
|
||||
packageName = "ch.dissem.yaep"
|
||||
packageVersion = "1.0.0"
|
||||
|
||||
buildTypes.release.proguard {
|
||||
configurationFiles.from(project.file("proguard-rules.pro"))
|
||||
isEnabled.set(true)
|
||||
obfuscate.set(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
25
desktop/proguard-rules.pro
vendored
Normal file
25
desktop/proguard-rules.pro
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
-libraryjars <java.home>/jmods/java.base.jmod(!**.jar;!module-info.class)
|
||||
|
||||
-keepclasseswithmembers public class MainKt {
|
||||
public static void main(java.lang.String[]);
|
||||
}
|
||||
|
||||
-dontwarn kotlinx.coroutines.debug.*
|
||||
-dontwarn kotlinx.datetime.**
|
||||
|
||||
-keep class kotlin.** { *; }
|
||||
-keep class kotlinx.coroutines.** { *; }
|
||||
-keep class org.jetbrains.skia.** { *; }
|
||||
-keep class org.jetbrains.skiko.** { *; }
|
||||
|
||||
-ignorewarnings
|
||||
|
||||
# Windows folders
|
||||
-keep class com.sun.jna.* { *; }
|
||||
-keepclassmembers class * extends com.sun.jna.* { public *; }
|
||||
|
||||
-assumenosideeffects public class androidx.compose.runtime.ComposerKt {
|
||||
void sourceInformation(androidx.compose.runtime.Composer,java.lang.String);
|
||||
void sourceInformationMarkerStart(androidx.compose.runtime.Composer,int,java.lang.String);
|
||||
void sourceInformationMarkerEnd(androidx.compose.runtime.Composer);
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.window.WindowDraggableArea
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Switch
|
||||
import androidx.compose.material3.SwitchDefaults
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.window.WindowPlacement
|
||||
import androidx.compose.ui.window.WindowScope
|
||||
import androidx.compose.ui.window.WindowState
|
||||
import ch.dissem.yaep.ui.common.theme.AppTheme
|
||||
import org.jetbrains.compose.resources.painterResource
|
||||
import yaep.commonui.generated.resources.Res
|
||||
import yaep.commonui.generated.resources.moon
|
||||
import yaep.commonui.generated.resources.sun
|
||||
import yaep.commonui.generated.resources.window_close
|
||||
import yaep.commonui.generated.resources.window_maximize
|
||||
import yaep.commonui.generated.resources.window_minimize
|
||||
|
||||
@Composable
|
||||
fun WindowScope.DesktopWindow(
|
||||
useDarkMode: Boolean,
|
||||
topBar: @Composable () -> Unit,
|
||||
content: @Composable (PaddingValues) -> Unit
|
||||
) {
|
||||
AppTheme(darkTheme = useDarkMode) {
|
||||
Scaffold(
|
||||
topBar = {
|
||||
WindowDraggableArea {
|
||||
topBar()
|
||||
}
|
||||
}
|
||||
) { paddingValues ->
|
||||
content(paddingValues)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun AppBar(
|
||||
useDarkMode: Boolean,
|
||||
setDarkMode: (Boolean) -> Unit,
|
||||
onCloseRequest: () -> Unit,
|
||||
windowState: WindowState,
|
||||
) {
|
||||
TopAppBar(
|
||||
navigationIcon = {
|
||||
// TODO Icon(painterResource(Res.drawable.heart), null)
|
||||
},
|
||||
title = { Text(text = "Yet Another Einstein Puzzle") },
|
||||
actions = {
|
||||
Switch(
|
||||
checked = useDarkMode,
|
||||
onCheckedChange = setDarkMode,
|
||||
thumbContent = {
|
||||
Icon(
|
||||
painter = painterResource(
|
||||
if (useDarkMode) {
|
||||
Res.drawable.sun
|
||||
} else {
|
||||
Res.drawable.moon
|
||||
}
|
||||
),
|
||||
contentDescription = null,
|
||||
modifier = Modifier.size(SwitchDefaults.IconSize),
|
||||
)
|
||||
}
|
||||
)
|
||||
Spacer(Modifier.width(8.dp))
|
||||
IconButton(
|
||||
onClick = { windowState.isMinimized = !windowState.isMinimized }
|
||||
) {
|
||||
Icon(
|
||||
painter = painterResource(Res.drawable.window_minimize),
|
||||
contentDescription = null,
|
||||
modifier = Modifier.size(SwitchDefaults.IconSize),
|
||||
)
|
||||
}
|
||||
IconButton(
|
||||
onClick = {
|
||||
windowState.placement =
|
||||
if (windowState.placement == WindowPlacement.Maximized)
|
||||
WindowPlacement.Floating else WindowPlacement.Maximized
|
||||
}
|
||||
) {
|
||||
Icon(
|
||||
painter = painterResource(Res.drawable.window_maximize),
|
||||
contentDescription = null,
|
||||
modifier = Modifier.size(SwitchDefaults.IconSize),
|
||||
)
|
||||
}
|
||||
IconButton(
|
||||
onClick = onCloseRequest
|
||||
) {
|
||||
Icon(
|
||||
painter = painterResource(Res.drawable.window_close),
|
||||
contentDescription = null,
|
||||
modifier = Modifier.size(SwitchDefaults.IconSize),
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
53
desktop/src/main/kotlin/ch/dissem/yaep/ui/desktop/main.kt
Normal file
53
desktop/src/main/kotlin/ch/dissem/yaep/ui/desktop/main.kt
Normal file
@@ -0,0 +1,53 @@
|
||||
import androidx.compose.foundation.layout.padding
|
||||
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.text.font.FontFamily
|
||||
import androidx.compose.ui.text.font.FontStyle
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.platform.Font
|
||||
import androidx.compose.ui.window.Window
|
||||
import androidx.compose.ui.window.WindowPlacement
|
||||
import androidx.compose.ui.window.application
|
||||
import androidx.compose.ui.window.rememberWindowState
|
||||
import ch.dissem.yaep.ui.common.App
|
||||
import ch.dissem.yaep.ui.common.theme.emojiFontFamily
|
||||
import org.jetbrains.compose.resources.painterResource
|
||||
import yaep.commonui.generated.resources.Res
|
||||
import yaep.commonui.generated.resources.moon
|
||||
|
||||
fun main() = application {
|
||||
emojiFontFamily = FontFamily(
|
||||
Font(
|
||||
resource = "NotoColorEmoji-Regular.ttf",
|
||||
weight = FontWeight.W400,
|
||||
style = FontStyle.Normal
|
||||
)
|
||||
)
|
||||
|
||||
Window(
|
||||
onCloseRequest = ::exitApplication,
|
||||
undecorated = true,
|
||||
title = "YAEP",
|
||||
icon = painterResource(Res.drawable.moon)
|
||||
) {
|
||||
var useDarkMode by remember { mutableStateOf(true) }
|
||||
DesktopWindow(
|
||||
useDarkMode = useDarkMode,
|
||||
topBar = {
|
||||
AppBar(
|
||||
useDarkMode = useDarkMode,
|
||||
setDarkMode = { useDarkMode = it },
|
||||
onCloseRequest = ::exitApplication,
|
||||
windowState = rememberWindowState(
|
||||
placement = WindowPlacement.Floating
|
||||
)
|
||||
)
|
||||
}
|
||||
) {
|
||||
App(modifier = Modifier.padding(it))
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
desktop/src/main/resources/NotoColorEmoji-Regular.ttf
Normal file
BIN
desktop/src/main/resources/NotoColorEmoji-Regular.ttf
Normal file
Binary file not shown.
Reference in New Issue
Block a user