
Creates G2-continuous rounded rectangles and capsules with configurable continuity (G1/G2), tunable arc/Bezier profiles, G1-guarantee and optimized Bézier control-point calculation for efficient rendering.
Based on the original project: Capsule
Original author: Kyant0
Capsule for Compose Multiplatform is a Compose Multiplatform library that creates G2 continuous rounded rectangles.
In build.gradle.kts, add
implementation("dev.mingyubmy:capsule-compose-multiplatform:<version>")Replace the 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 on Android performs poorly. 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.
Based on the original project: Capsule
Original author: Kyant0
Capsule for Compose Multiplatform is a Compose Multiplatform library that creates G2 continuous rounded rectangles.
In build.gradle.kts, add
implementation("dev.mingyubmy:capsule-compose-multiplatform:<version>")Replace the 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 on Android performs poorly. 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.