Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
fscarponi committed Sep 5, 2023
1 parent 8c9f591 commit 4214263
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 1 deletion.
34 changes: 34 additions & 0 deletions core/src/main/kotlin/org/jetbrains/jewel/CircularProgressBar.kt
Original file line number Diff line number Diff line change
@@ -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())
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -36,6 +37,7 @@ class IntelliJComponentStyling(
val scrollbarStyle: ScrollbarStyle,
val textAreaStyle: TextAreaStyle,
val textFieldStyle: TextFieldStyle,
val circularProgressStyle: CircularProgressStyle,
) {

override fun equals(other: Any?): Boolean {
Expand All @@ -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
}
Expand All @@ -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
}

Expand All @@ -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)"
}
7 changes: 7 additions & 0 deletions core/src/main/kotlin/org/jetbrains/jewel/IntelliJTheme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -175,6 +177,11 @@ interface IntelliJTheme {
@Composable
@ReadOnlyComposable
get() = LocalEditorTabStyle.current

val circularProgressStyle: CircularProgressStyle
@Composable
@ReadOnlyComposable
get() = LocalCircularProgressStyle.current
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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<List<Painter>>
}

@Immutable
interface CircularProgressMetrics {

val animationDelay: Duration
val frameTime: Duration
val size: DpSize
}

val LocalCircularProgressStyle = staticCompositionLocalOf<CircularProgressStyle> {
error("No CircularProgressStyle provided")
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
}
Expand Down Expand Up @@ -871,3 +872,5 @@ private fun readEditorTabStyle(iconData: IntelliJThemeIconData, svgLoader: SvgLo
),
)
}

private fun readCircularProgressStyle(iconData: IntelliJThemeIconData, svgLoader: SvgLoader): IntUiCircula
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -176,6 +178,11 @@ interface BaseIntUiTheme : IntelliJTheme {
@Composable
@ReadOnlyComposable
get() = IntelliJTheme.editorTabStyle

val circularProgressStyle: CircularProgressStyle
@Composable
@ReadOnlyComposable
get() = IntelliJTheme.circularProgressStyle
}

@Composable
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 4214263

Please sign in to comment.