diff --git a/core/src/main/kotlin/org/jetbrains/jewel/IntelliJTheme.kt b/core/src/main/kotlin/org/jetbrains/jewel/IntelliJTheme.kt index 31717896a7..697947ecb5 100644 --- a/core/src/main/kotlin/org/jetbrains/jewel/IntelliJTheme.kt +++ b/core/src/main/kotlin/org/jetbrains/jewel/IntelliJTheme.kt @@ -262,7 +262,7 @@ val LocalIconData = staticCompositionLocalOf { */ @Composable fun onBackground(color: Color, content: @Composable () -> Unit) { - val locals = if (color.isSpecified) { + val locals = if (color.isSpecified && color.alpha > 0) { arrayOf(LocalOnDarkBackground provides color.isDark()) } else { emptyArray() diff --git a/samples/standalone/src/main/kotlin/org/jetbrains/jewel/samples/standalone/IntUiThemes.kt b/samples/standalone/src/main/kotlin/org/jetbrains/jewel/samples/standalone/IntUiThemes.kt new file mode 100644 index 0000000000..651f0393a5 --- /dev/null +++ b/samples/standalone/src/main/kotlin/org/jetbrains/jewel/samples/standalone/IntUiThemes.kt @@ -0,0 +1,9 @@ +package org.jetbrains.jewel.samples.standalone + +enum class IntUiThemes { + Light, LightWithLightHeader, Dark; + + fun isDark() = this == Dark + + fun isLightHeader() = this == LightWithLightHeader +} diff --git a/samples/standalone/src/main/kotlin/org/jetbrains/jewel/samples/standalone/Main.kt b/samples/standalone/src/main/kotlin/org/jetbrains/jewel/samples/standalone/Main.kt index 50821cdba0..50b214b8e6 100644 --- a/samples/standalone/src/main/kotlin/org/jetbrains/jewel/samples/standalone/Main.kt +++ b/samples/standalone/src/main/kotlin/org/jetbrains/jewel/samples/standalone/Main.kt @@ -67,21 +67,22 @@ import java.net.URI fun main() { val icon = svgResource("icons/jewel-logo.svg") application { - var isDark by remember { mutableStateOf(false) } - var lightHeaderInLight by remember { mutableStateOf(false) } + // 0 for light + // 1 for light with light header + // 2 for dark + var intTheme by remember { mutableStateOf(IntUiThemes.Light) } + var swingCompat by remember { mutableStateOf(false) } - val theme = if (isDark) IntUiTheme.darkThemeDefinition() else IntUiTheme.lightThemeDefinition() + val theme = if (intTheme.isDark()) IntUiTheme.darkThemeDefinition() else IntUiTheme.lightThemeDefinition() val projectColor by rememberUpdatedState( - if (isDark) { - Color(0xFF654B40) - } else if (lightHeaderInLight) { + if (intTheme.isLightHeader()) { Color(0xFFF5D4C1) } else { Color(0xFF654B40) - }, + } ) - IntUiTheme(theme.withDecoratedWindow(lightHeaderInLight), swingCompat) { + IntUiTheme(theme.withDecoratedWindow(intTheme.isLightHeader()), swingCompat) { val resourceLoader = LocalResourceLoader.current val svgLoader by rememberSvgLoader() @@ -90,30 +91,38 @@ fun main() { title = "Jewel component catalog", icon = icon, ) { - val windowBackground = if (isDark) { + val windowBackground = if (intTheme.isDark()) { IntUiTheme.colorPalette.grey(1) } else { IntUiTheme.colorPalette.grey(14) } TitleBar(Modifier.newFullscreenControls(), gradientStartColor = projectColor) { - Text("<- Left", Modifier.align(Alignment.Start)) + val jewelLogoProvider = rememberStatelessPainterProvider("icons/jewel-logo.svg", svgLoader) + val jewelLogo by jewelLogoProvider.getPainter(resourceLoader) + + Icon(jewelLogo, "Jewel Logo", Modifier.size(20.dp).align(Alignment.Start)) + Text(title) Tooltip({ - if (isDark) { - Text("Switch to light theme") - } else { - Text("Switch to dark theme") + when (intTheme) { + IntUiThemes.Light -> Text("Switch to light theme with light header") + IntUiThemes.LightWithLightHeader -> Text("Switch to dark theme") + IntUiThemes.Dark -> Text("Switch to light theme") } }, Modifier.align(Alignment.End)) { IconButton({ - isDark = !isDark + intTheme = when (intTheme) { + IntUiThemes.Light -> IntUiThemes.LightWithLightHeader + IntUiThemes.LightWithLightHeader -> IntUiThemes.Dark + IntUiThemes.Dark -> IntUiThemes.Light + } }, Modifier.size(40.dp).padding(5.dp)) { val lightThemeIcon = rememberStatelessPainterProvider("icons/lightTheme@20x20.svg", svgLoader) val darkThemeIcon = rememberStatelessPainterProvider("icons/darkTheme@20x20.svg", svgLoader) - val iconProvider = if (isDark) darkThemeIcon else lightThemeIcon + val iconProvider = if (intTheme.isDark()) darkThemeIcon else lightThemeIcon Icon(iconProvider.getPainter(resourceLoader).value, "Themes") } } @@ -136,15 +145,6 @@ fun main() { horizontalArrangement = Arrangement.spacedBy(16.dp, Alignment.CenterHorizontally), verticalAlignment = Alignment.CenterVertically, ) { - CheckboxRow("Dark", isDark, resourceLoader, { isDark = it }) - if (!isDark) { - CheckboxRow( - "Light Header", - lightHeaderInLight, - resourceLoader, - { lightHeaderInLight = it }, - ) - } CheckboxRow("Swing compat", swingCompat, resourceLoader, { swingCompat = it }) }