
Generates G2-continuous rounded rectangles and capsules with customizable curvature profiles, efficient Bézier control-point computation, and runtime continuity tuning for smooth corners.
Capsule is a Kotlin Multiplatform & Compose Multiplatform library that creates G2 continuous rounded rectangles.
Customizable curvature combs:
A sample project for both Android and iOS is available in the example directory. You can run:
:example:androidApp
:example:iosApp (Xcode project located in example/iosApp)In your multiplatform project, add the dependency to your commonMain source set:
kotlin {
sourceSets {
commonMain.dependencies {
implementation("zone.ien.capsule:capsule:<version>")
}
}
}Or for single-platform Android projects, in build.gradle.kts:
dependencies {
implementation("zone.ien.capsule:capsule:<version>")
}Replace RoundedCornerShape with ContinuousRoundedRectangle or ContinuousCapsule:
// create a basic rounded corner shape
ContinuousRoundedRectangle(16.dp)
// create a capsule shape
ContinuousCapsuleCustom continuity:
val g1 = G1Continuity // no corner smoothness
val g2 = G2Continuity(
profile = G2ContinuityProfile.RoundedRectangle.copy(
extendedFraction = 0.5,
arcFraction = 0.5,
bezierCurvatureScale = 1.1,
arcCurvatureScale = 1.1
),
capsuleProfile = G2ContinuityProfile.Capsule.copy(
extendedFraction = 0.5,
arcFraction = 0.25
)
)
// create shapes with custom continuity
ContinuousRoundedRectangle(16.dp, continuity = g2)
ContinuousCapsule(continuity = g2)The following parameters are supported by G2ContinuityProfile:
Note: It guarantees G1 continuity at least. Only if the Bezier curvature scale equals the arc curvature scale, it will have exact G2 continuity.
Drawing cubic Bézier curves can be computationally heavy. However, the Capsule library uses a very efficient method to calculate the control points, achieving optimal theoretical performance.
When the shape area is large (almost fullscreen) and the corner radius is constantly changing, performance may decrease. Use animatedShape.copy(continuity = G1Continuity) to temporarily disable corner smoothing during the animation.
Capsule is a Kotlin Multiplatform & Compose Multiplatform library that creates G2 continuous rounded rectangles.
Customizable curvature combs:
A sample project for both Android and iOS is available in the example directory. You can run:
:example:androidApp
:example:iosApp (Xcode project located in example/iosApp)In your multiplatform project, add the dependency to your commonMain source set:
kotlin {
sourceSets {
commonMain.dependencies {
implementation("zone.ien.capsule:capsule:<version>")
}
}
}Or for single-platform Android projects, in build.gradle.kts:
dependencies {
implementation("zone.ien.capsule:capsule:<version>")
}Replace RoundedCornerShape with ContinuousRoundedRectangle or ContinuousCapsule:
// create a basic rounded corner shape
ContinuousRoundedRectangle(16.dp)
// create a capsule shape
ContinuousCapsuleCustom continuity:
val g1 = G1Continuity // no corner smoothness
val g2 = G2Continuity(
profile = G2ContinuityProfile.RoundedRectangle.copy(
extendedFraction = 0.5,
arcFraction = 0.5,
bezierCurvatureScale = 1.1,
arcCurvatureScale = 1.1
),
capsuleProfile = G2ContinuityProfile.Capsule.copy(
extendedFraction = 0.5,
arcFraction = 0.25
)
)
// create shapes with custom continuity
ContinuousRoundedRectangle(16.dp, continuity = g2)
ContinuousCapsule(continuity = g2)The following parameters are supported by G2ContinuityProfile:
Note: It guarantees G1 continuity at least. Only if the Bezier curvature scale equals the arc curvature scale, it will have exact G2 continuity.
Drawing cubic Bézier curves can be computationally heavy. However, the Capsule library uses a very efficient method to calculate the control points, achieving optimal theoretical performance.
When the shape area is large (almost fullscreen) and the corner radius is constantly changing, performance may decrease. Use animatedShape.copy(continuity = G1Continuity) to temporarily disable corner smoothing during the animation.