-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
114 additions
and
1 deletion.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
core/src/main/kotlin/org/jetbrains/jewel/CircularProgressBar.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
core/src/main/kotlin/org/jetbrains/jewel/styling/CircularProgressStyle.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters