From 4214263fda71f16eea5e5476bd2e38ae91da3f86 Mon Sep 17 00:00:00 2001 From: fscarponi Date: Tue, 5 Sep 2023 22:43:23 +0200 Subject: [PATCH] wip --- .../jetbrains/jewel/CircularProgressBar.kt | 34 +++++++++++ .../jewel/IntelliJComponentStyling.kt | 7 ++- .../org/jetbrains/jewel/IntelliJTheme.kt | 7 +++ .../jewel/styling/CircularProgressStyle.kt | 56 +++++++++++++++++++ .../org/jetbrains/jewel/bridge/IntUiBridge.kt | 3 + .../jewel/themes/intui/core/BaseIntUiTheme.kt | 8 +++ 6 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 core/src/main/kotlin/org/jetbrains/jewel/CircularProgressBar.kt create mode 100644 core/src/main/kotlin/org/jetbrains/jewel/styling/CircularProgressStyle.kt diff --git a/core/src/main/kotlin/org/jetbrains/jewel/CircularProgressBar.kt b/core/src/main/kotlin/org/jetbrains/jewel/CircularProgressBar.kt new file mode 100644 index 0000000000..43e18f5942 --- /dev/null +++ b/core/src/main/kotlin/org/jetbrains/jewel/CircularProgressBar.kt @@ -0,0 +1,34 @@ +package org.jetbrains.jewel + +import androidx.compose.foundation.layout.size +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Modifier +import kotlinx.coroutines.delay +import org.jetbrains.jewel.styling.CircularProgressStyle + +fun CircularProgress( + modifier: Modifier, + style: CircularProgressStyle = IntelliJTheme.circularProgressStyle, +) { + var currentFrame by remember { mutableStateOf(0) } + + Icon( + painter = style.frameIcons.frames.value[currentFrame], + contentDescription = null, + modifier = modifier.size(style.metrics.size) + ) + + LaunchedEffect(Unit) { + delay(style.metrics.animationDelay.toMillis()) + while (true) { + for (i in 0 until style.frameIcons.frames.value.size) { + currentFrame = i + delay(style.metrics.frameTime.toMillis()) + } + } + } +} diff --git a/core/src/main/kotlin/org/jetbrains/jewel/IntelliJComponentStyling.kt b/core/src/main/kotlin/org/jetbrains/jewel/IntelliJComponentStyling.kt index ac4cbde9db..08a232f8fc 100644 --- a/core/src/main/kotlin/org/jetbrains/jewel/IntelliJComponentStyling.kt +++ b/core/src/main/kotlin/org/jetbrains/jewel/IntelliJComponentStyling.kt @@ -4,6 +4,7 @@ import androidx.compose.runtime.Stable import org.jetbrains.jewel.styling.ButtonStyle import org.jetbrains.jewel.styling.CheckboxStyle import org.jetbrains.jewel.styling.ChipStyle +import org.jetbrains.jewel.styling.CircularProgressStyle import org.jetbrains.jewel.styling.DropdownStyle import org.jetbrains.jewel.styling.GroupHeaderStyle import org.jetbrains.jewel.styling.HorizontalProgressBarStyle @@ -36,6 +37,7 @@ class IntelliJComponentStyling( val scrollbarStyle: ScrollbarStyle, val textAreaStyle: TextAreaStyle, val textFieldStyle: TextFieldStyle, + val circularProgressStyle: CircularProgressStyle, ) { override fun equals(other: Any?): Boolean { @@ -61,6 +63,7 @@ class IntelliJComponentStyling( if (lazyTreeStyle != other.lazyTreeStyle) return false if (defaultTabStyle != other.defaultTabStyle) return false if (editorTabStyle != other.editorTabStyle) return false + if (circularProgressStyle != other.circularProgressStyle) return false return true } @@ -83,6 +86,7 @@ class IntelliJComponentStyling( result = 31 * result + lazyTreeStyle.hashCode() result = 31 * result + defaultTabStyle.hashCode() result = 31 * result + editorTabStyle.hashCode() + result = 31 * result + circularProgressStyle.hashCode() return result } @@ -93,5 +97,6 @@ class IntelliJComponentStyling( "horizontalProgressBarStyle=$horizontalProgressBarStyle, labelledTextFieldStyle=$labelledTextFieldStyle, " + "lazyTreeStyle=$lazyTreeStyle, linkStyle=$linkStyle, menuStyle=$menuStyle, " + "outlinedButtonStyle=$outlinedButtonStyle, radioButtonStyle=$radioButtonStyle, " + - "scrollbarStyle=$scrollbarStyle, textAreaStyle=$textAreaStyle, textFieldStyle=$textFieldStyle)" + "scrollbarStyle=$scrollbarStyle, textAreaStyle=$textAreaStyle, textFieldStyle=$textFieldStyle" + + "circularProgressStyle=$circularProgressStyle)" } diff --git a/core/src/main/kotlin/org/jetbrains/jewel/IntelliJTheme.kt b/core/src/main/kotlin/org/jetbrains/jewel/IntelliJTheme.kt index 6c26b6eacd..e036ab87e8 100644 --- a/core/src/main/kotlin/org/jetbrains/jewel/IntelliJTheme.kt +++ b/core/src/main/kotlin/org/jetbrains/jewel/IntelliJTheme.kt @@ -9,6 +9,7 @@ import androidx.compose.ui.text.TextStyle import org.jetbrains.jewel.styling.ButtonStyle import org.jetbrains.jewel.styling.CheckboxStyle import org.jetbrains.jewel.styling.ChipStyle +import org.jetbrains.jewel.styling.CircularProgressStyle import org.jetbrains.jewel.styling.DropdownStyle import org.jetbrains.jewel.styling.GroupHeaderStyle import org.jetbrains.jewel.styling.HorizontalProgressBarStyle @@ -17,6 +18,7 @@ import org.jetbrains.jewel.styling.LazyTreeStyle import org.jetbrains.jewel.styling.LinkStyle import org.jetbrains.jewel.styling.LocalCheckboxStyle import org.jetbrains.jewel.styling.LocalChipStyle +import org.jetbrains.jewel.styling.LocalCircularProgressStyle import org.jetbrains.jewel.styling.LocalDefaultButtonStyle import org.jetbrains.jewel.styling.LocalDefaultTabStyle import org.jetbrains.jewel.styling.LocalDropdownStyle @@ -175,6 +177,11 @@ interface IntelliJTheme { @Composable @ReadOnlyComposable get() = LocalEditorTabStyle.current + + val circularProgressStyle: CircularProgressStyle + @Composable + @ReadOnlyComposable + get() = LocalCircularProgressStyle.current } } diff --git a/core/src/main/kotlin/org/jetbrains/jewel/styling/CircularProgressStyle.kt b/core/src/main/kotlin/org/jetbrains/jewel/styling/CircularProgressStyle.kt new file mode 100644 index 0000000000..66701fb297 --- /dev/null +++ b/core/src/main/kotlin/org/jetbrains/jewel/styling/CircularProgressStyle.kt @@ -0,0 +1,56 @@ +package org.jetbrains.jewel.styling + +import androidx.compose.runtime.Immutable +import androidx.compose.runtime.State +import androidx.compose.runtime.staticCompositionLocalOf +import androidx.compose.ui.graphics.painter.Painter +import androidx.compose.ui.unit.DpSize +import java.time.Duration + +data class IntUiCircularProgressStyle( + override val frameIcons: CircularProgressIcons, + override val metrics: CircularProgressMetrics, +) : CircularProgressStyle { + + companion object { + // todo +// @Composable +// fun light( +// svgLoader: SvgLoader, +// metrics: IntUiLazyTreeMetrics = IntUiLazyTreeMetrics(), +// frameIcons: CircularProgressIcons: IntUiLazyTreeIcons = intUiLazyTreeIcons(svgLoader), +// ) = IntUiLazyTreeStyle(colors, metrics, icons) +// +// @Composable +// fun dark( +// svgLoader: SvgLoader, +// colors: IntUiLazyTreeColors = IntUiLazyTreeColors.dark(), +// metrics: IntUiLazyTreeMetrics = IntUiLazyTreeMetrics(), +// icons: IntUiLazyTreeIcons = intUiLazyTreeIcons(svgLoader), +// ) = IntUiLazyTreeStyle(colors, metrics, icons) + } +} + +interface CircularProgressStyle { + + val frameIcons: CircularProgressIcons + val metrics: CircularProgressMetrics +} + +@Immutable +interface CircularProgressIcons { + + val frames: State> +} + +@Immutable +interface CircularProgressMetrics { + + val animationDelay: Duration + val frameTime: Duration + val size: DpSize +} + +val LocalCircularProgressStyle = staticCompositionLocalOf { + error("No CircularProgressStyle provided") +} diff --git a/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/IntUiBridge.kt b/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/IntUiBridge.kt index 7939a5374b..e06767274e 100644 --- a/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/IntUiBridge.kt +++ b/ide-laf-bridge/src/main/kotlin/org/jetbrains/jewel/bridge/IntUiBridge.kt @@ -157,6 +157,7 @@ internal fun createSwingIntUiComponentStyling( radioButtonStyle = readRadioButtonStyle(theme.iconData, svgLoader), scrollbarStyle = readScrollbarStyle(theme.isDark), textAreaStyle = readTextAreaStyle(textAreaTextStyle, textFieldStyle.metrics), + circularProgressStyle = readCircularProgressStyle(theme.isDark, svgLoader), textFieldStyle = textFieldStyle, ) } @@ -871,3 +872,5 @@ private fun readEditorTabStyle(iconData: IntelliJThemeIconData, svgLoader: SvgLo ), ) } + +private fun readCircularProgressStyle(iconData: IntelliJThemeIconData, svgLoader: SvgLoader): IntUiCircula diff --git a/themes/int-ui/int-ui-core/src/main/kotlin/org/jetbrains/jewel/themes/intui/core/BaseIntUiTheme.kt b/themes/int-ui/int-ui-core/src/main/kotlin/org/jetbrains/jewel/themes/intui/core/BaseIntUiTheme.kt index 0e090974ec..72f58188a5 100644 --- a/themes/int-ui/int-ui-core/src/main/kotlin/org/jetbrains/jewel/themes/intui/core/BaseIntUiTheme.kt +++ b/themes/int-ui/int-ui-core/src/main/kotlin/org/jetbrains/jewel/themes/intui/core/BaseIntUiTheme.kt @@ -17,6 +17,7 @@ import org.jetbrains.jewel.LocalIconData import org.jetbrains.jewel.styling.ButtonStyle import org.jetbrains.jewel.styling.CheckboxStyle import org.jetbrains.jewel.styling.ChipStyle +import org.jetbrains.jewel.styling.CircularProgressStyle import org.jetbrains.jewel.styling.DropdownStyle import org.jetbrains.jewel.styling.GroupHeaderStyle import org.jetbrains.jewel.styling.HorizontalProgressBarStyle @@ -25,6 +26,7 @@ import org.jetbrains.jewel.styling.LazyTreeStyle import org.jetbrains.jewel.styling.LinkStyle import org.jetbrains.jewel.styling.LocalCheckboxStyle import org.jetbrains.jewel.styling.LocalChipStyle +import org.jetbrains.jewel.styling.LocalCircularProgressStyle import org.jetbrains.jewel.styling.LocalDefaultButtonStyle import org.jetbrains.jewel.styling.LocalDefaultTabStyle import org.jetbrains.jewel.styling.LocalDropdownStyle @@ -176,6 +178,11 @@ interface BaseIntUiTheme : IntelliJTheme { @Composable @ReadOnlyComposable get() = IntelliJTheme.editorTabStyle + + val circularProgressStyle: CircularProgressStyle + @Composable + @ReadOnlyComposable + get() = IntelliJTheme.circularProgressStyle } @Composable @@ -215,6 +222,7 @@ fun BaseIntUiTheme( LocalTextFieldStyle provides componentStyling.textFieldStyle, LocalDefaultTabStyle provides componentStyling.defaultTabStyle, LocalEditorTabStyle provides componentStyling.editorTabStyle, + LocalCircularProgressStyle provides componentStyling.circularProgressStyle, ) { IntelliJTheme(theme, swingCompatMode, content) }