Skip to content

Commit 79128cb

Browse files
authored
Merge pull request #1 from Konyaco/theme
Support light theme
2 parents 56885c8 + 53d596c commit 79128cb

File tree

14 files changed

+587
-349
lines changed

14 files changed

+587
-349
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Now supported:
1717

1818
- Coarse implementation of some basic components: `Button`, `Switcher`, `TextField`, `Slider`...
1919
- A fake `Mica` and `Layer`
20-
- Only dark theme
20+
- Dark theme and light theme
2121

2222
There are lots of hard-code and workaround in our source code, we are going to eliminate them in the future
2323

@@ -60,7 +60,9 @@ The copyright to the icon assets (in `/resources/icon/`) belongs to Microsoft.
6060
- [x] Text Field
6161
- [x] Part of Animation
6262
- M2
63-
- [ ] Theme (Light and Dark, custom Accent color)
63+
- [ ] Theme
64+
- [x] Light and Dark theme
65+
- [ ] Custom Accent color
6466
- [ ] Animation
6567
- [ ] Refactor architecture, cleanup code, eliminate hard-code
6668
- [ ] More

assets/screenshot.png

-2.33 KB
Loading

src/jvmMain/kotlin/Main.kt

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import androidx.compose.foundation.shape.RoundedCornerShape
44
import androidx.compose.runtime.*
55
import androidx.compose.ui.Alignment
66
import androidx.compose.ui.Modifier
7-
import androidx.compose.ui.graphics.Color
87
import androidx.compose.ui.platform.LocalDensity
98
import androidx.compose.ui.text.input.TextFieldValue
109
import androidx.compose.ui.unit.Density
@@ -16,9 +15,9 @@ import androidx.compose.ui.window.rememberWindowState
1615
import com.konyaco.fluent.FluentTheme
1716
import com.konyaco.fluent.background.Layer
1817
import com.konyaco.fluent.background.Mica
19-
import com.konyaco.fluent.color.Colors
2018
import com.konyaco.fluent.component.*
2119
import com.konyaco.fluent.darkColors
20+
import com.konyaco.fluent.lightColors
2221

2322
fun main() = application {
2423
Window(
@@ -32,7 +31,10 @@ fun main() = application {
3231

3332
@Composable
3433
private fun App() {
35-
FluentTheme(colors = darkColors()) {
34+
val systemDarkMode = isSystemInDarkTheme()
35+
var darkMode by remember(systemDarkMode) { mutableStateOf(systemDarkMode) }
36+
37+
FluentTheme(colors = if (darkMode) darkColors() else lightColors()) {
3638
Mica(Modifier.fillMaxSize().verticalScroll(rememberScrollState()).horizontalScroll(rememberScrollState())) {
3739
val density = LocalDensity.current
3840
var scale by remember { mutableStateOf(density.density) }
@@ -41,14 +43,17 @@ private fun App() {
4143
modifier = Modifier.padding(start = 32.dp, top = 16.dp, end = 16.dp, bottom = 16.dp)
4244
.defaultMinSize(minWidth = 600.dp),
4345
shape = RoundedCornerShape(8.dp),
44-
border = BorderStroke(1.dp, Colors.Stroke.Control.Default),
46+
border = BorderStroke(1.dp, FluentTheme.colors.stroke.control.default),
4547
cornerRadius = 8.dp
4648
) {
4749
Column(Modifier.padding(16.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {
48-
Row(verticalAlignment = Alignment.CenterVertically) {
50+
Row(
51+
verticalAlignment = Alignment.CenterVertically,
52+
horizontalArrangement = Arrangement.spacedBy(8.dp)
53+
) {
4954
Text("Scale: %.2f".format(scale))
50-
Spacer(Modifier.width(8.dp))
5155
Button(onClick = { scale = density.density }) { Text("Reset") }
56+
Switcher(darkMode, text = "Dark Mode", onCheckStateChange = { darkMode = it })
5257
}
5358
Slider(
5459
modifier = Modifier.width(200.dp),
@@ -99,17 +104,17 @@ private fun App() {
99104
modifier = Modifier.size(32.dp),
100105
shape = RoundedCornerShape(4.dp),
101106
cornerRadius = 4.dp,
102-
color = Colors.Fill.Accent.Default,
103-
border = BorderStroke(1.dp, Colors.Stroke.Control.Default),
107+
color = FluentTheme.colors.fillAccent.default,
108+
border = BorderStroke(1.dp, FluentTheme.colors.stroke.control.default),
104109
content = {},
105110
outsideBorder = false
106111
)
107112
Layer(
108113
modifier = Modifier.size(32.dp),
109114
shape = RoundedCornerShape(4.dp),
110115
cornerRadius = 4.dp,
111-
color = Colors.Fill.Accent.Default,
112-
border = BorderStroke(1.dp, Colors.Stroke.Control.Default),
116+
color = FluentTheme.colors.fillAccent.default,
117+
border = BorderStroke(1.dp, FluentTheme.colors.stroke.control.default),
113118
content = {},
114119
outsideBorder = true
115120
)

0 commit comments

Comments
 (0)