Skip to content

Commit

Permalink
Improve user experience.
Browse files Browse the repository at this point in the history
  • Loading branch information
sgpublic committed Mar 11, 2022
1 parent 59ebf66 commit 588d4ce
Show file tree
Hide file tree
Showing 6 changed files with 400 additions and 272 deletions.
7 changes: 7 additions & 0 deletions .idea/runConfigurations/build.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 20 additions & 7 deletions .idea/runConfigurations/run.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group = "io.github.sgpublic"
version = "1.0.1"
version = "1.1.0"

repositories {
google()
Expand All @@ -34,11 +34,11 @@ tasks.withType<KotlinCompile> {

compose.desktop {
application {
mainClass = "MainKt"
mainClass = "io.github.sgpublic.MainKt"
nativeDistributions {
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
packageName = "SingleChipDigitalTube"
packageVersion = "1.0.1"
packageVersion = "1.1.0"
}
}
}
9 changes: 7 additions & 2 deletions src/main/kotlin/io/github/sgpublic/Main.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package io.github.sgpublic

import androidx.compose.material.MaterialTheme
import androidx.compose.ui.Alignment
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
Expand All @@ -15,15 +18,17 @@ fun main() {
application {
Window(
onCloseRequest = ::exitApplication,
title = "KED 数码管生成器 by 忆丶距",
title = "LED 数码管生成器 by 忆丶距 V1.1.0",
resizable = false,
state = rememberWindowState(
size = DpSize(860.dp, 470.dp),
// 设置初始位置为屏幕正中
position = WindowPosition.Aligned(Alignment.Center)
)
) {
App.Compose()
MaterialTheme {
App.Compose()
}
}
}
}
73 changes: 17 additions & 56 deletions src/main/kotlin/io/github/sgpublic/compose/DropDownList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,61 +26,23 @@ import androidx.compose.ui.unit.dp
fun DropDownList(
title: String,
selected: Int,
size: Int = 8,
expanded: Boolean = false,
request: (Boolean) -> Unit,
modifier: Modifier = Modifier,
onSelect: (Int) -> Unit = { }
) {
Row(
modifier = Modifier.wrapContentHeight()
.width(120.dp).padding(0.dp, 4.dp),
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = title,
modifier = Modifier.width(24.dp)
)
Box(
modifier = Modifier.wrapContentSize()
) {
Column {
Card(
elevation = 4.dp,
shape = RoundedCornerShape(8.dp),
modifier = Modifier.size(80.dp, 28.dp)
) {
Row(
modifier = Modifier.padding(14.dp, 0.dp)
) {
Text(
text = "$selected",
modifier = Modifier.align(Alignment.CenterVertically)
)
}
}
DropdownMenu(
expanded = expanded,
onDismissRequest = { request(false) },
modifier = Modifier.width(140.dp)
) {
for (i in 0 until 8) {
DropdownMenuItem(
onClick = {
request(false)
onSelect(i)
}
) {
Text("$i")
}
}
}
}
Spacer(
modifier = Modifier.matchParentSize()
.background(Color.Transparent)
.clickable { request(true) }
)
}
}
DropDownList(
title = title,
selected = selected.toString(),
expanded = expanded,
request = request,
modifier = modifier,
list = mutableListOf<String>().also {
for (i in 0 until size) it.add(i.toString())
},
onSelect = { onSelect(it.toInt()) }
)
}

/**
Expand All @@ -104,13 +66,11 @@ fun DropDownList(
onSelect: (String) -> Unit = { }
) {
Row(
modifier = modifier.wrapContentSize()
.padding(0.dp, 4.dp),
verticalAlignment = Alignment.CenterVertically,
) {
Text(
text = title,
modifier = Modifier.width(100.dp)
modifier = modifier
)
Box(
modifier = Modifier.wrapContentSize()
Expand All @@ -132,14 +92,15 @@ fun DropDownList(
}
DropdownMenu(
expanded = expanded,
onDismissRequest = { request(false) }
onDismissRequest = { request(false) },
) {
for (i in list) {
DropdownMenuItem(
onClick = {
request(false)
onSelect(i)
}
},
modifier = Modifier.height(40.dp)
) {
Text(i)
}
Expand Down
Loading

0 comments on commit 588d4ce

Please sign in to comment.