Compare commits
13 Commits
versioning
...
feature/ke
| Author | SHA1 | Date | |
|---|---|---|---|
| b207754636 | |||
| a8a07d9c8a | |||
|
|
b05099da46 | ||
| c6f7cbae2b | |||
| 3582196720 | |||
|
|
25d4da4582 | ||
|
|
e80ae7f722 | ||
| 0eef2a65dc | |||
| 984160bb44 | |||
| aab1fbda65 | |||
|
|
54b1810606 | ||
|
|
5d9a7d37d9 | ||
| da8a3c5398 |
@@ -1,35 +0,0 @@
|
|||||||
on:
|
|
||||||
push:
|
|
||||||
# TODO: remove versioning branch once everything works
|
|
||||||
branches: [main,versioning]
|
|
||||||
tags:
|
|
||||||
- '[0-9]+.[0-9]+.[0-9]+'
|
|
||||||
name: Flatpak
|
|
||||||
jobs:
|
|
||||||
flatpak:
|
|
||||||
name: Flatpak
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
container:
|
|
||||||
image: ghcr.io/flathub-infra/flatpak-github-actions:gnome-48
|
|
||||||
options: --privileged
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- name: Set up JDK 21
|
|
||||||
uses: actions/setup-java@v4
|
|
||||||
with:
|
|
||||||
java-version: 21
|
|
||||||
distribution: 'temurin'
|
|
||||||
- name: Cache Gradle packages
|
|
||||||
uses: actions/cache@v4
|
|
||||||
with:
|
|
||||||
path: ~/.gradle/caches
|
|
||||||
key: ${{ runner.os }}-gradle
|
|
||||||
restore-keys: ${{ runner.os }}-gradle
|
|
||||||
- name: Build Release Uber JAR
|
|
||||||
run: ./gradlew packageReleaseUberJarForCurrentOS
|
|
||||||
- uses: flatpak/flatpak-github-actions/flatpak-builder@v6
|
|
||||||
with:
|
|
||||||
bundle: YAEP.flatpak
|
|
||||||
manifest-path: ./flatpak/ch.dissem.YAEP.yml
|
|
||||||
cache-key: flatpak-builder-${{ github.sha }}
|
|
||||||
upload-artifact: false
|
|
||||||
@@ -39,4 +39,4 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN }}
|
SONAR_TOKEN: ${{ secrets.SONARQUBE_TOKEN }}
|
||||||
SONAR_HOST_URL: ${{ secrets.SONARQUBE_HOST }}
|
SONAR_HOST_URL: ${{ secrets.SONARQUBE_HOST }}
|
||||||
run: ./gradlew sonar
|
run: ./gradlew sonar --stacktrace
|
||||||
|
|||||||
26
CHANGELOG.md
26
CHANGELOG.md
@@ -1,26 +0,0 @@
|
|||||||
# Changelog
|
|
||||||
|
|
||||||
All notable changes to this project will be documented in this file.
|
|
||||||
|
|
||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
||||||
|
|
||||||
## [Unreleased]
|
|
||||||
|
|
||||||
### Added
|
|
||||||
|
|
||||||
- Yet Another Einstein Puzzle, for Desktop and not-quite-yet Android
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
|
|
||||||
### Deprecated
|
|
||||||
|
|
||||||
### Removed
|
|
||||||
|
|
||||||
### Fixed
|
|
||||||
|
|
||||||
### Security
|
|
||||||
|
|
||||||
|
|
||||||
[unreleased]: https://git.dissem.ch/chris/YAEP/compare/1b9c8633c96e479e63afcd7301125ce67247a198...HEAD
|
|
||||||
[0.0.0]: https://git.dissem.ch/chris/YAEP/releases/tag/0.0.0
|
|
||||||
@@ -56,6 +56,11 @@ android {
|
|||||||
merges += "/META-INF/{AL2.0,LGPL2.1}"
|
merges += "/META-INF/{AL2.0,LGPL2.1}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lint {
|
||||||
|
baseline = file("lint-baseline.xml")
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|||||||
4
android/lint-baseline.xml
Normal file
4
android/lint-baseline.xml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<issues format="6" by="lint 8.13.2" type="baseline" client="gradle" dependencies="false" name="AGP (8.13.2)" variant="all" version="8.13.2">
|
||||||
|
|
||||||
|
</issues>
|
||||||
@@ -20,6 +20,7 @@ import androidx.compose.ui.tooling.preview.Preview
|
|||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import ch.dissem.yaep.domain.generateGame
|
import ch.dissem.yaep.domain.generateGame
|
||||||
import ch.dissem.yaep.ui.common.App
|
import ch.dissem.yaep.ui.common.App
|
||||||
|
import ch.dissem.yaep.ui.common.focus.FocusFollowingSelectionManager
|
||||||
import org.jetbrains.compose.resources.painterResource
|
import org.jetbrains.compose.resources.painterResource
|
||||||
import org.jetbrains.compose.resources.stringResource
|
import org.jetbrains.compose.resources.stringResource
|
||||||
import yaep.commonui.generated.resources.action_restart
|
import yaep.commonui.generated.resources.action_restart
|
||||||
@@ -63,8 +64,8 @@ class MainActivity : ComponentActivity() {
|
|||||||
) { insets ->
|
) { insets ->
|
||||||
App(
|
App(
|
||||||
modifier = Modifier.padding(insets),
|
modifier = Modifier.padding(insets),
|
||||||
|
rootSelectionManager = FocusFollowingSelectionManager,
|
||||||
spacing = 4.dp,
|
spacing = 4.dp,
|
||||||
selectDirectly = false,
|
|
||||||
game = game,
|
game = game,
|
||||||
onNewGame = { game = generateGame() },
|
onNewGame = { game = generateGame() },
|
||||||
resetCluesBeacon = resetCluesBeacon
|
resetCluesBeacon = resetCluesBeacon
|
||||||
@@ -83,7 +84,7 @@ fun AppAndroidPreview() {
|
|||||||
App(
|
App(
|
||||||
game = game,
|
game = game,
|
||||||
spacing = 4.dp,
|
spacing = 4.dp,
|
||||||
selectDirectly = false,
|
rootSelectionManager = FocusFollowingSelectionManager,
|
||||||
onNewGame = { game = generateGame() },
|
onNewGame = { game = generateGame() },
|
||||||
resetCluesBeacon = resetCluesBeacon
|
resetCluesBeacon = resetCluesBeacon
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ plugins {
|
|||||||
alias(libs.plugins.versions)
|
alias(libs.plugins.versions)
|
||||||
alias(libs.plugins.sonarqube)
|
alias(libs.plugins.sonarqube)
|
||||||
alias(libs.plugins.kotlin.kover)
|
alias(libs.plugins.kotlin.kover)
|
||||||
alias(libs.plugins.versioning)
|
|
||||||
alias(libs.plugins.android.application) apply false
|
alias(libs.plugins.android.application) apply false
|
||||||
alias(libs.plugins.android.library) apply false
|
alias(libs.plugins.android.library) apply false
|
||||||
alias(libs.plugins.compose) apply false
|
alias(libs.plugins.compose) apply false
|
||||||
@@ -18,28 +17,11 @@ plugins {
|
|||||||
alias(libs.plugins.kotlin.android) apply false
|
alias(libs.plugins.kotlin.android) apply false
|
||||||
}
|
}
|
||||||
|
|
||||||
version = "0.0.0-SNAPSHOT"
|
|
||||||
gitVersioning.apply {
|
|
||||||
refs {
|
|
||||||
branch(".+") {
|
|
||||||
considerTagsOnBranches = true
|
|
||||||
version = "\${ref}-SNAPSHOT"
|
|
||||||
}
|
|
||||||
tag("(?<version>.*)") {
|
|
||||||
version = "\${ref.version}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// optional fallback configuration in case of no matching ref configuration
|
|
||||||
rev {
|
|
||||||
version = "\${commit}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sonar {
|
sonar {
|
||||||
properties {
|
properties {
|
||||||
property("sonar.projectKey", "YAEP")
|
property("sonar.projectKey", "YAEP")
|
||||||
property("sonar.projectName", "YAEP")
|
property("sonar.projectName", "YAEP")
|
||||||
|
property("sonar.organization", "default")
|
||||||
|
|
||||||
property(
|
property(
|
||||||
"sonar.coverage.jacoco.xmlReportPaths",
|
"sonar.coverage.jacoco.xmlReportPaths",
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSetTree
|
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
alias(libs.plugins.kotlin.kover)
|
alias(libs.plugins.kotlin.kover)
|
||||||
alias(libs.plugins.kotlin.multiplatform)
|
alias(libs.plugins.kotlin.multiplatform)
|
||||||
@@ -13,9 +10,12 @@ kotlin {
|
|||||||
jvmToolchain(libs.versions.jdk.get().toInt())
|
jvmToolchain(libs.versions.jdk.get().toInt())
|
||||||
|
|
||||||
jvm()
|
jvm()
|
||||||
androidTarget {
|
androidLibrary {
|
||||||
@OptIn(ExperimentalKotlinGradlePluginApi::class)
|
namespace = "ch.dissem.yaep.common.ui"
|
||||||
instrumentedTestVariant.sourceSetTree.set(KotlinSourceSetTree.test)
|
compileSdk = libs.versions.android.compileSdk.get().toInt()
|
||||||
|
minSdk = libs.versions.android.minSdk.get().toInt()
|
||||||
|
|
||||||
|
experimentalProperties["android.experimental.kmp.enableAndroidResources"] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
@@ -44,36 +44,10 @@ kotlin {
|
|||||||
jvmTest.dependencies {
|
jvmTest.dependencies {
|
||||||
implementation(compose.desktop.currentOs)
|
implementation(compose.desktop.currentOs)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
android {
|
androidMain.dependencies {
|
||||||
namespace = "ch.dissem.yaep.common.ui"
|
|
||||||
compileSdk = libs.versions.android.compileSdk.get().toInt()
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation(libs.androidx.compose.foundation)
|
implementation(libs.androidx.compose.foundation)
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultConfig {
|
|
||||||
minSdk = libs.versions.android.minSdk.get().toInt()
|
|
||||||
}
|
|
||||||
|
|
||||||
buildFeatures {
|
|
||||||
compose = true
|
|
||||||
}
|
|
||||||
|
|
||||||
sourceSets {
|
|
||||||
getByName("test") {
|
|
||||||
resources.srcDirs("src/commonTest/resources")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
buildTypes {
|
|
||||||
debug {
|
|
||||||
enableAndroidTestCoverage = true
|
|
||||||
enableUnitTestCoverage = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,17 +15,20 @@ import androidx.compose.ui.unit.Dp
|
|||||||
import androidx.compose.ui.unit.TextUnit
|
import androidx.compose.ui.unit.TextUnit
|
||||||
import androidx.compose.ui.unit.TextUnitType
|
import androidx.compose.ui.unit.TextUnitType
|
||||||
import ch.dissem.yaep.domain.Game
|
import ch.dissem.yaep.domain.Game
|
||||||
|
import ch.dissem.yaep.ui.common.focus.FocusFollowingFocusable
|
||||||
|
import ch.dissem.yaep.ui.common.focus.SelectionManager
|
||||||
|
import ch.dissem.yaep.ui.common.layout.AdaptiveGameLayout
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.IO
|
||||||
import kotlin.coroutines.CoroutineContext
|
import kotlin.coroutines.CoroutineContext
|
||||||
import kotlin.time.ExperimentalTime
|
import kotlin.time.ExperimentalTime
|
||||||
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@OptIn(ExperimentalTime::class)
|
@OptIn(ExperimentalTime::class)
|
||||||
fun App(
|
fun App(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
selectDirectly: Boolean,
|
rootSelectionManager: SelectionManager<FocusFollowingFocusable>,
|
||||||
spacing: Dp,
|
spacing: Dp,
|
||||||
game: Game,
|
game: Game,
|
||||||
onNewGame: () -> Unit,
|
onNewGame: () -> Unit,
|
||||||
@@ -54,45 +57,71 @@ fun App(
|
|||||||
Box(modifier = modifier) {
|
Box(modifier = modifier) {
|
||||||
AdaptiveGameLayout(
|
AdaptiveGameLayout(
|
||||||
modifier = Modifier.blurOnFinished(isSolved),
|
modifier = Modifier.blurOnFinished(isSolved),
|
||||||
grid = {
|
selectionManager = rootSelectionManager,
|
||||||
|
grid = { selectionManager ->
|
||||||
PuzzleGrid(
|
PuzzleGrid(
|
||||||
|
selectionManager = selectionManager,
|
||||||
grid = game.grid,
|
grid = game.grid,
|
||||||
spacing = spacing,
|
spacing = spacing,
|
||||||
selectDirectly = selectDirectly,
|
|
||||||
onUpdate = {
|
onUpdate = {
|
||||||
horizontalClues.forEach { it.update(game.grid) }
|
horizontalClues.forEach { it.update(game.grid) }
|
||||||
verticalClues.forEach { it.update(game.grid) }
|
verticalClues.forEach { it.update(game.grid) }
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
horizontalClues = {
|
horizontalClues = { selectionManager ->
|
||||||
for (clue in horizontalClues) {
|
for (clue in horizontalClues) {
|
||||||
HorizontalClue(
|
HorizontalClue(
|
||||||
modifier = Modifier.forClue(clue, spacing),
|
modifier = Modifier
|
||||||
|
.focus(remember(selectionManager) {
|
||||||
|
selectionManager.add(
|
||||||
|
primaryAction = {
|
||||||
|
clue.isActive = !clue.isActive
|
||||||
|
},
|
||||||
|
secondaryAction = {
|
||||||
|
clue.isActive = false
|
||||||
|
}
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.forClue(clue, spacing),
|
||||||
spacing = spacing,
|
spacing = spacing,
|
||||||
clue = clue.clue,
|
clue = clue.clue,
|
||||||
isClueViolated = clue.isViolated
|
isClueViolated = clue.isViolated
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
verticalClues = {
|
verticalClues = { selectionManager ->
|
||||||
|
if (verticalClues.isNotEmpty()) {
|
||||||
for (clue in verticalClues) {
|
for (clue in verticalClues) {
|
||||||
VerticalClue(
|
VerticalClue(
|
||||||
modifier = Modifier.forClue(clue, spacing),
|
modifier = Modifier
|
||||||
|
.focus(remember(selectionManager) {
|
||||||
|
selectionManager.add(
|
||||||
|
primaryAction = {
|
||||||
|
clue.isActive = !clue.isActive
|
||||||
|
},
|
||||||
|
secondaryAction = {
|
||||||
|
clue.isActive = false
|
||||||
|
}
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.forClue(clue, spacing),
|
||||||
spacing = spacing,
|
spacing = spacing,
|
||||||
clue = clue.clue,
|
clue = clue.clue,
|
||||||
isClueViolated = clue.isViolated
|
isClueViolated = clue.isViolated
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
time = {
|
time = {
|
||||||
Text(
|
Text(
|
||||||
time,
|
time,
|
||||||
fontSize = TextUnit(4f, TextUnitType.Companion.Em),
|
fontSize = TextUnit(4f, TextUnitType.Em),
|
||||||
textAlign = TextAlign.End
|
textAlign = TextAlign.End
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
spacing = spacing
|
spacing = spacing,
|
||||||
|
game, resetCluesBeacon
|
||||||
)
|
)
|
||||||
EndOfGame(isSolved = isSolved, time = time, onRestart = onNewGame)
|
EndOfGame(isSolved = isSolved, time = time, onRestart = onNewGame)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,338 +0,0 @@
|
|||||||
package ch.dissem.yaep.ui.common
|
|
||||||
|
|
||||||
import androidx.compose.material3.HorizontalDivider
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.layout.Layout
|
|
||||||
import androidx.compose.ui.layout.Measurable
|
|
||||||
import androidx.compose.ui.layout.Placeable
|
|
||||||
import androidx.compose.ui.unit.Constraints
|
|
||||||
import androidx.compose.ui.unit.Constraints.Companion.fixed
|
|
||||||
import androidx.compose.ui.unit.Constraints.Companion.fixedWidth
|
|
||||||
import androidx.compose.ui.unit.Dp
|
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import ch.dissem.yaep.ui.common.AspectRatio.LANDSCAPE
|
|
||||||
import ch.dissem.yaep.ui.common.AspectRatio.PORTRAIT
|
|
||||||
import ch.dissem.yaep.ui.common.AspectRatio.SQUARISH
|
|
||||||
import kotlin.math.max
|
|
||||||
import kotlin.math.min
|
|
||||||
|
|
||||||
|
|
||||||
private enum class AspectRatio {
|
|
||||||
PORTRAIT, LANDSCAPE, SQUARISH;
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
private const val ASPECT_RATIO_LANDSCAPE = 1.4f
|
|
||||||
private const val ASPECT_RATIO_PORTRAIT = 1 / ASPECT_RATIO_LANDSCAPE
|
|
||||||
|
|
||||||
fun from(constraints: Constraints): AspectRatio {
|
|
||||||
val ratio = constraints.maxWidth.toFloat() / constraints.maxHeight.toFloat()
|
|
||||||
return when {
|
|
||||||
ratio < ASPECT_RATIO_PORTRAIT -> PORTRAIT
|
|
||||||
ratio > ASPECT_RATIO_LANDSCAPE -> LANDSCAPE
|
|
||||||
else -> SQUARISH
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun AdaptiveGameLayout(
|
|
||||||
modifier: Modifier = Modifier,
|
|
||||||
grid: @Composable () -> Unit,
|
|
||||||
horizontalClues: @Composable () -> Unit,
|
|
||||||
verticalClues: @Composable () -> Unit,
|
|
||||||
time: @Composable () -> Unit,
|
|
||||||
divider: @Composable () -> Unit = { HorizontalDivider() },
|
|
||||||
spacing: Dp = 8.dp
|
|
||||||
) {
|
|
||||||
Layout(
|
|
||||||
contents = listOf(grid, horizontalClues, verticalClues, time, divider, divider),
|
|
||||||
modifier = modifier
|
|
||||||
) { measurables, constraints ->
|
|
||||||
layout(width = constraints.maxWidth, height = constraints.maxHeight) {
|
|
||||||
val aspectRatio = AspectRatio.from(constraints)
|
|
||||||
|
|
||||||
val gridMeasurable = measurables[0][0]
|
|
||||||
val horizontalCluesMeasurables = measurables[1]
|
|
||||||
val verticalCluesMeasurables = measurables[2]
|
|
||||||
val timeMeasurable = measurables[3][0]
|
|
||||||
val dividerMeasurable = measurables[4][0]
|
|
||||||
|
|
||||||
val spacingPx = spacing.roundToPx()
|
|
||||||
|
|
||||||
when (aspectRatio) {
|
|
||||||
PORTRAIT -> {
|
|
||||||
val divider2Measurable = measurables[5][0]
|
|
||||||
portrait(
|
|
||||||
constraints,
|
|
||||||
spacingPx,
|
|
||||||
gridMeasurable,
|
|
||||||
horizontalCluesMeasurables,
|
|
||||||
verticalCluesMeasurables,
|
|
||||||
timeMeasurable,
|
|
||||||
dividerMeasurable,
|
|
||||||
divider2Measurable
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
SQUARISH -> {
|
|
||||||
squarish(
|
|
||||||
constraints,
|
|
||||||
spacingPx,
|
|
||||||
gridMeasurable,
|
|
||||||
horizontalCluesMeasurables,
|
|
||||||
verticalCluesMeasurables,
|
|
||||||
timeMeasurable
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
LANDSCAPE -> {
|
|
||||||
landscape(
|
|
||||||
constraints,
|
|
||||||
spacingPx,
|
|
||||||
gridMeasurable,
|
|
||||||
horizontalCluesMeasurables,
|
|
||||||
verticalCluesMeasurables,
|
|
||||||
timeMeasurable,
|
|
||||||
dividerMeasurable
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun Placeable.PlacementScope.portrait(
|
|
||||||
constraints: Constraints,
|
|
||||||
spacingPx: Int,
|
|
||||||
gridMeasurable: Measurable,
|
|
||||||
horizontalCluesMeasurables: List<Measurable>,
|
|
||||||
verticalCluesMeasurables: List<Measurable>,
|
|
||||||
timeMeasurable: Measurable,
|
|
||||||
divider1Measurable: Measurable,
|
|
||||||
divider2Measurable: Measurable
|
|
||||||
) {
|
|
||||||
val gridSize = constraints.maxWidth
|
|
||||||
val gridItemSize = (gridSize - 12 * spacingPx) / 18
|
|
||||||
|
|
||||||
val gridConstraints = fixed(gridSize, gridSize)
|
|
||||||
val horizontalCluesConstraints = fixed(
|
|
||||||
width = 3 * gridItemSize + 2 * spacingPx,
|
|
||||||
height = gridItemSize + 2 * spacingPx
|
|
||||||
)
|
|
||||||
val verticalCluesConstraints = fixed(
|
|
||||||
width = gridItemSize + 2 * spacingPx,
|
|
||||||
height = 3 * gridItemSize + 2 * spacingPx
|
|
||||||
)
|
|
||||||
val timeConstraints = Constraints()
|
|
||||||
val dividerConstraints = fixedWidth(gridSize)
|
|
||||||
|
|
||||||
val gridPlaceable = gridMeasurable.measure(gridConstraints)
|
|
||||||
val horizontalCluesPlaceables = horizontalCluesMeasurables.map {
|
|
||||||
it.measure(horizontalCluesConstraints)
|
|
||||||
}
|
|
||||||
val verticalCluesPlaceables = verticalCluesMeasurables.map {
|
|
||||||
it.measure(verticalCluesConstraints)
|
|
||||||
}
|
|
||||||
val timePlaceable = timeMeasurable.measure(timeConstraints)
|
|
||||||
val divider1Placeable = divider1Measurable.measure(dividerConstraints)
|
|
||||||
val divider2Placeable = divider2Measurable.measure(dividerConstraints)
|
|
||||||
|
|
||||||
// Position the grid
|
|
||||||
gridPlaceable.place(0, 0)
|
|
||||||
|
|
||||||
divider1Placeable.place(0, gridSize + spacingPx)
|
|
||||||
|
|
||||||
// Position the horizontal clues
|
|
||||||
var offsetY = placeClues(
|
|
||||||
placeables = horizontalCluesPlaceables,
|
|
||||||
offsetX = 0,
|
|
||||||
offsetY = gridSize + 2 * spacingPx,
|
|
||||||
maxWidth = gridSize
|
|
||||||
)
|
|
||||||
|
|
||||||
// Add divider in between
|
|
||||||
divider2Placeable.place(0, offsetY + spacingPx)
|
|
||||||
|
|
||||||
// Position the vertical clues
|
|
||||||
offsetY = placeClues(
|
|
||||||
placeables = verticalCluesPlaceables,
|
|
||||||
offsetX = 0,
|
|
||||||
offsetY = offsetY + spacingPx + divider2Placeable.height,
|
|
||||||
maxWidth = gridSize
|
|
||||||
)
|
|
||||||
|
|
||||||
// Position the time
|
|
||||||
val remainingSpace = constraints.maxHeight - offsetY
|
|
||||||
if (remainingSpace < timePlaceable.height) {
|
|
||||||
val scale = remainingSpace.toFloat() / timePlaceable.height.toFloat()
|
|
||||||
if (scale > 0.1f) {
|
|
||||||
timePlaceable.placeWithLayer(
|
|
||||||
x = constraints.maxWidth - timePlaceable.width - spacingPx,
|
|
||||||
y = constraints.maxHeight - timePlaceable.height
|
|
||||||
) {
|
|
||||||
scaleX = scale
|
|
||||||
scaleY = scale
|
|
||||||
translationX = (timePlaceable.width * (1 - scale)) / 2f
|
|
||||||
translationY = (timePlaceable.height * (1 - scale)) / 2f
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
timePlaceable.place(
|
|
||||||
x = constraints.maxWidth - timePlaceable.width - spacingPx,
|
|
||||||
y = constraints.maxHeight - timePlaceable.height
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun Placeable.PlacementScope.squarish(
|
|
||||||
constraints: Constraints,
|
|
||||||
spacingPx: Int,
|
|
||||||
gridMeasurable: Measurable,
|
|
||||||
horizontalCluesMeasurables: List<Measurable>,
|
|
||||||
verticalCluesMeasurables: List<Measurable>,
|
|
||||||
timeMeasurable: Measurable
|
|
||||||
) {
|
|
||||||
val gridSize = (7 * min(constraints.maxWidth, constraints.maxHeight)) / 10
|
|
||||||
val gridItemSize = (gridSize - 12 * spacingPx) / 18
|
|
||||||
val rightBarWidth = constraints.maxWidth - gridSize - spacingPx
|
|
||||||
|
|
||||||
val gridConstraints = fixed(gridSize, gridSize)
|
|
||||||
val horizontalCluesConstraints = fixed(
|
|
||||||
width = 3 * gridItemSize + 2 * spacingPx,
|
|
||||||
height = gridItemSize + 2 * spacingPx
|
|
||||||
)
|
|
||||||
val verticalCluesConstraints = fixed(
|
|
||||||
width = gridItemSize + 2 * spacingPx,
|
|
||||||
height = 3 * gridItemSize + 2 * spacingPx
|
|
||||||
)
|
|
||||||
val timeConstraints = Constraints()
|
|
||||||
|
|
||||||
val gridPlaceable = gridMeasurable.measure(gridConstraints)
|
|
||||||
val horizontalCluesPlaceables = horizontalCluesMeasurables.map {
|
|
||||||
it.measure(horizontalCluesConstraints)
|
|
||||||
}
|
|
||||||
val verticalCluesPlaceables = verticalCluesMeasurables.map {
|
|
||||||
it.measure(verticalCluesConstraints)
|
|
||||||
}
|
|
||||||
val timePlaceable = timeMeasurable.measure(timeConstraints)
|
|
||||||
|
|
||||||
// Position the grid
|
|
||||||
gridPlaceable.place(0, 0)
|
|
||||||
|
|
||||||
// Position the horizontal clues
|
|
||||||
placeClues(
|
|
||||||
placeables = horizontalCluesPlaceables,
|
|
||||||
offsetX = gridSize + 2 * spacingPx,
|
|
||||||
offsetY = 0,
|
|
||||||
maxWidth = rightBarWidth
|
|
||||||
)
|
|
||||||
|
|
||||||
// Position the vertical clues
|
|
||||||
placeClues(
|
|
||||||
placeables = verticalCluesPlaceables,
|
|
||||||
offsetX = 0,
|
|
||||||
offsetY = gridSize + 2 * spacingPx,
|
|
||||||
maxWidth = gridSize
|
|
||||||
)
|
|
||||||
|
|
||||||
// Position the time
|
|
||||||
timePlaceable.place(
|
|
||||||
x = constraints.maxWidth - timePlaceable.width - spacingPx,
|
|
||||||
y = constraints.maxHeight - timePlaceable.height
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun Placeable.PlacementScope.landscape(
|
|
||||||
constraints: Constraints,
|
|
||||||
spacingPx: Int,
|
|
||||||
gridMeasurable: Measurable,
|
|
||||||
horizontalCluesMeasurables: List<Measurable>,
|
|
||||||
verticalCluesMeasurables: List<Measurable>,
|
|
||||||
timeMeasurable: Measurable,
|
|
||||||
dividerMeasurable: Measurable
|
|
||||||
) {
|
|
||||||
val gridSize = constraints.maxHeight
|
|
||||||
val gridItemSize = (gridSize - 12 * spacingPx) / 18
|
|
||||||
val rightBarWidth = constraints.maxWidth - gridSize - 2 * spacingPx
|
|
||||||
|
|
||||||
val gridConstraints = fixed(gridSize, gridSize)
|
|
||||||
val baseSpace = gridSize - 2 * spacingPx
|
|
||||||
val horizontalCluesConstraints = fixed(
|
|
||||||
width = 3 * gridItemSize + 2 * spacingPx,
|
|
||||||
height = gridItemSize + 2 * spacingPx
|
|
||||||
)
|
|
||||||
val verticalCluesConstraints = fixed(
|
|
||||||
width = gridItemSize + 2 * spacingPx,
|
|
||||||
height = 3 * gridItemSize + 2 * spacingPx
|
|
||||||
)
|
|
||||||
val timeConstraints = Constraints.fixedHeight(baseSpace / 10)
|
|
||||||
val dividerConstraints = fixedWidth(rightBarWidth - 2 * spacingPx)
|
|
||||||
|
|
||||||
val gridPlaceable = gridMeasurable.measure(gridConstraints)
|
|
||||||
val horizontalCluesPlaceables = horizontalCluesMeasurables.map {
|
|
||||||
it.measure(horizontalCluesConstraints)
|
|
||||||
}
|
|
||||||
val verticalCluesPlaceables = verticalCluesMeasurables.map {
|
|
||||||
it.measure(verticalCluesConstraints)
|
|
||||||
}
|
|
||||||
val timePlaceable = timeMeasurable.measure(timeConstraints)
|
|
||||||
val dividerPlaceable = dividerMeasurable.measure(dividerConstraints)
|
|
||||||
|
|
||||||
// Position the grid
|
|
||||||
gridPlaceable.place(0, 0)
|
|
||||||
|
|
||||||
// Position the horizontal clues
|
|
||||||
val offsetY = placeClues(
|
|
||||||
placeables = horizontalCluesPlaceables,
|
|
||||||
offsetX = gridSize + 2 * spacingPx,
|
|
||||||
offsetY = 0,
|
|
||||||
maxWidth = rightBarWidth
|
|
||||||
)
|
|
||||||
|
|
||||||
// Add divider in between
|
|
||||||
dividerPlaceable.place(gridSize + 3 * spacingPx, offsetY + spacingPx)
|
|
||||||
|
|
||||||
// Position the vertical clues
|
|
||||||
placeClues(
|
|
||||||
placeables = verticalCluesPlaceables,
|
|
||||||
offsetX = gridSize + 2 * spacingPx,
|
|
||||||
offsetY = offsetY + spacingPx + dividerPlaceable.height,
|
|
||||||
maxWidth = rightBarWidth
|
|
||||||
)
|
|
||||||
|
|
||||||
// Position the time
|
|
||||||
timePlaceable.place(
|
|
||||||
x = constraints.maxWidth - timePlaceable.width - spacingPx,
|
|
||||||
y = constraints.maxHeight - timePlaceable.height
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun Placeable.PlacementScope.placeClues(
|
|
||||||
placeables: List<Placeable>,
|
|
||||||
offsetX: Int,
|
|
||||||
offsetY: Int,
|
|
||||||
maxWidth: Int
|
|
||||||
): Int {
|
|
||||||
if (placeables.isEmpty()) return offsetY
|
|
||||||
|
|
||||||
val itemWidth = placeables.first().width
|
|
||||||
val itemHeight = placeables.first().height
|
|
||||||
val columns = max(1, maxWidth / itemWidth)
|
|
||||||
val spacing = if (columns == 1) 0 else (maxWidth - columns * itemWidth) / (columns - 1)
|
|
||||||
var currentX = offsetX
|
|
||||||
var currentY = offsetY
|
|
||||||
var i = 0
|
|
||||||
for (placeable in placeables) {
|
|
||||||
placeable.place(currentX, currentY)
|
|
||||||
currentX += itemWidth + spacing
|
|
||||||
i++
|
|
||||||
if (i % columns == 0 && i < placeables.size) {
|
|
||||||
currentX = offsetX
|
|
||||||
currentY += itemHeight
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return currentY + itemHeight
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -13,10 +13,14 @@ import androidx.compose.material3.Button
|
|||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Alignment.Companion.CenterHorizontally
|
import androidx.compose.ui.Alignment.Companion.CenterHorizontally
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.drawBehind
|
import androidx.compose.ui.draw.drawBehind
|
||||||
|
import androidx.compose.ui.focus.FocusRequester
|
||||||
|
import androidx.compose.ui.focus.focusRequester
|
||||||
import androidx.compose.ui.graphics.BlurEffect
|
import androidx.compose.ui.graphics.BlurEffect
|
||||||
import androidx.compose.ui.graphics.graphicsLayer
|
import androidx.compose.ui.graphics.graphicsLayer
|
||||||
import androidx.compose.ui.platform.testTag
|
import androidx.compose.ui.platform.testTag
|
||||||
@@ -36,6 +40,12 @@ fun EndOfGame(
|
|||||||
time: String,
|
time: String,
|
||||||
onRestart: () -> Unit
|
onRestart: () -> Unit
|
||||||
) {
|
) {
|
||||||
|
val focusRequester = remember { FocusRequester() }
|
||||||
|
LaunchedEffect(isSolved) {
|
||||||
|
if (isSolved) {
|
||||||
|
focusRequester.requestFocus()
|
||||||
|
}
|
||||||
|
}
|
||||||
AnimatedVisibility(
|
AnimatedVisibility(
|
||||||
visible = isSolved,
|
visible = isSolved,
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
@@ -72,6 +82,7 @@ fun EndOfGame(
|
|||||||
Spacer(modifier = Modifier.height(32.dp))
|
Spacer(modifier = Modifier.height(32.dp))
|
||||||
Button(
|
Button(
|
||||||
modifier = Modifier.align(CenterHorizontally)
|
modifier = Modifier.align(CenterHorizontally)
|
||||||
|
.focusRequester(focusRequester)
|
||||||
.testTag("EndOfGame.restart"),
|
.testTag("EndOfGame.restart"),
|
||||||
onClick = onRestart
|
onClick = onRestart
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package ch.dissem.yaep.ui.common.focus
|
||||||
|
|
||||||
|
class CluesFocusable(
|
||||||
|
manager: CluesSelectionManager,
|
||||||
|
primaryAction: (() -> Unit)?,
|
||||||
|
secondaryAction: (() -> Unit)?
|
||||||
|
) : Focusable<CluesFocusable>(manager, primaryAction, secondaryAction)
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
package ch.dissem.yaep.ui.common.focus
|
||||||
|
|
||||||
|
import androidx.compose.ui.input.key.Key
|
||||||
|
import androidx.compose.ui.input.key.KeyEvent
|
||||||
|
import androidx.compose.ui.input.key.key
|
||||||
|
import ch.dissem.yaep.ui.common.ceilDiv
|
||||||
|
import kotlin.math.max
|
||||||
|
import kotlin.math.min
|
||||||
|
|
||||||
|
class CluesSelectionManager : SelectionManager<CluesFocusable>() {
|
||||||
|
var columns: Int = 1
|
||||||
|
|
||||||
|
private var row: Int = 0
|
||||||
|
private var col: Int = 0
|
||||||
|
|
||||||
|
private val focusables = mutableListOf<CluesFocusable>()
|
||||||
|
|
||||||
|
override fun add(
|
||||||
|
primaryAction: (() -> Unit)?,
|
||||||
|
secondaryAction: (() -> Unit)?
|
||||||
|
): CluesFocusable {
|
||||||
|
val new = CluesFocusable(
|
||||||
|
manager = this,
|
||||||
|
primaryAction = primaryAction,
|
||||||
|
secondaryAction = secondaryAction
|
||||||
|
)
|
||||||
|
focusables.add(new)
|
||||||
|
return new
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun doOnKeyEvent(event: KeyEvent): Boolean {
|
||||||
|
val rows = focusables.size ceilDiv columns
|
||||||
|
|
||||||
|
when (event.key) {
|
||||||
|
Key.DirectionDown -> {
|
||||||
|
row++
|
||||||
|
if (row >= rows) {
|
||||||
|
row = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Key.DirectionUp -> {
|
||||||
|
row--
|
||||||
|
if (row < 0) {
|
||||||
|
row = rows - 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Key.DirectionRight -> {
|
||||||
|
col++
|
||||||
|
if (col >= columns) {
|
||||||
|
col = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Key.DirectionLeft -> {
|
||||||
|
col--
|
||||||
|
if (col < 0) {
|
||||||
|
col = columns - 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> return focused?.child?.onKeyEvent(event) == true
|
||||||
|
}
|
||||||
|
|
||||||
|
// This makes sure the limits aren't exceeded when values are changed concurrently
|
||||||
|
val index = max(0, min(row * columns + col, focusables.size - 1))
|
||||||
|
focused = focusables[index]
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package ch.dissem.yaep.ui.common.focus
|
||||||
|
|
||||||
|
import androidx.compose.ui.focus.FocusRequester
|
||||||
|
import androidx.compose.ui.focus.FocusState
|
||||||
|
|
||||||
|
class FocusFollowingFocusable(
|
||||||
|
manager: FocusFollowingSelectionManager,
|
||||||
|
primaryAction: (() -> Unit)?,
|
||||||
|
secondaryAction: (() -> Unit)?
|
||||||
|
) : Focusable<FocusFollowingFocusable>(manager, primaryAction, secondaryAction) {
|
||||||
|
|
||||||
|
val focusRequester = FocusRequester()
|
||||||
|
|
||||||
|
fun setFocus(state: FocusState) {
|
||||||
|
if (state.hasFocus) {
|
||||||
|
manager.focused = this
|
||||||
|
} else if (manager.focused === this) {
|
||||||
|
manager.focused = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package ch.dissem.yaep.ui.common.focus
|
||||||
|
|
||||||
|
import androidx.compose.ui.input.key.KeyEvent
|
||||||
|
|
||||||
|
object FocusFollowingSelectionManager : SelectionManager<FocusFollowingFocusable>() {
|
||||||
|
init {
|
||||||
|
isActive = true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun add(
|
||||||
|
primaryAction: (() -> Unit)?,
|
||||||
|
secondaryAction: (() -> Unit)?
|
||||||
|
): FocusFollowingFocusable {
|
||||||
|
return FocusFollowingFocusable(
|
||||||
|
manager = this,
|
||||||
|
primaryAction = primaryAction,
|
||||||
|
secondaryAction = secondaryAction
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Key events are ignored, the default focus mechanisms are used
|
||||||
|
override fun doOnKeyEvent(event: KeyEvent): Boolean = focused?.child?.onKeyEvent(event) == true
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package ch.dissem.yaep.ui.common.focus
|
||||||
|
|
||||||
|
import androidx.compose.ui.input.key.KeyEvent
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.combine
|
||||||
|
|
||||||
|
abstract class Focusable<F : Focusable<F>>(
|
||||||
|
protected val manager: SelectionManager<F>,
|
||||||
|
val primaryAction: (() -> Unit)?,
|
||||||
|
val secondaryAction: (() -> Unit)?,
|
||||||
|
var onKeyEvent: ((KeyEvent) -> Boolean)? = null
|
||||||
|
) {
|
||||||
|
|
||||||
|
val hasFocus: Flow<Boolean> =
|
||||||
|
combine(manager.isActiveFlow, manager.focusedFlow) { isActive, focused ->
|
||||||
|
isActive && focused == this
|
||||||
|
}
|
||||||
|
|
||||||
|
var child: SelectionManager<*>? = null
|
||||||
|
private set
|
||||||
|
|
||||||
|
fun <M : SelectionManager<*>> create(selectionManager: M): M = selectionManager.apply {
|
||||||
|
isActive = manager.isActive && manager.focused == this@Focusable
|
||||||
|
this@Focusable.child = this
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package ch.dissem.yaep.ui.common.focus
|
||||||
|
|
||||||
|
import androidx.compose.ui.input.key.KeyEvent
|
||||||
|
|
||||||
|
class GridFocusable(
|
||||||
|
manager: GridSelectionManager,
|
||||||
|
primaryAction: (() -> Unit)?,
|
||||||
|
secondaryAction: (() -> Unit)?,
|
||||||
|
onKeyEvent: ((KeyEvent) -> Boolean)? = null
|
||||||
|
) : Focusable<GridFocusable>(manager, primaryAction, secondaryAction, onKeyEvent)
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
package ch.dissem.yaep.ui.common.focus
|
||||||
|
|
||||||
|
import androidx.compose.ui.input.key.Key
|
||||||
|
import androidx.compose.ui.input.key.KeyEvent
|
||||||
|
import androidx.compose.ui.input.key.key
|
||||||
|
|
||||||
|
class GridSelectionManager : SelectionManager<GridFocusable>() {
|
||||||
|
|
||||||
|
val grid = mutableListOf<MutableList<GridFocusable>>()
|
||||||
|
|
||||||
|
var row = 0
|
||||||
|
var col = 0
|
||||||
|
|
||||||
|
fun addRow(): GridSelectionManager {
|
||||||
|
grid.add(mutableListOf())
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun add(onKeyEvent: (KeyEvent) -> Boolean): GridFocusable {
|
||||||
|
val new = GridFocusable(
|
||||||
|
manager = this,
|
||||||
|
primaryAction = null,
|
||||||
|
secondaryAction = null,
|
||||||
|
onKeyEvent = onKeyEvent
|
||||||
|
)
|
||||||
|
grid.last().add(new)
|
||||||
|
return new
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun add(
|
||||||
|
primaryAction: (() -> Unit)?,
|
||||||
|
secondaryAction: (() -> Unit)?
|
||||||
|
): GridFocusable {
|
||||||
|
val new = GridFocusable(
|
||||||
|
manager = this,
|
||||||
|
primaryAction = primaryAction,
|
||||||
|
secondaryAction = secondaryAction
|
||||||
|
)
|
||||||
|
grid.last().add(new)
|
||||||
|
return new
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun doOnKeyEvent(event: KeyEvent): Boolean {
|
||||||
|
if (grid.isEmpty()) return false
|
||||||
|
|
||||||
|
when (event.key) {
|
||||||
|
Key.DirectionDown -> {
|
||||||
|
row++
|
||||||
|
if (row >= grid.size) {
|
||||||
|
row = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Key.DirectionUp -> {
|
||||||
|
row--
|
||||||
|
if (row < 0) {
|
||||||
|
row = grid.size - 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Key.DirectionRight -> {
|
||||||
|
col++
|
||||||
|
if (col >= grid[row].size) {
|
||||||
|
col = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Key.DirectionLeft -> {
|
||||||
|
col--
|
||||||
|
if (col < 0) {
|
||||||
|
col = grid[row].size - 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> return focused?.child?.onKeyEvent(event) == true
|
||||||
|
}
|
||||||
|
|
||||||
|
focused = grid[row][col]
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package ch.dissem.yaep.ui.common.focus
|
||||||
|
|
||||||
|
class LinearFocusable(
|
||||||
|
manager: LinearSelectionManager,
|
||||||
|
primaryAction: (() -> Unit)?,
|
||||||
|
secondaryAction: (() -> Unit)?
|
||||||
|
) : Focusable<LinearFocusable>(manager, primaryAction, secondaryAction) {
|
||||||
|
|
||||||
|
var previous: LinearFocusable = this
|
||||||
|
private set
|
||||||
|
|
||||||
|
private var _next: LinearFocusable = this
|
||||||
|
var next: LinearFocusable
|
||||||
|
get() = _next
|
||||||
|
set(value) {
|
||||||
|
previous = value.previous
|
||||||
|
previous._next = this
|
||||||
|
value.previous = this
|
||||||
|
_next = value
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package ch.dissem.yaep.ui.common.focus
|
||||||
|
|
||||||
|
import androidx.compose.ui.input.key.Key
|
||||||
|
import androidx.compose.ui.input.key.KeyEvent
|
||||||
|
import androidx.compose.ui.input.key.isShiftPressed
|
||||||
|
import androidx.compose.ui.input.key.key
|
||||||
|
|
||||||
|
class LinearSelectionManager(
|
||||||
|
val keyNext: Key,
|
||||||
|
val keyPrevious: Key? = null
|
||||||
|
) : SelectionManager<LinearFocusable>() {
|
||||||
|
|
||||||
|
private fun focusNext() {
|
||||||
|
focused = focused?.next
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun focusPrevious() {
|
||||||
|
focused = focused?.previous
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun add(
|
||||||
|
primaryAction: (() -> Unit)?,
|
||||||
|
secondaryAction: (() -> Unit)?
|
||||||
|
): LinearFocusable {
|
||||||
|
val new = LinearFocusable(
|
||||||
|
manager = this,
|
||||||
|
primaryAction = primaryAction,
|
||||||
|
secondaryAction = secondaryAction
|
||||||
|
)
|
||||||
|
if (focused != null) {
|
||||||
|
new.next = focused!!
|
||||||
|
} else {
|
||||||
|
focused = new
|
||||||
|
}
|
||||||
|
return new
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun doOnKeyEvent(event: KeyEvent): Boolean {
|
||||||
|
if (event.key == keyNext) {
|
||||||
|
if (keyPrevious == null && event.isShiftPressed) {
|
||||||
|
focusPrevious()
|
||||||
|
} else {
|
||||||
|
focusNext()
|
||||||
|
}
|
||||||
|
} else if (event.key == keyPrevious) {
|
||||||
|
focusPrevious()
|
||||||
|
} else {
|
||||||
|
return focused?.child?.onKeyEvent(event) == true
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
package ch.dissem.yaep.ui.common.focus
|
||||||
|
|
||||||
|
import androidx.compose.ui.input.key.Key
|
||||||
|
import androidx.compose.ui.input.key.KeyEvent
|
||||||
|
import androidx.compose.ui.input.key.KeyEventType
|
||||||
|
import androidx.compose.ui.input.key.key
|
||||||
|
import androidx.compose.ui.input.key.type
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
|
||||||
|
abstract class SelectionManager<F : Focusable<F>> {
|
||||||
|
var isActiveFlow = MutableStateFlow<Boolean>(false)
|
||||||
|
var isActive: Boolean
|
||||||
|
get() = isActiveFlow.value
|
||||||
|
set(value) {
|
||||||
|
isActiveFlow.value = value
|
||||||
|
}
|
||||||
|
|
||||||
|
var focusedFlow = MutableStateFlow<F?>(null)
|
||||||
|
|
||||||
|
var focused: F?
|
||||||
|
get() = focusedFlow.value
|
||||||
|
set(value) {
|
||||||
|
val previous = focusedFlow.value
|
||||||
|
if (previous != value) {
|
||||||
|
previous?.child?.isActive = false
|
||||||
|
value?.child?.isActive = true
|
||||||
|
focusedFlow.value = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun add(): F = add(null, null)
|
||||||
|
|
||||||
|
fun add(primaryAction: () -> Unit): F = add(primaryAction, null)
|
||||||
|
|
||||||
|
abstract fun add(
|
||||||
|
primaryAction: (() -> Unit)?,
|
||||||
|
secondaryAction: (() -> Unit)?
|
||||||
|
): F
|
||||||
|
|
||||||
|
fun onKeyEvent(event: KeyEvent): Boolean {
|
||||||
|
if (event.type != KeyEventType.KeyUp) return false
|
||||||
|
|
||||||
|
return when (event.key) {
|
||||||
|
Key.Spacebar, Key.Enter -> {
|
||||||
|
focused?.primaryAction?.invoke() != null ||
|
||||||
|
focused?.onKeyEvent?.invoke(event) == true ||
|
||||||
|
focused?.child?.onKeyEvent(event) == true
|
||||||
|
}
|
||||||
|
|
||||||
|
Key.Delete, Key.Backspace -> {
|
||||||
|
focused?.secondaryAction?.invoke() != null ||
|
||||||
|
focused?.onKeyEvent?.invoke(event) == true ||
|
||||||
|
focused?.child?.onKeyEvent(event) == true
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> focused?.onKeyEvent?.invoke(event) == true || doOnKeyEvent(event)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract fun doOnKeyEvent(event: KeyEvent): Boolean
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package ch.dissem.yaep.ui.common
|
|||||||
|
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.RowScope
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.wrapContentHeight
|
import androidx.compose.foundation.layout.wrapContentHeight
|
||||||
@@ -12,6 +13,10 @@ import androidx.compose.runtime.mutableStateOf
|
|||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.input.key.Key
|
||||||
|
import androidx.compose.ui.input.key.KeyEvent
|
||||||
|
import androidx.compose.ui.input.key.isShiftPressed
|
||||||
|
import androidx.compose.ui.input.key.key
|
||||||
import androidx.compose.ui.unit.Dp
|
import androidx.compose.ui.unit.Dp
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import ch.dissem.yaep.domain.GameCell
|
import ch.dissem.yaep.domain.GameCell
|
||||||
@@ -19,11 +24,12 @@ import ch.dissem.yaep.domain.GameRow
|
|||||||
import ch.dissem.yaep.domain.Grid
|
import ch.dissem.yaep.domain.Grid
|
||||||
import ch.dissem.yaep.domain.Item
|
import ch.dissem.yaep.domain.Item
|
||||||
import ch.dissem.yaep.domain.ItemClass
|
import ch.dissem.yaep.domain.ItemClass
|
||||||
|
import ch.dissem.yaep.ui.common.focus.GridSelectionManager
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun PuzzleGrid(
|
fun PuzzleGrid(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
selectDirectly: Boolean,
|
selectionManager: GridSelectionManager,
|
||||||
spacing: Dp = 8.dp,
|
spacing: Dp = 8.dp,
|
||||||
grid: Grid,
|
grid: Grid,
|
||||||
onUpdate: () -> Unit
|
onUpdate: () -> Unit
|
||||||
@@ -36,7 +42,7 @@ fun PuzzleGrid(
|
|||||||
onSnapshot = { grid.snapshot() },
|
onSnapshot = { grid.snapshot() },
|
||||||
onUndo = { grid.undo() },
|
onUndo = { grid.undo() },
|
||||||
spacing = spacing,
|
spacing = spacing,
|
||||||
selectDirectly = selectDirectly
|
selectionManager = remember(selectionManager) { selectionManager.addRow() }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -49,18 +55,40 @@ private fun PuzzleRow(
|
|||||||
onSnapshot: () -> Unit,
|
onSnapshot: () -> Unit,
|
||||||
onUndo: () -> Boolean,
|
onUndo: () -> Boolean,
|
||||||
spacing: Dp,
|
spacing: Dp,
|
||||||
selectDirectly: Boolean
|
selectionManager: GridSelectionManager
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.wrapContentHeight()
|
.wrapContentHeight()
|
||||||
) {
|
) {
|
||||||
val allOptions = row.options
|
|
||||||
for (cell in row) {
|
for (cell in row) {
|
||||||
|
PuzzleCell(
|
||||||
|
cell,
|
||||||
|
row,
|
||||||
|
onUpdate,
|
||||||
|
onSnapshot,
|
||||||
|
onUndo,
|
||||||
|
spacing,
|
||||||
|
selectionManager
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun RowScope.PuzzleCell(
|
||||||
|
cell: GameCell<ItemClass<*>>,
|
||||||
|
row: GameRow<ItemClass<*>>,
|
||||||
|
onUpdate: () -> Unit,
|
||||||
|
onSnapshot: () -> Unit,
|
||||||
|
onUndo: () -> Boolean,
|
||||||
|
spacing: Dp,
|
||||||
|
selectionManager: GridSelectionManager
|
||||||
|
) {
|
||||||
var selection by remember(cell) { mutableStateOf(cell.selection) }
|
var selection by remember(cell) { mutableStateOf(cell.selection) }
|
||||||
val options = remember(cell) {
|
val options = remember(cell) {
|
||||||
allOptions.map { Toggleable(it, cell.options.contains(it)) }
|
row.options.map { Toggleable(it, cell.options.contains(it)) }
|
||||||
}
|
}
|
||||||
LaunchedEffect(cell) {
|
LaunchedEffect(cell) {
|
||||||
cell.optionsChangedListeners.add { enabled ->
|
cell.optionsChangedListeners.add { enabled ->
|
||||||
@@ -71,17 +99,24 @@ private fun PuzzleRow(
|
|||||||
onUpdate()
|
onUpdate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
val focusable = remember(cell, selectionManager) {
|
||||||
|
selectionManager.add { e ->
|
||||||
|
if (selection != null) {
|
||||||
|
handleClearSelection(e.key, row, cell, options, onSnapshot, onUndo)
|
||||||
|
} else {
|
||||||
|
handleSelection(e, options, cell, row, onSnapshot, onUndo)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Selector(
|
Selector(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
|
.focus(focusable)
|
||||||
.padding(spacing)
|
.padding(spacing)
|
||||||
.weight(1f),
|
.weight(1f),
|
||||||
spacing,
|
spacing,
|
||||||
selectDirectly = selectDirectly,
|
|
||||||
options = options,
|
options = options,
|
||||||
onOptionRemoved = {
|
onOptionRemoved = { selectedItem ->
|
||||||
onSnapshot()
|
onOptionRemoved(row, cell, selectedItem, onSnapshot)
|
||||||
cell.options.remove(it)
|
|
||||||
row.cleanupOptions()
|
|
||||||
},
|
},
|
||||||
onOptionAdded = {
|
onOptionAdded = {
|
||||||
cell.options.add(it)
|
cell.options.add(it)
|
||||||
@@ -92,7 +127,72 @@ private fun PuzzleRow(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun handleSelection(
|
||||||
|
e: KeyEvent,
|
||||||
|
options: List<Toggleable<Item<ItemClass<*>>>>,
|
||||||
|
cell: GameCell<ItemClass<*>>,
|
||||||
|
row: GameRow<ItemClass<*>>,
|
||||||
|
onSnapshot: () -> Unit,
|
||||||
|
onUndo: () -> Boolean
|
||||||
|
): Boolean {
|
||||||
|
val i = getNumber(e)
|
||||||
|
return if (i != null && i in 1..options.size) {
|
||||||
|
val selectedItem = options[i - 1].item
|
||||||
|
if (e.isShiftPressed) {
|
||||||
|
if (cell.options.contains(selectedItem)) {
|
||||||
|
onOptionRemoved(row, cell, selectedItem, onSnapshot)
|
||||||
|
} else {
|
||||||
|
cell.options.add(selectedItem)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
onSelectItem(row, cell, options, selectedItem, onSnapshot, onUndo)
|
||||||
|
}
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun handleClearSelection(
|
||||||
|
key: Key,
|
||||||
|
row: GameRow<ItemClass<*>>,
|
||||||
|
cell: GameCell<ItemClass<*>>,
|
||||||
|
options: List<Toggleable<Item<ItemClass<*>>>>,
|
||||||
|
onSnapshot: () -> Unit,
|
||||||
|
onUndo: () -> Boolean
|
||||||
|
): Boolean = when (key) {
|
||||||
|
Key.Spacebar, Key.Enter, Key.Delete, Key.Backspace -> {
|
||||||
|
onSelectItem(row, cell, options, null, onSnapshot, onUndo)
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun onOptionRemoved(
|
||||||
|
row: GameRow<ItemClass<*>>,
|
||||||
|
cell: GameCell<ItemClass<*>>,
|
||||||
|
selectedItem: Item<ItemClass<*>>?,
|
||||||
|
onSnapshot: () -> Unit
|
||||||
|
) {
|
||||||
|
onSnapshot()
|
||||||
|
cell.options.remove(selectedItem)
|
||||||
|
row.cleanupOptions()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getNumber(e: KeyEvent): Int? = when (e.key) {
|
||||||
|
Key.Zero, Key.NumPad0 -> 0
|
||||||
|
Key.One, Key.NumPad1 -> 1
|
||||||
|
Key.Two, Key.NumPad2 -> 2
|
||||||
|
Key.Three, Key.NumPad3 -> 3
|
||||||
|
Key.Four, Key.NumPad4 -> 4
|
||||||
|
Key.Five, Key.NumPad5 -> 5
|
||||||
|
Key.Six, Key.NumPad6 -> 6
|
||||||
|
Key.Seven, Key.NumPad7 -> 7
|
||||||
|
Key.Eight, Key.NumPad8 -> 8
|
||||||
|
Key.Nine, Key.NumPad9 -> 9
|
||||||
|
else -> null
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onSelectItem(
|
private fun onSelectItem(
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package ch.dissem.yaep.ui.common.layout
|
||||||
|
|
||||||
|
import androidx.compose.ui.unit.Constraints
|
||||||
|
|
||||||
|
enum class AspectRatio {
|
||||||
|
PORTRAIT, LANDSCAPE, SQUARISH;
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val ASPECT_RATIO_LANDSCAPE = 1.4f
|
||||||
|
private const val ASPECT_RATIO_PORTRAIT = 1 / ASPECT_RATIO_LANDSCAPE
|
||||||
|
|
||||||
|
fun from(constraints: Constraints): AspectRatio {
|
||||||
|
val ratio = constraints.maxWidth.toFloat() / constraints.maxHeight.toFloat()
|
||||||
|
return when {
|
||||||
|
ratio < ASPECT_RATIO_PORTRAIT -> PORTRAIT
|
||||||
|
ratio > ASPECT_RATIO_LANDSCAPE -> LANDSCAPE
|
||||||
|
else -> SQUARISH
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package ch.dissem.yaep.ui.common.layout
|
||||||
|
|
||||||
|
import androidx.compose.ui.layout.Measurable
|
||||||
|
import ch.dissem.yaep.ui.common.focus.CluesSelectionManager
|
||||||
|
|
||||||
|
data class FocusGroup(
|
||||||
|
val items: List<Measurable>,
|
||||||
|
val box: Measurable,
|
||||||
|
val selectionManger: CluesSelectionManager? = null
|
||||||
|
) {
|
||||||
|
val item: Measurable
|
||||||
|
get() = items.single()
|
||||||
|
|
||||||
|
val hasItems: Boolean = items.isNotEmpty()
|
||||||
|
|
||||||
|
val count = items.size
|
||||||
|
}
|
||||||
@@ -0,0 +1,164 @@
|
|||||||
|
package ch.dissem.yaep.ui.common.layout
|
||||||
|
|
||||||
|
import androidx.compose.material3.HorizontalDivider
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.layout.Layout
|
||||||
|
import androidx.compose.ui.layout.Placeable
|
||||||
|
import androidx.compose.ui.unit.Constraints
|
||||||
|
import androidx.compose.ui.unit.Constraints.Companion.fixed
|
||||||
|
import androidx.compose.ui.unit.Dp
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import ch.dissem.yaep.ui.common.focus.CluesSelectionManager
|
||||||
|
import ch.dissem.yaep.ui.common.focus.FocusFollowingFocusable
|
||||||
|
import ch.dissem.yaep.ui.common.focus.GridSelectionManager
|
||||||
|
import ch.dissem.yaep.ui.common.focus.SelectionManager
|
||||||
|
import ch.dissem.yaep.ui.common.layout.AspectRatio.LANDSCAPE
|
||||||
|
import ch.dissem.yaep.ui.common.layout.AspectRatio.PORTRAIT
|
||||||
|
import ch.dissem.yaep.ui.common.layout.AspectRatio.SQUARISH
|
||||||
|
import kotlin.math.ceil
|
||||||
|
import kotlin.math.max
|
||||||
|
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun AdaptiveGameLayout(
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
selectionManager: SelectionManager<FocusFollowingFocusable>,
|
||||||
|
grid: @Composable (GridSelectionManager) -> Unit,
|
||||||
|
horizontalClues: @Composable (SelectionManager<*>) -> Unit,
|
||||||
|
verticalClues: @Composable (SelectionManager<*>) -> Unit,
|
||||||
|
time: @Composable () -> Unit,
|
||||||
|
spacing: Dp = 8.dp,
|
||||||
|
vararg resetBeacons: Any
|
||||||
|
) {
|
||||||
|
val gridFocusable = remember(*resetBeacons) { selectionManager.add() }
|
||||||
|
val gridSelectionManager = remember(*resetBeacons) { gridFocusable.create(GridSelectionManager()) }
|
||||||
|
|
||||||
|
val horizontalCluesFocusable = remember(*resetBeacons) { selectionManager.add() }
|
||||||
|
val horizontalCluesSelectionManager = remember(*resetBeacons) {
|
||||||
|
horizontalCluesFocusable.create(CluesSelectionManager())
|
||||||
|
}
|
||||||
|
|
||||||
|
val verticalCluesFocusable = remember(*resetBeacons) { selectionManager.add() }
|
||||||
|
val verticalCluesSelectionManager = remember(*resetBeacons) {
|
||||||
|
verticalCluesFocusable.create(CluesSelectionManager())
|
||||||
|
}
|
||||||
|
Layout(
|
||||||
|
contents = listOf(
|
||||||
|
{ grid(gridSelectionManager) },
|
||||||
|
{ FocusBox(gridFocusable, requestFocus = true) },
|
||||||
|
{ horizontalClues(horizontalCluesSelectionManager) },
|
||||||
|
{ FocusBox(horizontalCluesFocusable) },
|
||||||
|
{ verticalClues(verticalCluesSelectionManager) },
|
||||||
|
{ FocusBox(verticalCluesFocusable) },
|
||||||
|
time,
|
||||||
|
{
|
||||||
|
HorizontalDivider()
|
||||||
|
HorizontalDivider()
|
||||||
|
}
|
||||||
|
),
|
||||||
|
modifier = modifier
|
||||||
|
) { measurables, constraints ->
|
||||||
|
layout(width = constraints.maxWidth, height = constraints.maxHeight) {
|
||||||
|
val aspectRatio = AspectRatio.from(constraints)
|
||||||
|
|
||||||
|
val gridGroup = FocusGroup(
|
||||||
|
items = measurables[0],
|
||||||
|
box = measurables[1][0],
|
||||||
|
)
|
||||||
|
val horizontalCluesGroup = FocusGroup(
|
||||||
|
items = measurables[2],
|
||||||
|
box = measurables[3][0],
|
||||||
|
selectionManger = horizontalCluesSelectionManager
|
||||||
|
)
|
||||||
|
val verticalCluesGroup = FocusGroup(
|
||||||
|
items = measurables[4],
|
||||||
|
box = measurables[5][0],
|
||||||
|
selectionManger = verticalCluesSelectionManager
|
||||||
|
)
|
||||||
|
val timeMeasurable = measurables[6][0]
|
||||||
|
val dividerMeasurables = measurables[7]
|
||||||
|
|
||||||
|
val spacingPx = spacing.roundToPx()
|
||||||
|
|
||||||
|
when (aspectRatio) {
|
||||||
|
PORTRAIT -> {
|
||||||
|
portrait(
|
||||||
|
constraints,
|
||||||
|
spacingPx,
|
||||||
|
gridGroup,
|
||||||
|
horizontalCluesGroup,
|
||||||
|
verticalCluesGroup,
|
||||||
|
timeMeasurable,
|
||||||
|
dividerMeasurables
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
SQUARISH -> {
|
||||||
|
squarish(
|
||||||
|
constraints,
|
||||||
|
spacingPx,
|
||||||
|
gridGroup,
|
||||||
|
horizontalCluesGroup,
|
||||||
|
verticalCluesGroup,
|
||||||
|
timeMeasurable
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
LANDSCAPE -> {
|
||||||
|
landscape(
|
||||||
|
constraints,
|
||||||
|
spacingPx,
|
||||||
|
gridGroup,
|
||||||
|
horizontalCluesGroup,
|
||||||
|
verticalCluesGroup,
|
||||||
|
timeMeasurable,
|
||||||
|
dividerMeasurables[0]
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun cluesBoxConstraints(
|
||||||
|
width: Int,
|
||||||
|
itemConstraints: Constraints,
|
||||||
|
group: FocusGroup
|
||||||
|
): Constraints {
|
||||||
|
val columns = width / itemConstraints.maxWidth
|
||||||
|
group.selectionManger?.columns = columns
|
||||||
|
return fixed(
|
||||||
|
width,
|
||||||
|
itemConstraints.maxHeight * ceil(group.count.toFloat() / columns).toInt()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun Placeable.PlacementScope.placeClues(
|
||||||
|
placeables: List<Placeable>,
|
||||||
|
offsetX: Int,
|
||||||
|
offsetY: Int,
|
||||||
|
maxWidth: Int
|
||||||
|
): Int {
|
||||||
|
if (placeables.isEmpty()) return offsetY
|
||||||
|
|
||||||
|
val itemWidth = placeables.first().width
|
||||||
|
val itemHeight = placeables.first().height
|
||||||
|
val columns = max(1, maxWidth / itemWidth)
|
||||||
|
val spacing = if (columns == 1) 0 else (maxWidth - columns * itemWidth) / (columns - 1)
|
||||||
|
var currentX = offsetX
|
||||||
|
var currentY = offsetY
|
||||||
|
var i = 0
|
||||||
|
for (placeable in placeables) {
|
||||||
|
placeable.place(currentX, currentY)
|
||||||
|
currentX += itemWidth + spacing
|
||||||
|
i++
|
||||||
|
if (i % columns == 0 && i < placeables.size) {
|
||||||
|
currentX = offsetX
|
||||||
|
currentY += itemHeight
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return currentY + itemHeight
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package ch.dissem.yaep.ui.common.layout
|
||||||
|
|
||||||
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.focusable
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.collectAsState
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.draw.clip
|
||||||
|
import androidx.compose.ui.focus.focusRequester
|
||||||
|
import androidx.compose.ui.focus.onFocusChanged
|
||||||
|
import androidx.compose.ui.focus.onFocusEvent
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import ch.dissem.yaep.ui.common.focus.FocusFollowingFocusable
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun FocusBox(focusable: FocusFollowingFocusable, requestFocus: Boolean = false) {
|
||||||
|
val hasFocus by focusable.hasFocus.collectAsState(false)
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.focusRequester(focusable.focusRequester)
|
||||||
|
.onFocusEvent { state ->
|
||||||
|
focusable.setFocus(state)
|
||||||
|
}
|
||||||
|
.onFocusChanged {}
|
||||||
|
.focusable()
|
||||||
|
.clip(MaterialTheme.shapes.small)
|
||||||
|
.background(
|
||||||
|
if (hasFocus) {
|
||||||
|
MaterialTheme.colorScheme.surfaceContainerHigh
|
||||||
|
} else {
|
||||||
|
Color.Transparent
|
||||||
|
}
|
||||||
|
),
|
||||||
|
)
|
||||||
|
if (requestFocus) {
|
||||||
|
LaunchedEffect(Unit) {
|
||||||
|
focusable.focusRequester.requestFocus()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
package ch.dissem.yaep.ui.common.layout
|
||||||
|
|
||||||
|
import androidx.compose.ui.layout.Measurable
|
||||||
|
import androidx.compose.ui.layout.Placeable
|
||||||
|
import androidx.compose.ui.unit.Constraints
|
||||||
|
import androidx.compose.ui.unit.Constraints.Companion.fixed
|
||||||
|
import androidx.compose.ui.unit.Constraints.Companion.fixedWidth
|
||||||
|
|
||||||
|
internal fun Placeable.PlacementScope.landscape(
|
||||||
|
constraints: Constraints,
|
||||||
|
spacingPx: Int,
|
||||||
|
grid: FocusGroup,
|
||||||
|
horizontalClues: FocusGroup,
|
||||||
|
verticalClues: FocusGroup,
|
||||||
|
timeMeasurable: Measurable,
|
||||||
|
dividerMeasurable: Measurable
|
||||||
|
) {
|
||||||
|
val gridSize = constraints.maxHeight
|
||||||
|
val gridItemSize = (gridSize - 12 * spacingPx) / 18
|
||||||
|
val rightBarWidth = constraints.maxWidth - gridSize - 2 * spacingPx
|
||||||
|
|
||||||
|
val gridConstraints = fixed(gridSize, gridSize)
|
||||||
|
val baseSpace = gridSize - 2 * spacingPx
|
||||||
|
val horizontalCluesConstraints = fixed(
|
||||||
|
width = 3 * gridItemSize + 2 * spacingPx,
|
||||||
|
height = gridItemSize + 2 * spacingPx
|
||||||
|
)
|
||||||
|
val verticalCluesConstraints = fixed(
|
||||||
|
width = gridItemSize + 2 * spacingPx,
|
||||||
|
height = 3 * gridItemSize + 2 * spacingPx
|
||||||
|
)
|
||||||
|
val timeConstraints = Constraints.fixedHeight(baseSpace / 10)
|
||||||
|
val dividerConstraints = fixedWidth(rightBarWidth - 2 * spacingPx)
|
||||||
|
|
||||||
|
val gridPlaceable = grid.item.measure(gridConstraints)
|
||||||
|
val gridBoxPlaceable = grid.box.measure(gridConstraints)
|
||||||
|
val horizontalCluesPlaceables = horizontalClues.items.map {
|
||||||
|
it.measure(horizontalCluesConstraints)
|
||||||
|
}
|
||||||
|
val horizontalCluesBoxPlaceable = horizontalClues.box
|
||||||
|
.measure(
|
||||||
|
cluesBoxConstraints(
|
||||||
|
width = rightBarWidth,
|
||||||
|
itemConstraints = horizontalCluesConstraints,
|
||||||
|
group = horizontalClues
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
val verticalCluesPlaceables = verticalClues.items.map {
|
||||||
|
it.measure(verticalCluesConstraints)
|
||||||
|
}
|
||||||
|
val verticalCluesBoxPlaceable = verticalClues.box
|
||||||
|
.measure(
|
||||||
|
cluesBoxConstraints(
|
||||||
|
width = rightBarWidth,
|
||||||
|
itemConstraints = verticalCluesConstraints,
|
||||||
|
group = verticalClues
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
val timePlaceable = timeMeasurable.measure(timeConstraints)
|
||||||
|
val dividerPlaceable = dividerMeasurable.measure(dividerConstraints)
|
||||||
|
|
||||||
|
// Position the grid
|
||||||
|
gridBoxPlaceable.place(0, 0)
|
||||||
|
gridPlaceable.place(0, 0)
|
||||||
|
|
||||||
|
// Position the horizontal clues4
|
||||||
|
val horizontalCluesOffsetX = gridSize + 2 * spacingPx
|
||||||
|
horizontalCluesBoxPlaceable.place(horizontalCluesOffsetX, 0)
|
||||||
|
val offsetY = placeClues(
|
||||||
|
placeables = horizontalCluesPlaceables,
|
||||||
|
offsetX = horizontalCluesOffsetX,
|
||||||
|
offsetY = 0,
|
||||||
|
maxWidth = rightBarWidth
|
||||||
|
)
|
||||||
|
|
||||||
|
if (verticalClues.hasItems) {
|
||||||
|
// Add divider in between
|
||||||
|
dividerPlaceable.place(gridSize + 3 * spacingPx, offsetY + spacingPx)
|
||||||
|
|
||||||
|
// Position the vertical clues
|
||||||
|
val verticalCluesOffsetX = gridSize + 2 * spacingPx
|
||||||
|
val verticalCluesOffsetY = offsetY + spacingPx + dividerPlaceable.height
|
||||||
|
verticalCluesBoxPlaceable.place(verticalCluesOffsetX, verticalCluesOffsetY)
|
||||||
|
placeClues(
|
||||||
|
placeables = verticalCluesPlaceables,
|
||||||
|
offsetX = verticalCluesOffsetX,
|
||||||
|
offsetY = verticalCluesOffsetY,
|
||||||
|
maxWidth = rightBarWidth
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Position the time
|
||||||
|
timePlaceable.place(
|
||||||
|
x = constraints.maxWidth - timePlaceable.width - spacingPx,
|
||||||
|
y = constraints.maxHeight - timePlaceable.height
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,115 @@
|
|||||||
|
package ch.dissem.yaep.ui.common.layout
|
||||||
|
|
||||||
|
import androidx.compose.ui.layout.Measurable
|
||||||
|
import androidx.compose.ui.layout.Placeable
|
||||||
|
import androidx.compose.ui.unit.Constraints
|
||||||
|
import androidx.compose.ui.unit.Constraints.Companion.fixed
|
||||||
|
import androidx.compose.ui.unit.Constraints.Companion.fixedWidth
|
||||||
|
|
||||||
|
internal fun Placeable.PlacementScope.portrait(
|
||||||
|
constraints: Constraints,
|
||||||
|
spacingPx: Int,
|
||||||
|
grid: FocusGroup,
|
||||||
|
horizontalClues: FocusGroup,
|
||||||
|
verticalClues: FocusGroup,
|
||||||
|
timeMeasurable: Measurable,
|
||||||
|
dividerMeasurables: List<Measurable>
|
||||||
|
) {
|
||||||
|
val gridSize = constraints.maxWidth
|
||||||
|
val gridItemSize = (gridSize - 12 * spacingPx) / 18
|
||||||
|
|
||||||
|
val gridConstraints = fixed(gridSize, gridSize)
|
||||||
|
val horizontalCluesConstraints = fixed(
|
||||||
|
width = 3 * gridItemSize + 2 * spacingPx,
|
||||||
|
height = gridItemSize + 2 * spacingPx
|
||||||
|
)
|
||||||
|
val verticalCluesConstraints = fixed(
|
||||||
|
width = gridItemSize + 2 * spacingPx,
|
||||||
|
height = 3 * gridItemSize + 2 * spacingPx
|
||||||
|
)
|
||||||
|
val timeConstraints = Constraints()
|
||||||
|
val dividerConstraints = fixedWidth(gridSize)
|
||||||
|
|
||||||
|
val gridPlaceable = grid.item.measure(gridConstraints)
|
||||||
|
val gridBoxPlaceable = grid.box.measure(gridConstraints)
|
||||||
|
val horizontalCluesPlaceables = horizontalClues.items.map {
|
||||||
|
it.measure(horizontalCluesConstraints)
|
||||||
|
}
|
||||||
|
val verticalCluesPlaceables = verticalClues.items.map {
|
||||||
|
it.measure(verticalCluesConstraints)
|
||||||
|
}
|
||||||
|
val timePlaceable = timeMeasurable.measure(timeConstraints)
|
||||||
|
val divider1Placeable = dividerMeasurables[0].measure(dividerConstraints)
|
||||||
|
val divider2Placeable = dividerMeasurables[1].measure(dividerConstraints)
|
||||||
|
|
||||||
|
val horizontalCluesBoxPlaceable = horizontalClues.box
|
||||||
|
.measure(
|
||||||
|
cluesBoxConstraints(
|
||||||
|
width = gridSize,
|
||||||
|
itemConstraints = horizontalCluesConstraints,
|
||||||
|
group = horizontalClues
|
||||||
|
)
|
||||||
|
)
|
||||||
|
val verticalCluesBoxPlaceable = verticalClues.box
|
||||||
|
.measure(
|
||||||
|
cluesBoxConstraints(
|
||||||
|
width = gridSize,
|
||||||
|
itemConstraints = verticalCluesConstraints,
|
||||||
|
group = verticalClues
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
// Position the grid
|
||||||
|
gridBoxPlaceable.place(0, 0)
|
||||||
|
gridPlaceable.place(0, 0)
|
||||||
|
|
||||||
|
divider1Placeable.place(0, gridSize + spacingPx)
|
||||||
|
|
||||||
|
// Position the horizontal clues
|
||||||
|
val horizontalCluesOffsetY = gridSize + 2 * spacingPx
|
||||||
|
|
||||||
|
horizontalCluesBoxPlaceable.place(0, horizontalCluesOffsetY)
|
||||||
|
var offsetY = placeClues(
|
||||||
|
placeables = horizontalCluesPlaceables,
|
||||||
|
offsetX = 0,
|
||||||
|
offsetY = horizontalCluesOffsetY,
|
||||||
|
maxWidth = gridSize
|
||||||
|
)
|
||||||
|
|
||||||
|
if (verticalClues.hasItems) {
|
||||||
|
// Add divider in between
|
||||||
|
divider2Placeable.place(0, offsetY + spacingPx)
|
||||||
|
|
||||||
|
// Position the vertical clues
|
||||||
|
val verticalCluesOffsetY = offsetY + spacingPx + divider2Placeable.height
|
||||||
|
verticalCluesBoxPlaceable.place(0, verticalCluesOffsetY)
|
||||||
|
offsetY = placeClues(
|
||||||
|
placeables = verticalCluesPlaceables,
|
||||||
|
offsetX = 0,
|
||||||
|
offsetY = verticalCluesOffsetY,
|
||||||
|
maxWidth = gridSize
|
||||||
|
)
|
||||||
|
verticalCluesBoxPlaceable.place(0, verticalCluesOffsetY)
|
||||||
|
}
|
||||||
|
// Position the time
|
||||||
|
val remainingSpace = constraints.maxHeight - offsetY
|
||||||
|
if (remainingSpace < timePlaceable.height) {
|
||||||
|
val scale = remainingSpace.toFloat() / timePlaceable.height.toFloat()
|
||||||
|
if (scale > 0.1f) {
|
||||||
|
timePlaceable.placeWithLayer(
|
||||||
|
x = constraints.maxWidth - timePlaceable.width - spacingPx,
|
||||||
|
y = constraints.maxHeight - timePlaceable.height
|
||||||
|
) {
|
||||||
|
scaleX = scale
|
||||||
|
scaleY = scale
|
||||||
|
translationX = (timePlaceable.width * (1 - scale)) / 2f
|
||||||
|
translationY = (timePlaceable.height * (1 - scale)) / 2f
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
timePlaceable.place(
|
||||||
|
x = constraints.maxWidth - timePlaceable.width - spacingPx,
|
||||||
|
y = constraints.maxHeight - timePlaceable.height
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
package ch.dissem.yaep.ui.common.layout
|
||||||
|
|
||||||
|
import androidx.compose.ui.layout.Measurable
|
||||||
|
import androidx.compose.ui.layout.Placeable
|
||||||
|
import androidx.compose.ui.unit.Constraints
|
||||||
|
import androidx.compose.ui.unit.Constraints.Companion.fixed
|
||||||
|
import kotlin.math.min
|
||||||
|
|
||||||
|
internal fun Placeable.PlacementScope.squarish(
|
||||||
|
constraints: Constraints,
|
||||||
|
spacingPx: Int,
|
||||||
|
grid: FocusGroup,
|
||||||
|
horizontalClues: FocusGroup,
|
||||||
|
verticalClues: FocusGroup,
|
||||||
|
timeMeasurable: Measurable
|
||||||
|
) {
|
||||||
|
val gridSize = (7 * min(constraints.maxWidth, constraints.maxHeight)) / 10
|
||||||
|
val gridItemSize = (gridSize - 12 * spacingPx) / 18
|
||||||
|
val rightBarWidth = constraints.maxWidth - gridSize - spacingPx
|
||||||
|
|
||||||
|
val gridConstraints = fixed(gridSize, gridSize)
|
||||||
|
val horizontalCluesConstraints = fixed(
|
||||||
|
width = 3 * gridItemSize + 2 * spacingPx,
|
||||||
|
height = gridItemSize + 2 * spacingPx
|
||||||
|
)
|
||||||
|
val verticalCluesConstraints = fixed(
|
||||||
|
width = gridItemSize + 2 * spacingPx,
|
||||||
|
height = 3 * gridItemSize + 2 * spacingPx
|
||||||
|
)
|
||||||
|
val timeConstraints = Constraints()
|
||||||
|
|
||||||
|
|
||||||
|
val gridPlaceable = grid.item.measure(gridConstraints)
|
||||||
|
val gridBoxPlaceable = grid.box.measure(gridConstraints)
|
||||||
|
val horizontalCluesPlaceables = horizontalClues.items.map {
|
||||||
|
it.measure(horizontalCluesConstraints)
|
||||||
|
}
|
||||||
|
val horizontalCluesBoxPlaceable = horizontalClues.box
|
||||||
|
.measure(
|
||||||
|
cluesBoxConstraints(
|
||||||
|
width = rightBarWidth,
|
||||||
|
itemConstraints = horizontalCluesConstraints,
|
||||||
|
group = horizontalClues
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
val verticalCluesPlaceables = verticalClues.items.map {
|
||||||
|
it.measure(verticalCluesConstraints)
|
||||||
|
}
|
||||||
|
val verticalCluesBoxPlaceable = verticalClues.box
|
||||||
|
.measure(
|
||||||
|
cluesBoxConstraints(
|
||||||
|
width = rightBarWidth,
|
||||||
|
itemConstraints = verticalCluesConstraints,
|
||||||
|
group = verticalClues
|
||||||
|
)
|
||||||
|
)
|
||||||
|
val timePlaceable = timeMeasurable.measure(timeConstraints)
|
||||||
|
|
||||||
|
// Position the grid
|
||||||
|
gridBoxPlaceable.place(0, 0)
|
||||||
|
gridPlaceable.place(0, 0)
|
||||||
|
|
||||||
|
// Position the horizontal clues
|
||||||
|
val horizontalCluesOffsetX = gridSize + 2 * spacingPx
|
||||||
|
horizontalCluesBoxPlaceable.place(horizontalCluesOffsetX, 0)
|
||||||
|
placeClues(
|
||||||
|
placeables = horizontalCluesPlaceables,
|
||||||
|
offsetX = horizontalCluesOffsetX,
|
||||||
|
offsetY = 0,
|
||||||
|
maxWidth = rightBarWidth
|
||||||
|
)
|
||||||
|
|
||||||
|
if (verticalClues.hasItems) {
|
||||||
|
// Position the vertical clues
|
||||||
|
val verticalCluesOffsetY = gridSize + 2 * spacingPx
|
||||||
|
verticalCluesBoxPlaceable.place(0, verticalCluesOffsetY)
|
||||||
|
placeClues(
|
||||||
|
placeables = verticalCluesPlaceables,
|
||||||
|
offsetX = 0,
|
||||||
|
offsetY = verticalCluesOffsetY,
|
||||||
|
maxWidth = gridSize
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Position the time
|
||||||
|
timePlaceable.place(
|
||||||
|
x = constraints.maxWidth - timePlaceable.width - spacingPx,
|
||||||
|
y = constraints.maxHeight - timePlaceable.height
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package ch.dissem.yaep.ui.common
|
||||||
|
|
||||||
|
import kotlin.math.absoluteValue
|
||||||
|
import kotlin.math.sign
|
||||||
|
|
||||||
|
infix fun Int.ceilDiv(other: Int): Int {
|
||||||
|
return this.floorDiv(other) + this.rem(other).sign.absoluteValue
|
||||||
|
}
|
||||||
@@ -13,16 +13,15 @@ import yaep.commonui.generated.resources.Res
|
|||||||
import yaep.commonui.generated.resources.ant
|
import yaep.commonui.generated.resources.ant
|
||||||
import yaep.commonui.generated.resources.astronaut
|
import yaep.commonui.generated.resources.astronaut
|
||||||
import yaep.commonui.generated.resources.banana
|
import yaep.commonui.generated.resources.banana
|
||||||
import yaep.commonui.generated.resources.bubble_tea
|
|
||||||
import yaep.commonui.generated.resources.beverage
|
import yaep.commonui.generated.resources.beverage
|
||||||
import yaep.commonui.generated.resources.bicycle
|
import yaep.commonui.generated.resources.bicycle
|
||||||
import yaep.commonui.generated.resources.british
|
import yaep.commonui.generated.resources.british
|
||||||
|
import yaep.commonui.generated.resources.bubble_tea
|
||||||
import yaep.commonui.generated.resources.bus
|
import yaep.commonui.generated.resources.bus
|
||||||
import yaep.commonui.generated.resources.cake
|
import yaep.commonui.generated.resources.cake
|
||||||
import yaep.commonui.generated.resources.canadian
|
import yaep.commonui.generated.resources.canadian
|
||||||
import yaep.commonui.generated.resources.cherries
|
import yaep.commonui.generated.resources.cherries
|
||||||
import yaep.commonui.generated.resources.chocolate
|
import yaep.commonui.generated.resources.chocolate
|
||||||
import yaep.commonui.generated.resources.water
|
|
||||||
import yaep.commonui.generated.resources.coffee
|
import yaep.commonui.generated.resources.coffee
|
||||||
import yaep.commonui.generated.resources.cookie
|
import yaep.commonui.generated.resources.cookie
|
||||||
import yaep.commonui.generated.resources.cupcake
|
import yaep.commonui.generated.resources.cupcake
|
||||||
@@ -41,6 +40,7 @@ import yaep.commonui.generated.resources.lemon
|
|||||||
import yaep.commonui.generated.resources.locomotive
|
import yaep.commonui.generated.resources.locomotive
|
||||||
import yaep.commonui.generated.resources.lollipop
|
import yaep.commonui.generated.resources.lollipop
|
||||||
import yaep.commonui.generated.resources.mango
|
import yaep.commonui.generated.resources.mango
|
||||||
|
import yaep.commonui.generated.resources.mate
|
||||||
import yaep.commonui.generated.resources.milk
|
import yaep.commonui.generated.resources.milk
|
||||||
import yaep.commonui.generated.resources.motor_scooter
|
import yaep.commonui.generated.resources.motor_scooter
|
||||||
import yaep.commonui.generated.resources.norwegian
|
import yaep.commonui.generated.resources.norwegian
|
||||||
@@ -63,8 +63,8 @@ import yaep.commonui.generated.resources.tea
|
|||||||
import yaep.commonui.generated.resources.teacher
|
import yaep.commonui.generated.resources.teacher
|
||||||
import yaep.commonui.generated.resources.tram_car
|
import yaep.commonui.generated.resources.tram_car
|
||||||
import yaep.commonui.generated.resources.ukrainian
|
import yaep.commonui.generated.resources.ukrainian
|
||||||
|
import yaep.commonui.generated.resources.water
|
||||||
import yaep.commonui.generated.resources.watermelon
|
import yaep.commonui.generated.resources.watermelon
|
||||||
import yaep.commonui.generated.resources.mate
|
|
||||||
import yaep.commonui.generated.resources.zebra
|
import yaep.commonui.generated.resources.zebra
|
||||||
|
|
||||||
val ItemClass<*>.localName: StringResource
|
val ItemClass<*>.localName: StringResource
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package ch.dissem.yaep.ui.common
|
package ch.dissem.yaep.ui.common
|
||||||
|
|
||||||
import androidx.compose.foundation.Canvas
|
import androidx.compose.foundation.Canvas
|
||||||
import androidx.compose.foundation.clickable
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.aspectRatio
|
import androidx.compose.foundation.layout.aspectRatio
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
@@ -20,6 +19,7 @@ import androidx.compose.ui.text.TextStyle
|
|||||||
import androidx.compose.ui.text.drawText
|
import androidx.compose.ui.text.drawText
|
||||||
import androidx.compose.ui.text.rememberTextMeasurer
|
import androidx.compose.ui.text.rememberTextMeasurer
|
||||||
import androidx.compose.ui.unit.Dp
|
import androidx.compose.ui.unit.Dp
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
import ch.dissem.yaep.domain.Item
|
import ch.dissem.yaep.domain.Item
|
||||||
import ch.dissem.yaep.domain.ItemClass
|
import ch.dissem.yaep.domain.ItemClass
|
||||||
import ch.dissem.yaep.ui.common.theme.emojiFontFamily
|
import ch.dissem.yaep.ui.common.theme.emojiFontFamily
|
||||||
@@ -28,8 +28,7 @@ import kotlin.math.min
|
|||||||
@Composable
|
@Composable
|
||||||
fun <C : ItemClass<C>> Selector(
|
fun <C : ItemClass<C>> Selector(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
spacing: Dp,
|
spacing: Dp = 4.dp,
|
||||||
selectDirectly: Boolean,
|
|
||||||
options: List<Toggleable<Item<C>>>,
|
options: List<Toggleable<Item<C>>>,
|
||||||
onOptionRemoved: (Item<C>) -> Unit,
|
onOptionRemoved: (Item<C>) -> Unit,
|
||||||
onOptionAdded: (Item<C>) -> Unit,
|
onOptionAdded: (Item<C>) -> Unit,
|
||||||
@@ -40,7 +39,7 @@ fun <C : ItemClass<C>> Selector(
|
|||||||
if (selectedItem != null) {
|
if (selectedItem != null) {
|
||||||
DrawItem(
|
DrawItem(
|
||||||
item = selectedItem,
|
item = selectedItem,
|
||||||
modifier = modifier.clickable { onSelectItem(null) },
|
modifier = modifier.onEitherPointerAction { onSelectItem(null) },
|
||||||
spacing = radius
|
spacing = radius
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
@@ -83,8 +82,8 @@ fun <C : ItemClass<C>> Selector(
|
|||||||
@Composable
|
@Composable
|
||||||
fun <C : ItemClass<C>> DrawItem(
|
fun <C : ItemClass<C>> DrawItem(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
spacing: Dp,
|
item: Item<C>,
|
||||||
item: Item<C>
|
spacing: Dp = 4.dp
|
||||||
) {
|
) {
|
||||||
OutlinedCard(modifier = modifier.aspectRatio(1f), shape = RoundedCornerShape(spacing)) {
|
OutlinedCard(modifier = modifier.aspectRatio(1f), shape = RoundedCornerShape(spacing)) {
|
||||||
val emoji = item.symbol
|
val emoji = item.symbol
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
package ch.dissem.yaep.ui.common.theme
|
package ch.dissem.yaep.ui.common.theme
|
||||||
|
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
|
|
||||||
val primaryLight = Color(0xFF6D5E0F)
|
val primaryLight = Color(0xFF6D5E0F)
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package ch.dissem.yaep.ui.common
|
||||||
|
|
||||||
|
import androidx.compose.foundation.border
|
||||||
|
import androidx.compose.foundation.focusable
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.collectAsState
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.focus.focusRequester
|
||||||
|
import androidx.compose.ui.focus.onFocusChanged
|
||||||
|
import androidx.compose.ui.focus.onFocusEvent
|
||||||
|
import androidx.compose.ui.graphics.RectangleShape
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import ch.dissem.yaep.ui.common.focus.FocusFollowingFocusable
|
||||||
|
import ch.dissem.yaep.ui.common.focus.Focusable
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun Modifier.focus(focusable: Focusable<*>): Modifier {
|
||||||
|
var m = this
|
||||||
|
val hasFocus by focusable.hasFocus.collectAsState(false)
|
||||||
|
if (hasFocus) {
|
||||||
|
m = m.border(
|
||||||
|
width = 2.dp,
|
||||||
|
color = MaterialTheme.colorScheme.primary,
|
||||||
|
shape = RectangleShape
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (focusable is FocusFollowingFocusable) {
|
||||||
|
m = m
|
||||||
|
.focusRequester(focusable.focusRequester)
|
||||||
|
.onFocusEvent { state ->
|
||||||
|
focusable.setFocus(state)
|
||||||
|
}
|
||||||
|
.onFocusChanged {}
|
||||||
|
.focusable()
|
||||||
|
}
|
||||||
|
return m
|
||||||
|
}
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
package ch.dissem.yaep.ui.common.focus
|
||||||
|
|
||||||
|
import androidx.compose.ui.input.key.Key
|
||||||
|
import ch.tutteli.atrium.api.fluent.en_GB.toEqual
|
||||||
|
import ch.tutteli.atrium.api.verbs.expect
|
||||||
|
import kotlin.test.Test
|
||||||
|
|
||||||
|
class CluesSelectionManagerTest : SelectionManagerTest<CluesSelectionManager>() {
|
||||||
|
|
||||||
|
var primaryActionCalled: Int? = null
|
||||||
|
var secondaryActionCalled: Int? = null
|
||||||
|
|
||||||
|
lateinit var focusables: MutableList<CluesFocusable>
|
||||||
|
|
||||||
|
override fun setUp() {
|
||||||
|
manager = CluesSelectionManager()
|
||||||
|
|
||||||
|
primaryActionCalled = null
|
||||||
|
secondaryActionCalled = null
|
||||||
|
focusables = mutableListOf()
|
||||||
|
for (i in 0..10) {
|
||||||
|
focusables.add(
|
||||||
|
manager.add(
|
||||||
|
primaryAction = {
|
||||||
|
primaryActionCalled = i
|
||||||
|
},
|
||||||
|
secondaryAction = {
|
||||||
|
secondaryActionCalled = i
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
manager.columns = 3
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun ensure_navigation_right_cycles() {
|
||||||
|
manager.onKeyEvent(keyEvent(Key.DirectionRight))
|
||||||
|
expect(manager.focused).toEqual(focusables[1])
|
||||||
|
|
||||||
|
manager.onKeyEvent(keyEvent(Key.DirectionRight))
|
||||||
|
expect(manager.focused).toEqual(focusables[2])
|
||||||
|
|
||||||
|
manager.onKeyEvent(keyEvent(Key.DirectionRight))
|
||||||
|
expect(manager.focused).toEqual(focusables[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun ensure_navigation_left_cycles() {
|
||||||
|
manager.onKeyEvent(keyEvent(Key.DirectionLeft))
|
||||||
|
expect(manager.focused).toEqual(focusables[2])
|
||||||
|
|
||||||
|
manager.onKeyEvent(keyEvent(Key.DirectionLeft))
|
||||||
|
expect(manager.focused).toEqual(focusables[1])
|
||||||
|
|
||||||
|
manager.onKeyEvent(keyEvent(Key.DirectionLeft))
|
||||||
|
expect(manager.focused).toEqual(focusables[0])
|
||||||
|
|
||||||
|
manager.onKeyEvent(keyEvent(Key.DirectionLeft))
|
||||||
|
expect(manager.focused).toEqual(focusables[2])
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun ensure_navigation_down_cycles() {
|
||||||
|
manager.onKeyEvent(keyEvent(Key.DirectionDown))
|
||||||
|
expect(manager.focused).toEqual(focusables[3])
|
||||||
|
|
||||||
|
manager.onKeyEvent(keyEvent(Key.DirectionDown))
|
||||||
|
expect(manager.focused).toEqual(focusables[6])
|
||||||
|
|
||||||
|
manager.onKeyEvent(keyEvent(Key.DirectionDown))
|
||||||
|
expect(manager.focused).toEqual(focusables[9])
|
||||||
|
|
||||||
|
manager.onKeyEvent(keyEvent(Key.DirectionDown))
|
||||||
|
expect(manager.focused).toEqual(focusables[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun ensure_navigation_up_cycles() {
|
||||||
|
manager.onKeyEvent(keyEvent(Key.DirectionUp))
|
||||||
|
expect(manager.focused).toEqual(focusables[9])
|
||||||
|
|
||||||
|
manager.onKeyEvent(keyEvent(Key.DirectionUp))
|
||||||
|
expect(manager.focused).toEqual(focusables[6])
|
||||||
|
|
||||||
|
manager.onKeyEvent(keyEvent(Key.DirectionUp))
|
||||||
|
expect(manager.focused).toEqual(focusables[3])
|
||||||
|
|
||||||
|
manager.onKeyEvent(keyEvent(Key.DirectionUp))
|
||||||
|
expect(manager.focused).toEqual(focusables[0])
|
||||||
|
|
||||||
|
manager.onKeyEvent(keyEvent(Key.DirectionUp))
|
||||||
|
expect(manager.focused).toEqual(focusables[9])
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
package ch.dissem.yaep.ui.common.focus
|
||||||
|
|
||||||
|
import androidx.compose.ui.input.key.Key
|
||||||
|
import ch.tutteli.atrium.api.fluent.en_GB.toEqual
|
||||||
|
import ch.tutteli.atrium.api.verbs.expect
|
||||||
|
import kotlin.test.Test
|
||||||
|
|
||||||
|
class GridSelectionManagerTest : SelectionManagerTest<GridSelectionManager>() {
|
||||||
|
|
||||||
|
lateinit var focusables: MutableList<GridFocusable>
|
||||||
|
|
||||||
|
override fun setUp() {
|
||||||
|
manager = GridSelectionManager()
|
||||||
|
|
||||||
|
focusables = mutableListOf()
|
||||||
|
repeat(3) {
|
||||||
|
manager.addRow()
|
||||||
|
repeat(3) {
|
||||||
|
focusables.add(
|
||||||
|
manager.add()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun ensure_navigation_right_cycles() {
|
||||||
|
manager.onKeyEvent(keyEvent(Key.DirectionRight))
|
||||||
|
expect(manager.focused).toEqual(focusables[1])
|
||||||
|
|
||||||
|
manager.onKeyEvent(keyEvent(Key.DirectionRight))
|
||||||
|
expect(manager.focused).toEqual(focusables[2])
|
||||||
|
|
||||||
|
manager.onKeyEvent(keyEvent(Key.DirectionRight))
|
||||||
|
expect(manager.focused).toEqual(focusables[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun ensure_navigation_left_cycles() {
|
||||||
|
manager.onKeyEvent(keyEvent(Key.DirectionLeft))
|
||||||
|
expect(manager.focused).toEqual(focusables[2])
|
||||||
|
|
||||||
|
manager.onKeyEvent(keyEvent(Key.DirectionLeft))
|
||||||
|
expect(manager.focused).toEqual(focusables[1])
|
||||||
|
|
||||||
|
manager.onKeyEvent(keyEvent(Key.DirectionLeft))
|
||||||
|
expect(manager.focused).toEqual(focusables[0])
|
||||||
|
|
||||||
|
manager.onKeyEvent(keyEvent(Key.DirectionLeft))
|
||||||
|
expect(manager.focused).toEqual(focusables[2])
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun ensure_navigation_down_cycles() {
|
||||||
|
manager.onKeyEvent(keyEvent(Key.DirectionDown))
|
||||||
|
expect(manager.focused).toEqual(focusables[3])
|
||||||
|
|
||||||
|
manager.onKeyEvent(keyEvent(Key.DirectionDown))
|
||||||
|
expect(manager.focused).toEqual(focusables[6])
|
||||||
|
|
||||||
|
manager.onKeyEvent(keyEvent(Key.DirectionDown))
|
||||||
|
expect(manager.focused).toEqual(focusables[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun ensure_navigation_up_cycles() {
|
||||||
|
manager.onKeyEvent(keyEvent(Key.DirectionUp))
|
||||||
|
expect(manager.focused).toEqual(focusables[6])
|
||||||
|
|
||||||
|
manager.onKeyEvent(keyEvent(Key.DirectionUp))
|
||||||
|
expect(manager.focused).toEqual(focusables[3])
|
||||||
|
|
||||||
|
manager.onKeyEvent(keyEvent(Key.DirectionUp))
|
||||||
|
expect(manager.focused).toEqual(focusables[0])
|
||||||
|
|
||||||
|
manager.onKeyEvent(keyEvent(Key.DirectionUp))
|
||||||
|
expect(manager.focused).toEqual(focusables[6])
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
package ch.dissem.yaep.ui.common.focus
|
||||||
|
|
||||||
|
import androidx.compose.ui.input.key.Key
|
||||||
|
import ch.tutteli.atrium.api.fluent.en_GB.toEqual
|
||||||
|
import ch.tutteli.atrium.api.verbs.expect
|
||||||
|
import kotlin.test.Test
|
||||||
|
|
||||||
|
class LinearSelectionManagerTest : SelectionManagerTest<LinearSelectionManager>() {
|
||||||
|
|
||||||
|
override fun setUp() {
|
||||||
|
manager = LinearSelectionManager(
|
||||||
|
keyNext = Key.A,
|
||||||
|
keyPrevious = Key.B
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun ensure_manager_with_focusables_has_focus_on_first_item() {
|
||||||
|
val focusables = arrayOf(
|
||||||
|
manager.add(),
|
||||||
|
manager.add()
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(manager.focused).toEqual(focusables[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun ensure_keyEvent_A_selects_next() {
|
||||||
|
val focusables = arrayOf(
|
||||||
|
manager.add(),
|
||||||
|
manager.add(),
|
||||||
|
manager.add()
|
||||||
|
)
|
||||||
|
|
||||||
|
manager.onKeyEvent(keyEvent(Key.A))
|
||||||
|
expect(manager.focused).toEqual(focusables[1])
|
||||||
|
|
||||||
|
manager.onKeyEvent(keyEvent(Key.A))
|
||||||
|
expect(manager.focused).toEqual(focusables[2])
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun ensure_keyEvent_B_selects_previous() {
|
||||||
|
val focusables = arrayOf(
|
||||||
|
manager.add(),
|
||||||
|
manager.add(),
|
||||||
|
manager.add()
|
||||||
|
)
|
||||||
|
manager.focused = focusables[2]
|
||||||
|
|
||||||
|
manager.onKeyEvent(keyEvent(Key.B))
|
||||||
|
expect(manager.focused).toEqual(focusables[1])
|
||||||
|
|
||||||
|
manager.onKeyEvent(keyEvent(Key.B))
|
||||||
|
expect(manager.focused).toEqual(focusables[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun ensure_ring_behaviour() {
|
||||||
|
val focusables = arrayOf(
|
||||||
|
manager.add(),
|
||||||
|
manager.add(),
|
||||||
|
manager.add()
|
||||||
|
)
|
||||||
|
|
||||||
|
manager.onKeyEvent(keyEvent(Key.B))
|
||||||
|
expect(manager.focused).toEqual(focusables[2])
|
||||||
|
|
||||||
|
manager.onKeyEvent(keyEvent(Key.A))
|
||||||
|
expect(manager.focused).toEqual(focusables[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package ch.dissem.yaep.ui.common.focus
|
||||||
|
|
||||||
|
import androidx.compose.ui.InternalComposeUiApi
|
||||||
|
import androidx.compose.ui.input.key.Key
|
||||||
|
import androidx.compose.ui.input.key.KeyEvent
|
||||||
|
import androidx.compose.ui.input.key.KeyEventType
|
||||||
|
import kotlin.test.BeforeTest
|
||||||
|
|
||||||
|
abstract class SelectionManagerTest<M : SelectionManager<*>> {
|
||||||
|
lateinit var manager: M
|
||||||
|
|
||||||
|
@BeforeTest
|
||||||
|
abstract fun setUp()
|
||||||
|
|
||||||
|
@OptIn(InternalComposeUiApi::class)
|
||||||
|
fun keyEvent(key: Key, type: KeyEventType = KeyEventType.KeyUp) = KeyEvent(
|
||||||
|
key = key,
|
||||||
|
type = type
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,6 +1,4 @@
|
|||||||
import org.jetbrains.compose.desktop.application.dsl.TargetFormat.Deb
|
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
|
||||||
import org.jetbrains.compose.desktop.application.dsl.TargetFormat.Dmg
|
|
||||||
import org.jetbrains.compose.desktop.application.dsl.TargetFormat.Msi
|
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
alias(libs.plugins.kotlin.kover)
|
alias(libs.plugins.kotlin.kover)
|
||||||
@@ -31,31 +29,18 @@ compose.desktop {
|
|||||||
mainClass = "ch.dissem.yaep.ui.desktop.MainKt"
|
mainClass = "ch.dissem.yaep.ui.desktop.MainKt"
|
||||||
|
|
||||||
nativeDistributions {
|
nativeDistributions {
|
||||||
val formats = mutableListOf(Deb)
|
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
|
||||||
packageName = "YAEP"
|
packageName = "YAEP"
|
||||||
val baseVersion = version.toString()
|
packageVersion = libs.versions.app.version.name.get()
|
||||||
packageVersion = baseVersion
|
|
||||||
if (baseVersion.matches(Regex("[1-9][0-9]*(\\.[0-9]+)(\\.[0-9]+)"))) {
|
|
||||||
formats.add(Dmg)
|
|
||||||
macOS {
|
macOS {
|
||||||
iconFile.set(project.file("icon.icns"))
|
iconFile.set(project.file("icon.icns"))
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (baseVersion.matches(Regex("[1-2]?[0-9]?[0-9]\\.[1-2]?[0-9]?[0-9]\\.[1-6]?[0-9]?[0-9]?[0-9]?[0-9]"))) {
|
|
||||||
windows {
|
windows {
|
||||||
formats.add(Msi)
|
|
||||||
iconFile.set(project.file("icon.ico"))
|
iconFile.set(project.file("icon.ico"))
|
||||||
}
|
}
|
||||||
}
|
|
||||||
linux {
|
linux {
|
||||||
debPackageVersion = if (baseVersion.first().isDigit()) {
|
|
||||||
baseVersion
|
|
||||||
} else {
|
|
||||||
"0-$baseVersion"
|
|
||||||
}
|
|
||||||
iconFile.set(project.file("icon.png"))
|
iconFile.set(project.file("icon.png"))
|
||||||
}
|
}
|
||||||
targetFormats(*formats.toTypedArray())
|
|
||||||
|
|
||||||
buildTypes.release.proguard {
|
buildTypes.release.proguard {
|
||||||
configurationFiles.from(project.file("proguard-rules.pro"))
|
configurationFiles.from(project.file("proguard-rules.pro"))
|
||||||
|
|||||||
@@ -16,10 +16,12 @@ import androidx.compose.material3.Text
|
|||||||
import androidx.compose.material3.TopAppBar
|
import androidx.compose.material3.TopAppBar
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.input.key.onKeyEvent
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.window.WindowPlacement
|
import androidx.compose.ui.window.WindowPlacement
|
||||||
import androidx.compose.ui.window.WindowScope
|
import androidx.compose.ui.window.WindowScope
|
||||||
import androidx.compose.ui.window.WindowState
|
import androidx.compose.ui.window.WindowState
|
||||||
|
import ch.dissem.yaep.ui.common.focus.FocusFollowingSelectionManager
|
||||||
import ch.dissem.yaep.ui.common.theme.AppTheme
|
import ch.dissem.yaep.ui.common.theme.AppTheme
|
||||||
import org.jetbrains.compose.resources.painterResource
|
import org.jetbrains.compose.resources.painterResource
|
||||||
import org.jetbrains.compose.resources.stringResource
|
import org.jetbrains.compose.resources.stringResource
|
||||||
@@ -40,11 +42,13 @@ import yaep.desktop.generated.resources.Res as DRes
|
|||||||
@Composable
|
@Composable
|
||||||
fun WindowScope.DesktopWindow(
|
fun WindowScope.DesktopWindow(
|
||||||
useDarkMode: Boolean,
|
useDarkMode: Boolean,
|
||||||
|
selectionManager: FocusFollowingSelectionManager,
|
||||||
topBar: @Composable () -> Unit,
|
topBar: @Composable () -> Unit,
|
||||||
content: @Composable (PaddingValues) -> Unit
|
content: @Composable (PaddingValues) -> Unit
|
||||||
) {
|
) {
|
||||||
AppTheme(darkTheme = useDarkMode) {
|
AppTheme(darkTheme = useDarkMode) {
|
||||||
Scaffold(
|
Scaffold(
|
||||||
|
modifier = Modifier.onKeyEvent { event -> selectionManager.onKeyEvent(event) },
|
||||||
topBar = {
|
topBar = {
|
||||||
WindowDraggableArea {
|
WindowDraggableArea {
|
||||||
topBar()
|
topBar()
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import androidx.compose.ui.window.application
|
|||||||
import androidx.compose.ui.window.rememberWindowState
|
import androidx.compose.ui.window.rememberWindowState
|
||||||
import ch.dissem.yaep.domain.generateGame
|
import ch.dissem.yaep.domain.generateGame
|
||||||
import ch.dissem.yaep.ui.common.App
|
import ch.dissem.yaep.ui.common.App
|
||||||
|
import ch.dissem.yaep.ui.common.focus.FocusFollowingSelectionManager
|
||||||
import ch.dissem.yaep.ui.common.theme.emojiFontFamily
|
import ch.dissem.yaep.ui.common.theme.emojiFontFamily
|
||||||
import org.jetbrains.compose.resources.painterResource
|
import org.jetbrains.compose.resources.painterResource
|
||||||
import org.jetbrains.compose.resources.stringResource
|
import org.jetbrains.compose.resources.stringResource
|
||||||
@@ -47,10 +48,12 @@ fun main(): Unit = application {
|
|||||||
state = windowState,
|
state = windowState,
|
||||||
icon = painterResource(DRes.drawable.ic_launcher)
|
icon = painterResource(DRes.drawable.ic_launcher)
|
||||||
) {
|
) {
|
||||||
|
val rootSelectionManager = FocusFollowingSelectionManager
|
||||||
var useDarkMode by remember { mutableStateOf(true) }
|
var useDarkMode by remember { mutableStateOf(true) }
|
||||||
var resetCluesBeacon by remember { mutableStateOf(Any()) }
|
var resetCluesBeacon by remember { mutableStateOf(Any()) }
|
||||||
DesktopWindow(
|
DesktopWindow(
|
||||||
useDarkMode = useDarkMode,
|
useDarkMode = useDarkMode,
|
||||||
|
selectionManager = rootSelectionManager,
|
||||||
topBar = {
|
topBar = {
|
||||||
AppBar(
|
AppBar(
|
||||||
useDarkMode = useDarkMode,
|
useDarkMode = useDarkMode,
|
||||||
@@ -67,8 +70,8 @@ fun main(): Unit = application {
|
|||||||
) {
|
) {
|
||||||
App(
|
App(
|
||||||
modifier = Modifier.padding(it),
|
modifier = Modifier.padding(it),
|
||||||
|
rootSelectionManager = rootSelectionManager,
|
||||||
spacing = 8.dp,
|
spacing = 8.dp,
|
||||||
selectDirectly = true,
|
|
||||||
game = game,
|
game = game,
|
||||||
onNewGame = { game = generateGame() },
|
onNewGame = { game = generateGame() },
|
||||||
resetCluesBeacon = resetCluesBeacon
|
resetCluesBeacon = resetCluesBeacon
|
||||||
|
|||||||
@@ -8,7 +8,11 @@ kotlin {
|
|||||||
jvmToolchain(libs.versions.jdk.get().toInt())
|
jvmToolchain(libs.versions.jdk.get().toInt())
|
||||||
|
|
||||||
jvm()
|
jvm()
|
||||||
androidTarget()
|
androidLibrary {
|
||||||
|
namespace = "ch.dissem.yaep.domain"
|
||||||
|
compileSdk = libs.versions.android.compileSdk.get().toInt()
|
||||||
|
minSdk = libs.versions.android.minSdk.get().toInt()
|
||||||
|
}
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
commonMain.dependencies {
|
commonMain.dependencies {
|
||||||
@@ -21,25 +25,3 @@ kotlin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
android {
|
|
||||||
namespace = "ch.dissem.yaep.domain"
|
|
||||||
compileSdk = libs.versions.android.compileSdk.get().toInt()
|
|
||||||
|
|
||||||
defaultConfig {
|
|
||||||
minSdk = libs.versions.android.minSdk.get().toInt()
|
|
||||||
}
|
|
||||||
|
|
||||||
sourceSets {
|
|
||||||
getByName("test") {
|
|
||||||
resources.srcDirs("src/commonTest/resources")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
buildTypes {
|
|
||||||
debug {
|
|
||||||
enableAndroidTestCoverage = true
|
|
||||||
enableUnitTestCoverage = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -14,8 +14,11 @@ class SameColumnClueTest : ClueTest() {
|
|||||||
val a = grid[ia][j]
|
val a = grid[ia][j]
|
||||||
val b = grid[ib][j]
|
val b = grid[ib][j]
|
||||||
|
|
||||||
expect(SameColumnClue(a.solution!!, b.solution!!).isValid(grid)).toEqual(true)
|
a.solution!!
|
||||||
expect(SameColumnClue(b.solution!!, a.solution!!).isValid(grid)).toEqual(true)
|
b.solution!!
|
||||||
|
|
||||||
|
expect(SameColumnClue(a.solution, b.solution).isValid(grid)).toEqual(true)
|
||||||
|
expect(SameColumnClue(b.solution, a.solution).isValid(grid)).toEqual(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -32,8 +35,11 @@ class SameColumnClueTest : ClueTest() {
|
|||||||
val a = grid[ia][ja]
|
val a = grid[ia][ja]
|
||||||
val b = grid[ib][jb]
|
val b = grid[ib][jb]
|
||||||
|
|
||||||
expect(SameColumnClue(a.solution!!, b.solution!!).isValid(grid)).toEqual(false)
|
a.solution!!
|
||||||
expect(SameColumnClue(b.solution!!, a.solution!!).isValid(grid)).toEqual(false)
|
b.solution!!
|
||||||
|
|
||||||
|
expect(SameColumnClue(a.solution, b.solution).isValid(grid)).toEqual(false)
|
||||||
|
expect(SameColumnClue(b.solution, a.solution).isValid(grid)).toEqual(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -51,11 +57,14 @@ class SameColumnClueTest : ClueTest() {
|
|||||||
val a = grid[ia][ja]
|
val a = grid[ia][ja]
|
||||||
val b = grid[ib][jb]
|
val b = grid[ib][jb]
|
||||||
|
|
||||||
|
a.solution!!
|
||||||
|
b.solution!!
|
||||||
|
|
||||||
a.selection = a.solution
|
a.selection = a.solution
|
||||||
b.selection = b.solution
|
b.selection = b.solution
|
||||||
|
|
||||||
expect(SameColumnClue(a.solution!!, b.solution!!).isValid(grid)).toEqual(false)
|
expect(SameColumnClue(a.solution, b.solution).isValid(grid)).toEqual(false)
|
||||||
expect(SameColumnClue(b.solution!!, a.solution!!).isValid(grid)).toEqual(false)
|
expect(SameColumnClue(b.solution, a.solution).isValid(grid)).toEqual(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -72,6 +81,10 @@ class SameColumnClueTest : ClueTest() {
|
|||||||
for (i in 0 until size) {
|
for (i in 0 until size) {
|
||||||
val a = rowA[i]
|
val a = rowA[i]
|
||||||
val b = rowB[i]
|
val b = rowB[i]
|
||||||
|
|
||||||
|
a.solution!!
|
||||||
|
b.solution!!
|
||||||
|
|
||||||
rowA.forEachIndexed { index, gameCell ->
|
rowA.forEachIndexed { index, gameCell ->
|
||||||
if (index < i) {
|
if (index < i) {
|
||||||
gameCell.selection = rowA.options.filter { it != a.solution }.random()
|
gameCell.selection = rowA.options.filter { it != a.solution }.random()
|
||||||
@@ -87,8 +100,8 @@ class SameColumnClueTest : ClueTest() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(SameColumnClue(a.solution!!, b.solution!!).isValid(grid)).toEqual(false)
|
expect(SameColumnClue(a.solution, b.solution).isValid(grid)).toEqual(false)
|
||||||
expect(SameColumnClue(b.solution!!, a.solution!!).isValid(grid)).toEqual(false)
|
expect(SameColumnClue(b.solution, a.solution).isValid(grid)).toEqual(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,8 +17,12 @@ class TripletClueTest : ClueTest() {
|
|||||||
val b = grid[ib][j - 1]
|
val b = grid[ib][j - 1]
|
||||||
val c = grid[ic][j]
|
val c = grid[ic][j]
|
||||||
|
|
||||||
expect(TripletClue(a.solution!!, b.solution!!, c.solution!!).isValid(grid)).toEqual(true)
|
a.solution!!
|
||||||
expect(TripletClue(c.solution!!, b.solution!!, a.solution!!).isValid(grid)).toEqual(true)
|
b.solution!!
|
||||||
|
c.solution!!
|
||||||
|
|
||||||
|
expect(TripletClue(a.solution, b.solution, c.solution).isValid(grid)).toEqual(true)
|
||||||
|
expect(TripletClue(c.solution, b.solution, a.solution).isValid(grid)).toEqual(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -36,16 +40,20 @@ class TripletClueTest : ClueTest() {
|
|||||||
val b = rowB[2]
|
val b = rowB[2]
|
||||||
val c = rowC[3]
|
val c = rowC[3]
|
||||||
|
|
||||||
|
a.solution!!
|
||||||
|
b.solution!!
|
||||||
|
c.solution!!
|
||||||
|
|
||||||
rowB[0].selection = b.solution
|
rowB[0].selection = b.solution
|
||||||
|
|
||||||
expect(TripletClue(a.solution!!, b.solution!!, c.solution!!).isValid(grid)).toEqual(false)
|
expect(TripletClue(a.solution, b.solution, c.solution).isValid(grid)).toEqual(false)
|
||||||
expect(TripletClue(c.solution!!, b.solution!!, a.solution!!).isValid(grid)).toEqual(false)
|
expect(TripletClue(c.solution, b.solution, a.solution).isValid(grid)).toEqual(false)
|
||||||
|
|
||||||
rowB[0].selection = null
|
rowB[0].selection = null
|
||||||
rowB[grid.size - 1].selection = b.solution
|
rowB[grid.size - 1].selection = b.solution
|
||||||
|
|
||||||
expect(TripletClue(a.solution!!, b.solution!!, c.solution!!).isValid(grid)).toEqual(false)
|
expect(TripletClue(a.solution, b.solution, c.solution).isValid(grid)).toEqual(false)
|
||||||
expect(TripletClue(c.solution!!, b.solution!!, a.solution!!).isValid(grid)).toEqual(false)
|
expect(TripletClue(c.solution, b.solution, a.solution).isValid(grid)).toEqual(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -61,10 +69,14 @@ class TripletClueTest : ClueTest() {
|
|||||||
val rowC = grid[1]
|
val rowC = grid[1]
|
||||||
val c = rowC[ic]
|
val c = rowC[ic]
|
||||||
|
|
||||||
val clue = TripletClue(a.solution!!, b.solution!!, c.solution!!)
|
a.solution!!
|
||||||
|
b.solution!!
|
||||||
|
c.solution!!
|
||||||
|
|
||||||
|
val clue = TripletClue(a.solution, b.solution, c.solution)
|
||||||
|
|
||||||
b.selection = b.solution
|
b.selection = b.solution
|
||||||
c.options.add(c.solution!!)
|
c.options.add(c.solution)
|
||||||
|
|
||||||
|
|
||||||
rowA.forEachIndexed { index, notA ->
|
rowA.forEachIndexed { index, notA ->
|
||||||
@@ -75,7 +87,7 @@ class TripletClueTest : ClueTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
index == ic -> {
|
index == ic -> {
|
||||||
rowC[ia].options.add(c.solution!!)
|
rowC[ia].options.add(c.solution)
|
||||||
expect(clue.isValid(grid)).toEqual(true)
|
expect(clue.isValid(grid)).toEqual(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,11 +106,15 @@ class TripletClueTest : ClueTest() {
|
|||||||
val b = grid[0][2]
|
val b = grid[0][2]
|
||||||
val c = grid[1][3]
|
val c = grid[1][3]
|
||||||
|
|
||||||
|
a.solution!!
|
||||||
|
b.solution!!
|
||||||
|
c.solution!!
|
||||||
|
|
||||||
a.selection = a.solution
|
a.selection = a.solution
|
||||||
grid[1][4].selection = c.solution
|
grid[1][4].selection = c.solution
|
||||||
|
|
||||||
expect(TripletClue(a.solution!!, b.solution!!, c.solution!!).isValid(grid)).toEqual(false)
|
expect(TripletClue(a.solution, b.solution, c.solution).isValid(grid)).toEqual(false)
|
||||||
expect(TripletClue(c.solution!!, b.solution!!, a.solution!!).isValid(grid)).toEqual(false)
|
expect(TripletClue(c.solution, b.solution, a.solution).isValid(grid)).toEqual(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -111,15 +127,19 @@ class TripletClueTest : ClueTest() {
|
|||||||
val b = rowB[2]
|
val b = rowB[2]
|
||||||
val c = rowC[1]
|
val c = rowC[1]
|
||||||
|
|
||||||
|
a.solution!!
|
||||||
|
b.solution!!
|
||||||
|
c.solution!!
|
||||||
|
|
||||||
a.selection = a.solution
|
a.selection = a.solution
|
||||||
b.options.clear()
|
b.options.clear()
|
||||||
c.options.clear()
|
c.options.clear()
|
||||||
|
|
||||||
rowB[4].options.add(b.solution!!)
|
rowB[4].options.add(b.solution)
|
||||||
rowC[5].options.add(c.solution!!)
|
rowC[5].options.add(c.solution)
|
||||||
|
|
||||||
expect(TripletClue(a.solution!!, b.solution!!, c.solution!!).isValid(grid)).toEqual(true)
|
expect(TripletClue(a.solution, b.solution, c.solution).isValid(grid)).toEqual(true)
|
||||||
expect(TripletClue(c.solution!!, b.solution!!, a.solution!!).isValid(grid)).toEqual(true)
|
expect(TripletClue(c.solution, b.solution, a.solution).isValid(grid)).toEqual(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -132,11 +152,15 @@ class TripletClueTest : ClueTest() {
|
|||||||
val b = rowB[2]
|
val b = rowB[2]
|
||||||
val c = rowC[1]
|
val c = rowC[1]
|
||||||
|
|
||||||
|
a.solution!!
|
||||||
|
b.solution!!
|
||||||
|
c.solution!!
|
||||||
|
|
||||||
a.selection = a.solution
|
a.selection = a.solution
|
||||||
rowB[4].selection = rowC[3].solution
|
rowB[4].selection = rowC[3].solution
|
||||||
c.selection = rowC[3].solution
|
c.selection = rowC[3].solution
|
||||||
|
|
||||||
expect(TripletClue(a.solution!!, b.solution!!, c.solution!!).isValid(grid)).toEqual(false)
|
expect(TripletClue(a.solution, b.solution, c.solution).isValid(grid)).toEqual(false)
|
||||||
expect(TripletClue(c.solution!!, b.solution!!, a.solution!!).isValid(grid)).toEqual(false)
|
expect(TripletClue(c.solution, b.solution, a.solution).isValid(grid)).toEqual(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,7 +81,7 @@
|
|||||||
<url type="vcs-browser">https://git.dissem.ch/chris/YAEP</url>
|
<url type="vcs-browser">https://git.dissem.ch/chris/YAEP</url>
|
||||||
|
|
||||||
<releases>
|
<releases>
|
||||||
<release date="2025-11-29" version="0.0.0">
|
<release date="2025-11-29" version="1.0.0">
|
||||||
<description>
|
<description>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Initial release</li>
|
<li>Initial release</li>
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
[versions]
|
[versions]
|
||||||
app-version-code = "1"
|
app-version-code = "1"
|
||||||
app-version-name = "1.0.0"
|
app-version-name = "1.0.0"
|
||||||
agp = "8.13.0"
|
agp = "8.13.2"
|
||||||
jdk = "21"
|
jdk = "21"
|
||||||
android-compileSdk = "36"
|
android-compileSdk = "36"
|
||||||
android-minSdk = "26"
|
android-minSdk = "26"
|
||||||
android-targetSdk = "36"
|
android-targetSdk = "36"
|
||||||
androidx-activityCompose = "1.11.0"
|
androidx-activityCompose = "1.12.2"
|
||||||
androidx-compose = "1.9.4"
|
androidx-compose = "1.10.0"
|
||||||
compose-plugin = "1.9.2"
|
compose-plugin = "1.9.3"
|
||||||
kotlin = "2.2.21"
|
kotlin = "2.3.0"
|
||||||
coreKtx = "1.17.0"
|
coreKtx = "1.17.0"
|
||||||
atrium = "1.2.0"
|
atrium = "1.2.0"
|
||||||
|
|
||||||
@@ -19,28 +19,25 @@ androidx-core-ktx = { module = "androidx.core:core-ktx", version.ref = "coreKtx"
|
|||||||
androidx-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "androidx-compose" }
|
androidx-tooling = { module = "androidx.compose.ui:ui-tooling", version.ref = "androidx-compose" }
|
||||||
androidx-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview", version.ref = "androidx-compose" }
|
androidx-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview", version.ref = "androidx-compose" }
|
||||||
androidx-compose-foundation = { module = "androidx.compose.foundation:foundation", version.ref = "androidx-compose" }
|
androidx-compose-foundation = { module = "androidx.compose.foundation:foundation", version.ref = "androidx-compose" }
|
||||||
androidx-compose-ui-test-manifest = { module = "androidx.compose.ui:ui-test-manifest", version.ref = "androidx-compose" }
|
|
||||||
androidx-compose-ui-test-android = { module = "androidx.compose.ui:ui-test-junit4-android", version.ref = "androidx-compose" }
|
|
||||||
|
|
||||||
atrium = { module = "ch.tutteli.atrium:atrium-fluent", version.ref = "atrium" }
|
atrium = { module = "ch.tutteli.atrium:atrium-fluent", version.ref = "atrium" }
|
||||||
|
|
||||||
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
|
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
|
||||||
|
|
||||||
logging-jvm = { module = "io.github.oshai:kotlin-logging-jvm", version = "7.0.13" }
|
logging-jvm = { module = "io.github.oshai:kotlin-logging-jvm", version = "7.0.14" }
|
||||||
logging-slf4j = { module = "org.slf4j:slf4j-simple", version = "2.0.17" }
|
logging-slf4j = { module = "org.slf4j:slf4j-simple", version = "2.0.17" }
|
||||||
|
|
||||||
[bundles]
|
[bundles]
|
||||||
logging = ["logging-jvm", "logging-slf4j"]
|
logging = ["logging-jvm", "logging-slf4j"]
|
||||||
|
|
||||||
[plugins]
|
[plugins]
|
||||||
versioning = { id = "me.qoomon.git-versioning", version = "6.4.4"}
|
|
||||||
versions = { id = "com.github.ben-manes.versions", version = "0.53.0" }
|
versions = { id = "com.github.ben-manes.versions", version = "0.53.0" }
|
||||||
android-application = { id = "com.android.application", version.ref = "agp" }
|
android-application = { id = "com.android.application", version.ref = "agp" }
|
||||||
android-library = { id = "com.android.library", version.ref = "agp" }
|
android-library = { id = "com.android.kotlin.multiplatform.library", version.ref = "agp" }
|
||||||
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
|
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
|
||||||
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
|
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
|
||||||
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
|
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
|
||||||
compose = { id = "org.jetbrains.compose", version.ref = "compose-plugin" }
|
compose = { id = "org.jetbrains.compose", version.ref = "compose-plugin" }
|
||||||
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
|
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
|
||||||
sonarqube = { id = "org.sonarqube", version = "7.0.1.6134" }
|
sonarqube = { id = "org.sonarqube", version = "7.2.2.6593" }
|
||||||
kotlin-kover = { id = "org.jetbrains.kotlinx.kover", version = "0.9.3" }
|
kotlin-kover = { id = "org.jetbrains.kotlinx.kover", version = "0.9.4" }
|
||||||
Reference in New Issue
Block a user