Skip to content

Commit 31c6a62

Browse files
authored
library: remove G2RoundedCornerShape from utils (#139)
* switch to use [gaze-capsule](https://github.com/6xingyv/gaze-capsule) * now any app that relies on this method needs to implement it itself or import [Capsule](https://github.com/Kyant0/Capsule) / [gaze-capsule](https://github.com/6xingyv/gaze-capsule).
1 parent 2ca6c17 commit 31c6a62

File tree

21 files changed

+80
-812
lines changed

21 files changed

+80
-812
lines changed

docs/guide/utils.md

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -189,73 +189,3 @@ The `PressFeedbackType` enum defines different types of visual feedback that can
189189
| None | No visual feedback |
190190
| Sink | Applies a sink effect, where the component scales down slightly when pressed |
191191
| Tilt | Applies a tilt effect, where the component tilts slightly based on the touch position |
192-
193-
## Smooth Rounded Corners (G2RoundedCornerShape)
194-
195-
`G2RoundedCornerShape` provides visually smoother corners than the standard `RoundedCornerShape` by blending part of the circular arc with Bézier transitions. It supports: a single uniform corner size, per-corner sizes (Dp / px / percent), preset or custom smoothness via `CornerSmoothness`, and a ready-made `CapsuleShape()` helper.
196-
197-
> Source: https://github.com/Kyant0/Capsule (Apache-2.0 License).
198-
199-
```kotlin
200-
G2RoundedCornerShape(size: Dp, cornerSmoothness: CornerSmoothness = CornerSmoothness.Default)
201-
G2RoundedCornerShape(
202-
topStart: Dp = 0.dp,
203-
topEnd: Dp = 0.dp,
204-
bottomEnd: Dp = 0.dp,
205-
bottomStart: Dp = 0.dp,
206-
cornerSmoothness: CornerSmoothness = CornerSmoothness.Default
207-
)
208-
G2RoundedCornerShape(percent: Int, cornerSmoothness: CornerSmoothness = CornerSmoothness.Default)
209-
CapsuleShape(cornerSmoothness: CornerSmoothness = CornerSmoothness.Default)
210-
```
211-
212-
`CornerSmoothness` parameters:
213-
* `circleFraction`: 0f..1f portion of a quarter circle preserved (1f = normal rounded corner, no smoothing blend)
214-
* `extendedFraction`: how much the control points extend horizontally/vertically to create a softer capsule-like shape
215-
216-
Presets:
217-
* `CornerSmoothness.Default` – balanced smoothness (softened corners)
218-
* `CornerSmoothness.None` – equivalent to a regular rounded corner (no extra smoothing)
219-
220-
### Basic Usage
221-
222-
```kotlin
223-
Surface(shape = G2RoundedCornerShape(16.dp)) {
224-
/* 内容 */
225-
}
226-
```
227-
228-
### Per-Corner Sizes
229-
230-
```kotlin
231-
Surface(
232-
shape = G2RoundedCornerShape(
233-
topStart = 16.dp,
234-
topEnd = 16.dp,
235-
bottomStart = 8.dp,
236-
bottomEnd = 8.dp,
237-
cornerSmoothness = CornerSmoothness.Default
238-
)
239-
) { /* Content */ }
240-
```
241-
242-
### Capsule Shape
243-
244-
```kotlin
245-
Surface(shape = CapsuleShape()) { /* Content */ }
246-
```
247-
248-
### Custom Smoothness
249-
250-
You can craft your own smoothness (smaller `circleFraction` & higher `extendedFraction` => softer / more elongated transition):
251-
252-
```kotlin
253-
val ExtraSmooth = CornerSmoothness(
254-
circleFraction = 0.55f, // retain 55% of the arc; lower -> more smoothing
255-
extendedFraction = 0.90f // push Bézier handles further for a pill-like feel
256-
)
257-
258-
Surface(shape = G2RoundedCornerShape(24.dp, cornerSmoothness = ExtraSmooth)) {
259-
// Content
260-
}
261-
```

docs/zh_CN/guide/utils.md

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -189,73 +189,3 @@ Box(
189189
| None | 无视觉反馈 |
190190
| Sink | 应用下沉效果,组件在按下时轻微缩小 |
191191
| Tilt | 应用倾斜效果,组件根据触摸位置轻微倾斜 |
192-
193-
## 平滑圆角 (G2RoundedCornerShape)
194-
195-
`G2RoundedCornerShape` 通过在标准圆角圆弧与 Bézier 过渡之间混合,实现比 `RoundedCornerShape` 更柔和、视觉更自然的圆角。它支持:统一圆角值、分别设置四个角(支持 Dp / px / 百分比)、通过 `CornerSmoothness` 预设或自定义平滑度,以及快捷的 `CapsuleShape()` 胶囊形状。
196-
197-
> 来源: https://github.com/Kyant0/Capsule (Apache-2.0 License)。
198-
199-
```kotlin
200-
G2RoundedCornerShape(size: Dp, cornerSmoothness: CornerSmoothness = CornerSmoothness.Default)
201-
G2RoundedCornerShape(
202-
topStart: Dp = 0.dp,
203-
topEnd: Dp = 0.dp,
204-
bottomEnd: Dp = 0.dp,
205-
bottomStart: Dp = 0.dp,
206-
cornerSmoothness: CornerSmoothness = CornerSmoothness.Default
207-
)
208-
G2RoundedCornerShape(percent: Int, cornerSmoothness: CornerSmoothness = CornerSmoothness.Default)
209-
CapsuleShape(cornerSmoothness: CornerSmoothness = CornerSmoothness.Default)
210-
```
211-
212-
`CornerSmoothness` 参数说明:
213-
* `circleFraction`: 0f..1f,表示保留四分之一圆弧的比例(1f = 传统圆角,不做平滑混合)
214-
* `extendedFraction`: 控制 Bézier 控制点向外延伸的程度,越大越接近椭圆/胶囊视觉
215-
216-
预设:
217-
* `CornerSmoothness.Default` – 默认柔滑(推荐常规使用)
218-
* `CornerSmoothness.None` – 与普通圆角等效(无额外平滑)
219-
220-
### 基本使用
221-
222-
```kotlin
223-
Surface(shape = G2RoundedCornerShape(16.dp)) {
224-
/* 内容 */
225-
}
226-
```
227-
228-
### 分别指定四个角
229-
230-
```kotlin
231-
Surface(
232-
shape = G2RoundedCornerShape(
233-
topStart = 16.dp,
234-
topEnd = 16.dp,
235-
bottomStart = 8.dp,
236-
bottomEnd = 8.dp,
237-
cornerSmoothness = CornerSmoothness.Default
238-
)
239-
) { /* 内容 */ }
240-
```
241-
242-
### 胶囊形状
243-
244-
```kotlin
245-
Surface(shape = CapsuleShape()) { /* 内容 */ }
246-
```
247-
248-
### 自定义平滑度
249-
250-
(降低 `circleFraction` + 提高 `extendedFraction` => 更软、更延展)
251-
252-
```kotlin
253-
val ExtraSmooth = CornerSmoothness(
254-
circleFraction = 0.55f, // 保留 55% 圆弧,越低越“圆润”
255-
extendedFraction = 0.90f // 控制点更外扩,接近胶囊
256-
)
257-
258-
Surface(shape = G2RoundedCornerShape(24.dp, cornerSmoothness = ExtraSmooth)) {
259-
// 内容
260-
}
261-
```

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
android-gradle-plugin = "8.13.0"
33
androidx-activity = "1.11.0"
44
androidx-window = "1.5.0"
5+
capsule = "2.1.1-patch2"
56
jetbrains-compose = "1.9.1"
67
jetbrains-compose-hotReload = "1.0.0-rc02"
78
jetbrains-androidx-navigation = "2.9.1"
@@ -16,6 +17,7 @@ androidx-window = { group = "androidx.window", name = "window", version.ref = "a
1617
jetbrains-androidx-navigation = { module = "org.jetbrains.androidx.navigation:navigation-compose", version.ref = "jetbrains-androidx-navigation" }
1718
jetbrains-compose-ui-backhandler = { module = "org.jetbrains.compose.ui:ui-backhandler", version.ref = "jetbrains-compose" }
1819
jetbrains-compose-window-size = { module = "org.jetbrains.compose.material3:material3-window-size-class", version.ref = "jetbrains-compose-window-size" }
20+
gaze-capsule = { module = "com.mocharealm.gaze:capsule", version.ref = "capsule" }
1921

2022
[plugins]
2123
android-application = { id = "com.android.application", version.ref = "android-gradle-plugin" }

miuix/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ kotlin {
6666

6767
implementation(libs.jetbrains.compose.ui.backhandler)
6868
implementation(libs.jetbrains.compose.window.size)
69+
70+
implementation(libs.gaze.capsule) // Capsule for Multiplatform
6971
}
7072
}
7173
}

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/basic/Button.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import androidx.compose.ui.semantics.role
2020
import androidx.compose.ui.semantics.semantics
2121
import androidx.compose.ui.unit.Dp
2222
import androidx.compose.ui.unit.dp
23+
import com.mocharealm.gaze.capsule.ContinuousRoundedRectangle
2324
import top.yukonga.miuix.kmp.theme.MiuixTheme
24-
import top.yukonga.miuix.kmp.utils.G2RoundedCornerShape
2525

2626
/**
2727
* A [Button] component with Miuix style.
@@ -48,7 +48,7 @@ fun Button(
4848
insideMargin: PaddingValues = ButtonDefaults.InsideMargin,
4949
content: @Composable RowScope.() -> Unit
5050
) {
51-
val shape = remember(cornerRadius) { G2RoundedCornerShape(cornerRadius) }
51+
val shape = remember(cornerRadius) { ContinuousRoundedRectangle(cornerRadius) }
5252
val color = if (enabled) colors.color else colors.disabledColor
5353
Surface(
5454
onClick = onClick,
@@ -93,7 +93,7 @@ fun TextButton(
9393
minHeight: Dp = ButtonDefaults.MinHeight,
9494
insideMargin: PaddingValues = ButtonDefaults.InsideMargin
9595
) {
96-
val shape = remember(cornerRadius) { G2RoundedCornerShape(cornerRadius) }
96+
val shape = remember(cornerRadius) { ContinuousRoundedRectangle(cornerRadius) }
9797
val color = if (enabled) colors.color else colors.disabledColor
9898
val textColor = if (enabled) colors.textColor else colors.disabledTextColor
9999
Surface(

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/basic/Card.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ import androidx.compose.ui.semantics.isTraversalGroup
2424
import androidx.compose.ui.semantics.semantics
2525
import androidx.compose.ui.unit.Dp
2626
import androidx.compose.ui.unit.dp
27+
import com.mocharealm.gaze.capsule.ContinuousRoundedRectangle
28+
import com.mocharealm.gaze.capsule.continuities.G1Continuity
2729
import top.yukonga.miuix.kmp.theme.LocalContentColor
2830
import top.yukonga.miuix.kmp.theme.MiuixTheme
29-
import top.yukonga.miuix.kmp.utils.CornerSmoothness
30-
import top.yukonga.miuix.kmp.utils.G2RoundedCornerShape
3131
import top.yukonga.miuix.kmp.utils.PressFeedbackType
3232
import top.yukonga.miuix.kmp.utils.SinkFeedback
3333
import top.yukonga.miuix.kmp.utils.TiltFeedback
@@ -141,8 +141,8 @@ private fun BasicCard(
141141
cornerRadius: Dp = CardDefaults.CornerRadius,
142142
content: @Composable () -> Unit,
143143
) {
144-
val shape = remember(cornerRadius) { G2RoundedCornerShape(cornerRadius) }
145-
val clipShape = remember(cornerRadius) { G2RoundedCornerShape(cornerRadius, CornerSmoothness.None) }
144+
val shape = remember(cornerRadius) { ContinuousRoundedRectangle(cornerRadius) }
145+
val clipShape = remember(cornerRadius) { ContinuousRoundedRectangle(cornerRadius, G1Continuity) }
146146

147147
CompositionLocalProvider(
148148
LocalContentColor provides colors.contentColor,
@@ -152,7 +152,7 @@ private fun BasicCard(
152152
.semantics(mergeDescendants = false) {
153153
isTraversalGroup = true
154154
}
155-
.clip(clipShape) // For touch feedback, there is a problem when using G2RoundedCornerShape.
155+
.clip(clipShape) // For touch feedback, there is a problem when using G2Continuity.
156156
.background(color = colors.color, shape = shape),
157157
propagateMinConstraints = true,
158158
) {

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/basic/Checkbox.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ import androidx.compose.ui.hapticfeedback.HapticFeedbackType
3535
import androidx.compose.ui.platform.LocalHapticFeedback
3636
import androidx.compose.ui.semantics.Role
3737
import androidx.compose.ui.unit.dp
38+
import com.mocharealm.gaze.capsule.ContinuousCapsule
3839
import kotlinx.coroutines.launch
3940
import top.yukonga.miuix.kmp.theme.MiuixTheme
40-
import top.yukonga.miuix.kmp.utils.CapsuleShape
4141
import top.yukonga.miuix.kmp.utils.pressable
4242

4343
/**
@@ -94,7 +94,7 @@ fun Checkbox(
9494
.wrapContentSize(Alignment.Center)
9595
.requiredSize(25.5.dp)
9696
.pressable(enabled = enabled, delay = null)
97-
.clip(CapsuleShape)
97+
.clip(ContinuousCapsule)
9898
.drawBehind {
9999
drawCircle(backgroundColor)
100100
}

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/basic/ColorPalette.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ import androidx.compose.ui.unit.Dp
3535
import androidx.compose.ui.unit.IntSize
3636
import androidx.compose.ui.unit.dp
3737
import androidx.compose.ui.util.lerp
38-
import top.yukonga.miuix.kmp.utils.CapsuleShape
39-
import top.yukonga.miuix.kmp.utils.G2RoundedCornerShape
38+
import com.mocharealm.gaze.capsule.ContinuousCapsule
39+
import com.mocharealm.gaze.capsule.ContinuousRoundedRectangle
4040
import top.yukonga.miuix.kmp.utils.Hsv
4141
import top.yukonga.miuix.kmp.utils.toHsv
4242
import kotlin.math.abs
@@ -120,7 +120,7 @@ fun ColorPalette(
120120
modifier = Modifier
121121
.fillMaxWidth()
122122
.height(26.dp)
123-
.clip(CapsuleShape())
123+
.clip(ContinuousCapsule)
124124
.background(lastEmittedColor ?: initialColor)
125125
)
126126
}
@@ -159,7 +159,7 @@ fun ColorPalette(
159159
alpha = it
160160
val newColor = base.copy(alpha = it)
161161
lastAcceptedHSV =
162-
base.toHsv().let { it -> Triple(it.h.toFloat(), (it.s / 100.0).toFloat(), (it.v / 100.0).toFloat()) }
162+
base.toHsv().let { Triple(it.h.toFloat(), (it.s / 100.0).toFloat(), (it.v / 100.0).toFloat()) }
163163
lastEmittedColor = newColor
164164
onColorChangedState.value(newColor)
165165
}
@@ -182,7 +182,7 @@ private fun PaletteCanvas(
182182
val totalColumns = hueColumns + if (includeGrayColumn) 1 else 0
183183
val rowSV = remember(rows) { buildRowSV(rows) }
184184
val grayV = remember(rows) { buildGrayV(rows) }
185-
val shape = G2RoundedCornerShape(cornerRadius)
185+
val shape = ContinuousRoundedRectangle(cornerRadius)
186186

187187
var sizePx by remember { mutableStateOf(IntSize.Zero) }
188188

@@ -253,9 +253,9 @@ private fun PaletteCanvas(
253253
y = with(density) { cyPx.toDp() - indicatorSize / 2 }
254254
)
255255
.size(indicatorSize)
256-
.clip(CapsuleShape())
257-
.border(6.dp, Color.White, CapsuleShape())
258-
.background(Color.Transparent, CapsuleShape())
256+
.clip(ContinuousCapsule)
257+
.border(6.dp, Color.White, ContinuousCapsule)
258+
.background(Color.Transparent, ContinuousCapsule)
259259
)
260260
}
261261
}

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/basic/ColorPicker.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import androidx.compose.ui.platform.LocalDensity
3737
import androidx.compose.ui.platform.LocalHapticFeedback
3838
import androidx.compose.ui.unit.Dp
3939
import androidx.compose.ui.unit.dp
40-
import top.yukonga.miuix.kmp.utils.CapsuleShape
40+
import com.mocharealm.gaze.capsule.ContinuousCapsule
4141
import top.yukonga.miuix.kmp.utils.ColorUtils
4242
import top.yukonga.miuix.kmp.utils.Hsv
4343
import top.yukonga.miuix.kmp.utils.OkLab
@@ -154,7 +154,7 @@ fun HsvColorPicker(
154154
modifier = Modifier
155155
.fillMaxWidth()
156156
.height(26.dp)
157-
.clip(CapsuleShape())
157+
.clip(ContinuousCapsule)
158158
.background(selectedColor)
159159
)
160160
}
@@ -371,7 +371,7 @@ fun OkHsvColorPicker(
371371
modifier = Modifier
372372
.fillMaxWidth()
373373
.height(26.dp)
374-
.clip(CapsuleShape())
374+
.clip(ContinuousCapsule)
375375
.background(selectedColor)
376376
)
377377
}
@@ -596,7 +596,7 @@ fun OkLabColorPicker(
596596
modifier = Modifier
597597
.fillMaxWidth()
598598
.height(26.dp)
599-
.clip(CapsuleShape())
599+
.clip(ContinuousCapsule)
600600
.background(selectedColor)
601601
)
602602
}
@@ -840,7 +840,7 @@ private fun ColorSlider(
840840

841841
Box(
842842
modifier = Modifier
843-
.clip(CapsuleShape())
843+
.clip(ContinuousCapsule)
844844
.then(modifier)
845845
.height(sliderHeightDp)
846846
.onGloballyPositioned { coordinates ->
@@ -903,8 +903,8 @@ private fun SliderIndicator(
903903
modifier = modifier
904904
.offset(x = indicatorOffsetXDp)
905905
.size(indicatorSize)
906-
.border(6.dp, Color.White, CapsuleShape())
907-
.background(Color.Transparent, CapsuleShape())
906+
.border(6.dp, Color.White, ContinuousCapsule)
907+
.background(Color.Transparent, ContinuousCapsule)
908908
)
909909
}
910910

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/basic/FloatingActionButton.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import androidx.compose.ui.semantics.role
2323
import androidx.compose.ui.semantics.semantics
2424
import androidx.compose.ui.unit.Dp
2525
import androidx.compose.ui.unit.dp
26+
import com.mocharealm.gaze.capsule.ContinuousCapsule
2627
import top.yukonga.miuix.kmp.theme.MiuixTheme
27-
import top.yukonga.miuix.kmp.utils.CapsuleShape
2828

2929
/**
3030
* A [FloatingActionButton] component with Miuix style.
@@ -43,7 +43,7 @@ import top.yukonga.miuix.kmp.utils.CapsuleShape
4343
fun FloatingActionButton(
4444
onClick: () -> Unit,
4545
modifier: Modifier = Modifier,
46-
shape: Shape = CapsuleShape(),
46+
shape: Shape = ContinuousCapsule,
4747
containerColor: Color = MiuixTheme.colorScheme.primary,
4848
shadowElevation: Dp = 4.dp,
4949
minWidth: Dp = 60.dp,

0 commit comments

Comments
 (0)