This commit is contained in:
NianChen
2023-04-13 18:06:05 +08:00
commit e5873ae6fe
4063 changed files with 267552 additions and 0 deletions

66
common/build.gradle.kts Normal file
View File

@ -0,0 +1,66 @@
import org.jetbrains.compose.compose
plugins {
kotlin("multiplatform")
id("org.jetbrains.compose")
id("com.android.library")
}
group = "com.eim"
version = "1.0-SNAPSHOT"
kotlin {
android()
jvm("desktop") {
compilations.all {
kotlinOptions.jvmTarget = "11"
}
}
sourceSets {
val commonMain by getting {
dependencies {
api(compose.runtime)
api(compose.foundation)
api(compose.material)
api(project(":fluent"))
api("org.jetbrains.kotlin:kotlin-reflect")
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
val androidMain by getting {
dependencies {
api("androidx.appcompat:appcompat:1.2.0")
api("androidx.core:core-ktx:1.3.1")
}
}
val androidTest by getting {
dependencies {
implementation("junit:junit:4.13")
}
}
val desktopMain by getting {
dependencies {
api(compose.preview)
}
}
val desktopTest by getting
}
}
android {
compileSdkVersion(31)
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
defaultConfig {
minSdkVersion(24)
targetSdkVersion(31)
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}

View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.eim.common"/>

View File

@ -0,0 +1,5 @@
package com.eim.common
actual fun getPlatformName(): String {
return "Android"
}

View File

@ -0,0 +1,208 @@
package com.eim.common
import androidx.compose.foundation.*
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.dp
import com.konyaco.fluent.FluentTheme
import com.konyaco.fluent.LocalContentColor
import com.konyaco.fluent.background.Layer
import com.konyaco.fluent.background.Mica
import com.konyaco.fluent.component.*
import com.konyaco.fluent.darkColors
import com.konyaco.fluent.lightColors
import com.konyaco.fluent.icons.Icons
import com.konyaco.fluent.icons.regular.*
@Composable
fun App() {
var displayDialog by remember { mutableStateOf(false) }
var expanded by remember { mutableStateOf(false) }
// Layer(Modifier.fillMaxSize().verticalScroll(rememberScrollState())
// .horizontalScroll(rememberScrollState())
// ) {
Layer(
modifier = Modifier.verticalScroll(rememberScrollState())
.horizontalScroll(rememberScrollState()).padding(start = 32.dp, top = 16.dp, end = 16.dp, bottom = 16.dp)
.defaultMinSize(minWidth = 600.dp),
shape = RoundedCornerShape(4.dp),
cornerRadius = 4.dp
) {
Column(Modifier.padding(16.dp), Arrangement.spacedBy(8.dp)) {
Content()
AccentButton(onClick = {
displayDialog = true
}) { Text("Display Dialog") }
Box {
Button(onClick = {
expanded = true
}) {
Text("Show DropdownMenu")
}
DropdownMenu(expanded, {expanded = false}) {
DropdownMenuItem({expanded = false}) { Text("Option 1")}
DropdownMenuItem({expanded = false}) { Text("Option 2")}
DropdownMenuItem({expanded = false}) { Text("Option 3")}
}
}
}
Dialog(
title = "This is a example dialog",
visible = displayDialog,
cancelButtonText = "Cancel",
confirmButtonText = "Confirm",
onCancel = {
displayDialog = false
},
onConfirm = {
displayDialog = false
}
)
}
// }
}
@Composable
private fun Content() {
var sliderValue by remember { mutableStateOf(0.5f) }
Slider(
modifier = Modifier.width(200.dp),
value = sliderValue,
onValueChange = { sliderValue = it },
)
Buttons()
Controls()
Row {
Layer(
modifier = Modifier.size(32.dp),
shape = RoundedCornerShape(4.dp),
cornerRadius = 4.dp,
color = FluentTheme.colors.fillAccent.default,
border = BorderStroke(1.dp, FluentTheme.colors.stroke.control.default),
content = {},
outsideBorder = false
)
Layer(
modifier = Modifier.size(32.dp),
shape = RoundedCornerShape(4.dp),
cornerRadius = 4.dp,
color = FluentTheme.colors.fillAccent.default,
border = BorderStroke(1.dp, FluentTheme.colors.stroke.control.default),
content = {},
outsideBorder = true
)
}
var value by remember { mutableStateOf(TextFieldValue("Hello Fluent!")) }
TextField(value, onValueChange = { value = it })
TextField(
value = value, onValueChange = { value = it }, enabled = false,
header = { Text("With Header") }
)
// ProgressRings
Row(
horizontalArrangement = Arrangement.spacedBy(32.dp),
verticalAlignment = Alignment.CenterVertically
) {
ProgressRing(size = ProgressRingSize.Medium)
ProgressRing(progress = sliderValue)
AccentButton(onClick = {}) {
ProgressRing(size = ProgressRingSize.Small, color = LocalContentColor.current)
Text("Small")
}
}
ProgressBar(sliderValue)
ProgressBar()
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
for (imageVector in icons) {
Icon(
modifier = Modifier.size(18.dp),
imageVector = imageVector, contentDescription = null
)
}
}
}
@Composable
private fun Controls() {
var checked by remember { mutableStateOf(false) }
Switcher(checked, text = null, onCheckStateChange = { checked = it })
var checked2 by remember { mutableStateOf(true) }
Switcher(checked2, text = "With Label", onCheckStateChange = { checked2 = it })
var checked3 by remember { mutableStateOf(true) }
Switcher(
checked3,
text = "Before Label",
textBefore = true,
onCheckStateChange = { checked3 = it }
)
var checked4 by remember { mutableStateOf(false) }
CheckBox(checked4) { checked4 = it }
var checked5 by remember { mutableStateOf(true) }
CheckBox(checked5, label = "With Label") { checked5 = it }
var selectedRadio by remember { mutableStateOf(0) }
RadioButton(selectedRadio == 0, onClick = { selectedRadio = 0 })
RadioButton(selectedRadio == 1, onClick = { selectedRadio = 1 }, label = "With Label")
}
@Composable
private fun Buttons() {
var text by remember { mutableStateOf("Hello World") }
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
val onClick = { text = "Hello, Fluent Design!" }
Button(onClick) { Text(text) }
AccentButton(onClick) {
Icon(Icons.Default.Checkmark, contentDescription = null)
Text(text)
}
SubtleButton(onClick) {
Text("Text Button")
}
}
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
AccentButton({}, iconOnly = true) {
Icon(Icons.Default.Navigation, contentDescription = null)
}
Button({}, iconOnly = true) {
Icon(Icons.Default.Navigation, contentDescription = null)
}
SubtleButton({}, iconOnly = true) {
Icon(Icons.Default.Navigation, contentDescription = null)
}
}
}
private val icons = arrayOf(
Icons.Default.Add,
Icons.Default.Delete,
Icons.Default.Dismiss,
Icons.Default.ArrowLeft,
Icons.Default.Navigation,
Icons.Default.List
)

View File

@ -0,0 +1,3 @@
package com.eim.common
expect fun getPlatformName(): String

View File

@ -0,0 +1,11 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.eim.common
import androidx.compose.desktop.ui.tooling.preview.Preview
import androidx.compose.runtime.Composable
@Preview
@Composable
fun AppPreview() {
App()
}

View File

@ -0,0 +1,5 @@
package com.eim.common
actual fun getPlatformName(): String {
return "Desktop"
}