Skip to content

Commit 7e04ad8

Browse files
committed
update Checkbox to new rect outline implementation
1 parent f2f51d6 commit 7e04ad8

File tree

1 file changed

+13
-19
lines changed
  • ui/src/androidMain/kotlin/kiwi/orbit/compose/ui/controls

1 file changed

+13
-19
lines changed

ui/src/androidMain/kotlin/kiwi/orbit/compose/ui/controls/Checkbox.kt

+13-19
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import kiwi.orbit.compose.ui.OrbitTheme
3838
import kiwi.orbit.compose.ui.R
3939
import kiwi.orbit.compose.ui.controls.internal.OrbitPreviews
4040
import kiwi.orbit.compose.ui.controls.internal.Preview
41+
import kiwi.orbit.compose.ui.utils.drawStrokeOutlineRoundRect
4142

4243
@OptIn(ExperimentalAnimationGraphicsApi::class)
4344
@Composable
@@ -124,8 +125,6 @@ private fun DrawScope.drawCheckbox(borderColor: Color, backgroundColor: Color, e
124125
val errorShift = if (hasError) 0.5.dp.toPx() else 0f
125126

126127
val checkboxSize = CheckboxSize.toPx()
127-
val checkboxBorderWidth = CheckboxBorderWidth.toPx()
128-
val checkboxBorderHalfWidth = checkboxBorderWidth / 2.0f
129128
val checkboxCornerRadius = CornerRadius(CheckboxCornerRadius.toPx())
130129
drawRoundRect(
131130
color = backgroundColor,
@@ -134,36 +133,31 @@ private fun DrawScope.drawCheckbox(borderColor: Color, backgroundColor: Color, e
134133
cornerRadius = checkboxCornerRadius,
135134
style = Fill,
136135
)
137-
drawRoundRect(
136+
drawStrokeOutlineRoundRect(
138137
color = borderColor,
139-
topLeft = Offset(checkboxBorderHalfWidth, checkboxBorderHalfWidth),
140-
size = Size(checkboxSize - checkboxBorderWidth, checkboxSize - checkboxBorderWidth),
138+
topLeft = Offset(0f, 0f),
139+
size = Size(CheckboxSize.toPx(), CheckboxSize.toPx()),
141140
cornerRadius = checkboxCornerRadius,
142-
style = Stroke(checkboxBorderWidth),
141+
stroke = Stroke(CheckboxBorderWidth.toPx()),
143142
)
144143
}
145144

146145
private fun DrawScope.drawError(borderColor: Color, shadowColor: Color, alpha: Float) {
147146
if (alpha == 0.0f) return
148147

149-
val shadowRectShift = (ErrorShadowWidth / 2.0f).toPx()
150-
val shadowRectSize = (ErrorShadowSize - ErrorShadowWidth).toPx()
151-
drawRoundRect(
148+
drawStrokeOutlineRoundRect(
152149
color = shadowColor,
153-
topLeft = Offset(-shadowRectShift, -shadowRectShift),
154-
size = Size(shadowRectSize, shadowRectSize),
150+
topLeft = Offset(-ErrorShadowWidth.toPx(), -ErrorShadowWidth.toPx()),
151+
size = Size(ErrorShadowSize.toPx(), ErrorShadowSize.toPx()),
155152
cornerRadius = CornerRadius(ErrorShadowCornerRadius.toPx()),
156-
style = Stroke(ErrorShadowWidth.toPx()),
153+
stroke = Stroke(ErrorShadowWidth.toPx()),
157154
)
158-
159-
val errorRectShift = (CheckboxBorderWidth / 2.0f).toPx()
160-
val errorRectSize = (CheckboxSize - CheckboxBorderWidth).toPx()
161-
drawRoundRect(
155+
drawStrokeOutlineRoundRect(
162156
color = borderColor,
163-
topLeft = Offset(errorRectShift, errorRectShift),
164-
size = Size(errorRectSize, errorRectSize),
157+
topLeft = Offset(0f, 0f),
158+
size = Size(CheckboxSize.toPx(), CheckboxSize.toPx()),
165159
cornerRadius = CornerRadius(CheckboxCornerRadius.toPx()),
166-
style = Stroke(CheckboxBorderWidth.toPx()),
160+
stroke = Stroke(CheckboxBorderWidth.toPx()),
167161
)
168162
}
169163

0 commit comments

Comments
 (0)