Skip to content

Commit

Permalink
Avoid pass lightWithLightHeader to withDecoratedWindow DSL
Browse files Browse the repository at this point in the history
  • Loading branch information
devkanro committed Oct 13, 2023
1 parent f9f1633 commit 2db6eb1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,27 +1,14 @@
package org.jetbrains.jewel.intui.window

import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import org.jetbrains.jewel.SvgLoader
import org.jetbrains.jewel.intui.core.IntUiThemeDefinition
import org.jetbrains.jewel.intui.standalone.rememberSvgLoader
import org.jetbrains.jewel.intui.window.styling.IntUiDecoratedWindowStyle
import org.jetbrains.jewel.intui.window.styling.IntUiTitleBarStyle
import org.jetbrains.jewel.window.styling.DecoratedWindowStyle
import org.jetbrains.jewel.window.styling.LocalDecoratedWindowStyle
import org.jetbrains.jewel.window.styling.LocalTitleBarStyle
import org.jetbrains.jewel.window.styling.TitleBarStyle

@Composable
fun IntUiThemeDefinition.titleBarStyle(svgLoader: SvgLoader, lightHeaderInLight: Boolean = false): TitleBarStyle =
if (isDark) {
IntUiTitleBarStyle.dark(svgLoader)
} else if (lightHeaderInLight) {
IntUiTitleBarStyle.lightWithLightHeader(svgLoader)
} else {
IntUiTitleBarStyle.light(svgLoader)
}

@Composable
fun IntUiThemeDefinition.decoratedWindowStyle(): DecoratedWindowStyle =
if (isDark) {
Expand All @@ -31,11 +18,15 @@ fun IntUiThemeDefinition.decoratedWindowStyle(): DecoratedWindowStyle =
}

@Composable
fun IntUiThemeDefinition.withDecoratedWindow(lightHeaderInLight: Boolean = false): IntUiThemeDefinition {
val svgLoader by rememberSvgLoader(!lightHeaderInLight)

fun IntUiThemeDefinition.withDecoratedWindow(
titleBarStyle: TitleBarStyle = if (isDark) {
IntUiTitleBarStyle.dark()
} else {
IntUiTitleBarStyle.light()
},
): IntUiThemeDefinition {
return withExtensions(
LocalDecoratedWindowStyle provides decoratedWindowStyle(),
LocalTitleBarStyle provides titleBarStyle(svgLoader, lightHeaderInLight),
LocalTitleBarStyle provides titleBarStyle,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import org.jetbrains.jewel.LocalIconData
import org.jetbrains.jewel.SvgLoader
import org.jetbrains.jewel.intui.core.theme.IntUiDarkTheme
import org.jetbrains.jewel.intui.core.theme.IntUiLightTheme
import org.jetbrains.jewel.intui.standalone.rememberSvgLoader
import org.jetbrains.jewel.intui.standalone.styling.IntUiIconButtonColors
import org.jetbrains.jewel.intui.standalone.styling.IntUiIconButtonMetrics
import org.jetbrains.jewel.intui.standalone.styling.IntUiIconButtonStyle
Expand Down Expand Up @@ -109,23 +110,23 @@ class IntUiTitleBarStyle(

@Composable
fun light(
svgLoader: SvgLoader,
svgLoader: SvgLoader = rememberSvgLoader(false).value,
colors: IntUiTitleBarColors = IntUiTitleBarColors.light(),
metrics: IntUiTitleBarMetrics = IntUiTitleBarMetrics(),
icons: IntUiTitleBarIcons = intUiTitleBarIcons(svgLoader),
): IntUiTitleBarStyle = IntUiTitleBarStyle(colors, metrics, icons)

@Composable
fun lightWithLightHeader(
svgLoader: SvgLoader,
svgLoader: SvgLoader = rememberSvgLoader(false).value,
colors: IntUiTitleBarColors = IntUiTitleBarColors.lightWithLightHeader(),
metrics: IntUiTitleBarMetrics = IntUiTitleBarMetrics(),
icons: IntUiTitleBarIcons = intUiTitleBarIcons(svgLoader),
): IntUiTitleBarStyle = IntUiTitleBarStyle(colors, metrics, icons)

@Composable
fun dark(
svgLoader: SvgLoader,
svgLoader: SvgLoader = rememberSvgLoader(true).value,
colors: IntUiTitleBarColors = IntUiTitleBarColors.dark(),
metrics: IntUiTitleBarMetrics = IntUiTitleBarMetrics(),
icons: IntUiTitleBarIcons = intUiTitleBarIcons(svgLoader),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import org.jetbrains.jewel.Tooltip
import org.jetbrains.jewel.VerticalScrollbar
import org.jetbrains.jewel.intui.standalone.IntUiTheme
import org.jetbrains.jewel.intui.standalone.rememberSvgLoader
import org.jetbrains.jewel.intui.window.styling.IntUiTitleBarStyle
import org.jetbrains.jewel.intui.window.withDecoratedWindow
import org.jetbrains.jewel.samples.standalone.components.Borders
import org.jetbrains.jewel.samples.standalone.components.Buttons
Expand All @@ -67,9 +68,6 @@ import java.net.URI
fun main() {
val icon = svgResource("icons/jewel-logo.svg")
application {
// 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) }
Expand All @@ -79,10 +77,19 @@ fun main() {
Color(0xFFF5D4C1)
} else {
Color(0xFF654B40)
}
},
)

IntUiTheme(theme.withDecoratedWindow(intTheme.isLightHeader()), swingCompat) {
IntUiTheme(
theme.withDecoratedWindow(
titleBarStyle = when (intTheme) {
IntUiThemes.Light -> IntUiTitleBarStyle.light()
IntUiThemes.LightWithLightHeader -> IntUiTitleBarStyle.lightWithLightHeader()
IntUiThemes.Dark -> IntUiTitleBarStyle.dark()
},
),
swingCompat,
) {
val resourceLoader = LocalResourceLoader.current
val svgLoader by rememberSvgLoader()

Expand Down

0 comments on commit 2db6eb1

Please sign in to comment.