From a29c117b856dce8a3c4639b3d84373e0b2ece315 Mon Sep 17 00:00:00 2001 From: Christian Basler Date: Tue, 23 Jul 2024 00:11:16 +0200 Subject: [PATCH] Fix some rendering issues --- android/build.gradle.kts | 14 +++- .../kotlin/ch/dissem/android/MainActivity.kt | 2 +- build.gradle.kts | 1 + commonUI/build.gradle.kts | 3 +- .../composeResources/drawable/lightbulb.xml | 10 +++ .../kotlin/ch/dissem/yaep/ui/common/App.kt | 80 +++++++++++-------- .../ch/dissem/yaep/ui/common/selector.kt | 1 + .../dissem/yaep/ui/desktop/desktop window.kt | 3 +- .../kotlin/ch/dissem/yaep/ui/desktop/main.kt | 8 +- gradle/libs.versions.toml | 6 ++ 10 files changed, 86 insertions(+), 42 deletions(-) create mode 100644 commonUI/src/main/composeResources/drawable/lightbulb.xml diff --git a/android/build.gradle.kts b/android/build.gradle.kts index d3a73dd..798a266 100644 --- a/android/build.gradle.kts +++ b/android/build.gradle.kts @@ -2,6 +2,7 @@ plugins { alias(libs.plugins.android.application) alias(libs.plugins.kotlin.compose) alias(libs.plugins.compose) + alias(libs.plugins.jetbrains.kotlin.android) } android { @@ -26,15 +27,16 @@ android { implementation(libs.androidx.activity.compose) // implementation(libs.compose.ui.text.googlefonts) implementation(projects.commonUI) - implementation(compose.components.uiToolingPreview) +// implementation(compose.components.uiToolingPreview) + implementation(libs.androidx.tooling.preview) testImplementation(libs.kotlin.test) testImplementation(libs.atrium) } compileOptions { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 } buildTypes { @@ -48,4 +50,10 @@ android { merges += "/META-INF/{AL2.0,LGPL2.1}" } } + kotlinOptions { + jvmTarget = "17" + } +} +dependencies { + implementation(libs.androidx.core.ktx) } diff --git a/android/src/main/kotlin/ch/dissem/android/MainActivity.kt b/android/src/main/kotlin/ch/dissem/android/MainActivity.kt index 03576ab..ad2ed08 100644 --- a/android/src/main/kotlin/ch/dissem/android/MainActivity.kt +++ b/android/src/main/kotlin/ch/dissem/android/MainActivity.kt @@ -4,8 +4,8 @@ import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.compose.runtime.Composable +import androidx.compose.ui.tooling.preview.Preview import ch.dissem.yaep.ui.common.App -import org.jetbrains.compose.ui.tooling.preview.Preview class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { diff --git a/build.gradle.kts b/build.gradle.kts index 30d0a31..d2e692b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -10,6 +10,7 @@ plugins { alias(libs.plugins.kotlin.compose) apply false alias(libs.plugins.kotlin.multiplatform) apply false alias(libs.plugins.kotlin.jvm) apply false + alias(libs.plugins.jetbrains.kotlin.android) apply false } tasks.withType().configureEach { diff --git a/commonUI/build.gradle.kts b/commonUI/build.gradle.kts index e522b9d..e09ab41 100644 --- a/commonUI/build.gradle.kts +++ b/commonUI/build.gradle.kts @@ -8,6 +8,8 @@ kotlin { jvmToolchain(11) dependencies { + api(projects.domain) + implementation(compose.components.resources) implementation(compose.runtime) implementation(compose.foundation) @@ -16,7 +18,6 @@ kotlin { implementation(compose.components.resources) implementation(compose.components.uiToolingPreview) // implementation(libs.compose.ui.text.googlefonts) - implementation(projects.domain) testImplementation(libs.kotlin.test) testImplementation(libs.atrium) diff --git a/commonUI/src/main/composeResources/drawable/lightbulb.xml b/commonUI/src/main/composeResources/drawable/lightbulb.xml new file mode 100644 index 0000000..9f16726 --- /dev/null +++ b/commonUI/src/main/composeResources/drawable/lightbulb.xml @@ -0,0 +1,10 @@ + + + diff --git a/commonUI/src/main/kotlin/ch/dissem/yaep/ui/common/App.kt b/commonUI/src/main/kotlin/ch/dissem/yaep/ui/common/App.kt index d329400..126e009 100644 --- a/commonUI/src/main/kotlin/ch/dissem/yaep/ui/common/App.kt +++ b/commonUI/src/main/kotlin/ch/dissem/yaep/ui/common/App.kt @@ -5,11 +5,15 @@ import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.aspectRatio +import androidx.compose.foundation.layout.fillMaxHeight +import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.wrapContentHeight import androidx.compose.foundation.lazy.grid.GridCells +import androidx.compose.foundation.lazy.grid.GridItemSpan import androidx.compose.foundation.lazy.grid.LazyVerticalGrid +import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.OutlinedCard import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue @@ -43,8 +47,8 @@ fun App(modifier: Modifier = Modifier) { val horizontalClues = remember { game.horizontalClues.map { DisplayClue(it) } } val verticalClues = remember { game.verticalClues.map { DisplayClue(it) } } Row(modifier = modifier) { - PuzzleGrid(modifier = Modifier.weight(1f), game.grid) - PuzzleClues(modifier = Modifier.weight(1f), horizontalClues, verticalClues) + PuzzleGrid(modifier = Modifier.aspectRatio(1f).weight(0.6f).fillMaxHeight(), game.grid) + PuzzleClues(modifier = Modifier.weight(0.4f).fillMaxHeight(), horizontalClues, verticalClues) } } @@ -63,7 +67,7 @@ fun PuzzleGrid( for (item in row) { Selector( modifier = Modifier - .padding(4.dp) + .padding(8.dp) .weight(1f), category = row.category, options = item.options, @@ -84,13 +88,15 @@ fun PuzzleClues( ) { Column(modifier = modifier) { LazyVerticalGrid( - modifier = Modifier.fillMaxWidth().weight(1f), - columns = GridCells.Adaptive(32.dp) + modifier = Modifier.fillMaxSize(), + columns = GridCells.Fixed(4) ) { for (clue in horizontalClues.filter { it.isActive }) { item { HorizontalClue( - modifier = Modifier.clickable { clue.isActive = false }, + modifier = Modifier + .padding(8.dp) + .clickable { clue.isActive = false }, clue = clue.clue ) } @@ -100,21 +106,22 @@ fun PuzzleClues( HorizontalClue( modifier = Modifier .alpha(0.5f) + .padding(8.dp) .clickable { clue.isActive = true }, clue = clue.clue ) } } - } - - LazyVerticalGrid( - modifier = Modifier.fillMaxWidth().weight(1f), - columns = GridCells.Adaptive(32.dp) - ) { + item(span = { GridItemSpan(maxLineSpan) }) { + HorizontalDivider() + } for (clue in verticalClues.filter { it.isActive }) { item { VerticalClue( - modifier = Modifier.clickable { clue.isActive = false }, + modifier = Modifier + .padding(8.dp) + .aspectRatio(0.3333f) + .clickable { clue.isActive = false }, clue = clue.clue ) } @@ -124,6 +131,8 @@ fun PuzzleClues( VerticalClue( modifier = Modifier .alpha(0.5f) + .padding(8.dp) + .aspectRatio(0.3333f) .clickable { clue.isActive = true }, clue = clue.clue ) @@ -135,31 +144,34 @@ fun PuzzleClues( @Composable fun HorizontalClue(modifier: Modifier = Modifier, clue: HorizontalClue) { - Column { - when (clue) { - is NeighbourClue<*, *> -> { - DrawItem(modifier = Modifier.weight(1f), clue.a) - OutlinedCard(modifier = modifier.aspectRatio(1f).weight(1f)) { + OutlinedCard(modifier) { + Row { + when (clue) { + is NeighbourClue<*, *> -> { + DrawItem(modifier = Modifier.weight(1f), clue.a) Image( + modifier = Modifier.aspectRatio(1f).weight(1f), painter = painterResource(Res.drawable.neighbour), contentDescription = null ) + DrawItem(modifier = Modifier.weight(1f), clue.b) } - DrawItem(modifier = Modifier.weight(1f), clue.b) - } - is OrderClue<*, *> -> { - DrawItem(modifier = Modifier.weight(1f), clue.left) - OutlinedCard(modifier = modifier.aspectRatio(1f).weight(1f)) { - Image(painter = painterResource(Res.drawable.order), contentDescription = null) + is OrderClue<*, *> -> { + DrawItem(modifier = Modifier.weight(1f), clue.left) + Image( + modifier = Modifier.aspectRatio(1f).weight(1f), + painter = painterResource(Res.drawable.order), + contentDescription = null + ) + DrawItem(modifier = Modifier.weight(1f), clue.right) } - DrawItem(modifier = Modifier.weight(1f), clue.right) - } - is TripletClue<*, *, *> -> { - DrawItem(modifier = Modifier.weight(1f), clue.a) - DrawItem(modifier = Modifier.weight(1f), clue.b) - DrawItem(modifier = Modifier.weight(1f), clue.c) + is TripletClue<*, *, *> -> { + DrawItem(modifier = Modifier.weight(1f), clue.a) + DrawItem(modifier = Modifier.weight(1f), clue.b) + DrawItem(modifier = Modifier.weight(1f), clue.c) + } } } } @@ -167,8 +179,10 @@ fun HorizontalClue(modifier: Modifier = Modifier, clue: HorizontalClue) { @Composable fun VerticalClue(modifier: Modifier = Modifier, clue: SameColumnClue<*, *>) { - Column(modifier = modifier) { - DrawItem(modifier = Modifier.weight(1f), clue.a) - DrawItem(modifier = Modifier.weight(1f), clue.b) + OutlinedCard(modifier) { + Column { + DrawItem(modifier = Modifier.weight(1f), clue.a) + DrawItem(modifier = Modifier.weight(1f), clue.b) + } } } \ No newline at end of file diff --git a/commonUI/src/main/kotlin/ch/dissem/yaep/ui/common/selector.kt b/commonUI/src/main/kotlin/ch/dissem/yaep/ui/common/selector.kt index bf3d61c..3b48880 100644 --- a/commonUI/src/main/kotlin/ch/dissem/yaep/ui/common/selector.kt +++ b/commonUI/src/main/kotlin/ch/dissem/yaep/ui/common/selector.kt @@ -88,3 +88,4 @@ fun > DrawItem( ) } } + diff --git a/desktop/src/main/kotlin/ch/dissem/yaep/ui/desktop/desktop window.kt b/desktop/src/main/kotlin/ch/dissem/yaep/ui/desktop/desktop window.kt index 58e4470..488951a 100644 --- a/desktop/src/main/kotlin/ch/dissem/yaep/ui/desktop/desktop window.kt +++ b/desktop/src/main/kotlin/ch/dissem/yaep/ui/desktop/desktop window.kt @@ -20,6 +20,7 @@ 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.lightbulb import yaep.commonui.generated.resources.moon import yaep.commonui.generated.resources.sun import yaep.commonui.generated.resources.window_close @@ -55,7 +56,7 @@ fun AppBar( ) { TopAppBar( navigationIcon = { - // TODO Icon(painterResource(Res.drawable.heart), null) + Icon(painterResource(Res.drawable.lightbulb), null) }, title = { Text(text = "Yet Another Einstein Puzzle") }, actions = { diff --git a/desktop/src/main/kotlin/ch/dissem/yaep/ui/desktop/main.kt b/desktop/src/main/kotlin/ch/dissem/yaep/ui/desktop/main.kt index ebbcd7f..9733fbe 100644 --- a/desktop/src/main/kotlin/ch/dissem/yaep/ui/desktop/main.kt +++ b/desktop/src/main/kotlin/ch/dissem/yaep/ui/desktop/main.kt @@ -26,11 +26,15 @@ fun main() = application { style = FontStyle.Normal ) ) + val windowState = rememberWindowState( + placement = WindowPlacement.Floating + ) Window( onCloseRequest = ::exitApplication, undecorated = true, title = "YAEP", + state = windowState, icon = painterResource(Res.drawable.moon) ) { var useDarkMode by remember { mutableStateOf(true) } @@ -41,9 +45,7 @@ fun main() = application { useDarkMode = useDarkMode, setDarkMode = { useDarkMode = it }, onCloseRequest = ::exitApplication, - windowState = rememberWindowState( - placement = WindowPlacement.Floating - ) + windowState = windowState ) } ) { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 03d1dba..ef04ac3 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -4,13 +4,18 @@ android-compileSdk = "34" android-minSdk = "24" android-targetSdk = "34" androidx-activityCompose = "1.9.0" +androidx-compose = "1.6.8" compose-plugin = "1.6.11" kotlin = "2.0.0" +kotlinVersion = "2.0.0" +coreKtx = "1.13.1" [libraries] androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activityCompose" } +androidx-tooling-preview = {module="androidx.compose.ui:ui-tooling-preview", version.ref="androidx-compose"} kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" } atrium = { module = "ch.tutteli.atrium:atrium-fluent", version = "1.2.0" } +androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" } [plugins] android-application = { id = "com.android.application", version.ref = "agp" } @@ -19,3 +24,4 @@ kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } compose = { id = "org.jetbrains.compose", version.ref = "compose-plugin" } +jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlinVersion" }