Skip to content

Commit

Permalink
add example
Browse files Browse the repository at this point in the history
  • Loading branch information
X1nto committed Aug 25, 2022
1 parent f5a48bf commit 7e59136
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
35 changes: 35 additions & 0 deletions example/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import org.jetbrains.compose.compose
import org.jetbrains.compose.desktop.application.dsl.TargetFormat

plugins {
kotlin("multiplatform")
id("org.jetbrains.compose")
}

kotlin {
jvm {
compilations.all {
kotlinOptions.jvmTarget = "11"
}
withJava()
}
sourceSets {
named("jvmMain") {
dependencies {
implementation(project(":lib"))
implementation(compose.desktop.currentOs)
}
}
}
}

compose.desktop {
application {
mainClass = "MainKt"
nativeDistributions {
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
packageName = "com.kotrols.fluent.demo"
packageVersion = "1.0.0"
}
}
}
45 changes: 45 additions & 0 deletions example/src/jvmMain/kotlin/Main.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.application

@Composable
fun App(
isDark: Boolean,
requestThemeChange: () -> Unit,
) {
FluentExampleTheme(isDark = isDark) {
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.spacedBy(4.dp, Alignment.CenterVertically),
horizontalAlignment = Alignment.CenterHorizontally
) {
ToggleButton(
toggled = isDark,
onToggle = { requestThemeChange() }
) {
Text("Theme: ${if (isDark) "Dark" else "Light"}")
}
}
}
}

fun main() = application {
var isDark by remember { mutableStateOf(false) }
MicaWindow(
onCloseRequest = ::exitApplication,
isDark = isDark,
title = "Compose Window",
) {
App(
isDark = isDark,
requestThemeChange = {
isDark = !isDark
}
)
}
}
26 changes: 26 additions & 0 deletions example/src/jvmMain/kotlin/Theme.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import androidx.compose.runtime.Composable

@Composable
fun FluentExampleTheme(
isDark: Boolean = false,
content: @Composable () -> Unit
) {
val colorScheme = when (isDark) {
true -> darkColorScheme()
false -> lightColorScheme()
}
val borderElevation = when (isDark) {
true -> darkBorderElevation()
false -> lightBorderElevation()
}
val shadowElevation = when (isDark) {
true -> darkShadowElevation()
false -> lightShadowElevation()
}
FluentTheme(
colorScheme = colorScheme,
borderElevation = borderElevation,
shadowElevation = shadowElevation,
content = content
)
}

0 comments on commit 7e59136

Please sign in to comment.