Skip to content

Instantly share code, notes, and snippets.

Avatar

Francesc Vilariño Güell fvilarino

  • Vancouver, CA
View GitHub Profile
View segmented_progress_rtl.kt
private fun DrawScope.drawSegments(
progress: Float,
color: Color,
segmentHeight: Float,
segments: Int,
segmentGap: Float,
) {
val width = size.width
val gaps = (segments - 1) * segmentGap
val segmentWidth = (width - gaps) / segments
@fvilarino
fvilarino / segmented_progress_usage_sample.kt
Created Dec 4, 2022
Segmented Progress - Usage Sample
View segmented_progress_usage_sample.kt
var runForwards by remember { mutableStateOf(false) }
val progress: Float by animateFloatAsState(
if (runForwards) 1f else 0f,
animationSpec = tween(
durationMillis = 10_000,
easing = LinearEasing
)
)
Surface(color = MaterialTheme.colors.background) {
Column(
View segmented_progress_final.kt
private fun DrawScope.drawSegments(
progress: Float,
color: Color,
segmentHeight: Float,
segments: Int,
segmentGap: Float,
) {
val width = size.width
val start = 0f
val gaps = (segments - 1) * segmentGap
@fvilarino
fvilarino / segmented_progress_preliminary.kt
Created Dec 4, 2022
Segmented Progress - Preliminary
View segmented_progress_preliminary.kt
@Composable
fun SegmentedProgressIndicator(
/*@FloatRange(from = 0.0, to = 1.0)*/
progress: Float,
modifier: Modifier = Modifier,
color: Color = MaterialTheme.colors.primary,
backgroundColor: Color = color.copy(alpha = BackgroundOpacity),
progressHeight: Dp = ProgressHeight,
numberOfSegments: Int = NumberOfSegments,
segmentGap: Dp = SegmentGap
@fvilarino
fvilarino / segmented_progress_generalized.kt
Created Dec 4, 2022
Segmented Progress - Generalized
View segmented_progress_generalized.kt
private fun DrawScope.drawSegments(
// 1
progress: Float,
color: Color,
strokeWidth: Float,
segments: Int,
segmentGap: Float,
) {
val width = size.width
val start = 0f
@fvilarino
fvilarino / segmented_progress_background.kt
Created Dec 4, 2022
Segmented Progress - Background
View segmented_progress_background.kt
private fun DrawScope.drawSegments(
color: Color,
segmentHeight: Float,
segments: Int,
segmentGap: Float,
) {
// 1
val width = size.width
val start = 0f
val end = width
View segmented_progress_gap.kt
Canvas(
modifier
.progressSemantics(progress)
.height(progressHeight)
) {
drawSegments(backgroundColor, barHeight, numberOfSegments, gap)
}
@fvilarino
fvilarino / segmented_progress_local_density.kt
Created Dec 4, 2022
Segmented Progress - Local density
View segmented_progress_local_density.kt
val gap: Float
val barHeight: Float
with(LocalDensity.current) {
gap = segmentGap.toPx()
barHeight = progressHeight.toPx()
}
@fvilarino
fvilarino / segmented_progress_signature.kt
Created Dec 4, 2022
Segmented Progress - SIgnature
View segmented_progress_signature.kt
private const val BackgroundOpacity = 0.25f
private const val NumberOfSegments = 8
private val ProgressHeight = 4.dp
private val SegmentGap = 8.dp
@Composable
fun SegmentedProgressIndicator(
/*@FloatRange(from = 0.0, to = 1.0)*/
progress: Float,
modifier: Modifier = Modifier,
View progress_indicator_final2.kt
private const val NumDots = 5
private const val AnimationDuration = 2000
private const val AnimationSegment = AnimationDuration / 10
private val MainDotSize = 24.dp
private val Float.alphaFromRadians: Float
get() {
val normalized = (this / (2f * PI)).toFloat()
return .5f + (normalized - .5f).absoluteValue
}