@@ -2,6 +2,8 @@ package com.mohamedrejeb.richeditor.compose.spellcheck
22
33import androidx.compose.ui.graphics.Color
44import androidx.compose.ui.graphics.Path
5+ import androidx.compose.ui.graphics.StrokeCap
6+ import androidx.compose.ui.graphics.StrokeJoin
57import androidx.compose.ui.graphics.drawscope.DrawScope
68import androidx.compose.ui.graphics.drawscope.Stroke
79import androidx.compose.ui.text.SpanStyle
@@ -13,9 +15,15 @@ import com.mohamedrejeb.richeditor.annotation.ExperimentalRichTextApi
1315import com.mohamedrejeb.richeditor.model.RichSpanStyle
1416import com.mohamedrejeb.richeditor.model.RichTextConfig
1517import com.mohamedrejeb.richeditor.utils.getBoundingBoxes
18+ import kotlin.math.PI
19+ import kotlin.math.sin
1620
21+ /* *
22+ * RichSpanStyle that draws a Spell Check style red squiggle below the Spanned text.
23+ */
1724@OptIn(ExperimentalRichTextApi ::class )
1825public object SpellCheck: RichSpanStyle {
26+
1927 override val spanStyle: (RichTextConfig ) -> SpanStyle = {
2028 SpanStyle ()
2129 }
@@ -37,17 +45,35 @@ public object SpellCheck: RichSpanStyle {
3745
3846 boxes.fastForEach { box ->
3947 path.moveTo(box.left + startPadding, box.bottom + topPadding)
40- path.lineTo(box.right + startPadding, box.bottom + topPadding)
48+
49+ val amplitude = 1.5 .dp.toPx() // Height of the wave
50+ val frequency = 0.15f // Controls how many waves appear
51+ val width = box.right - box.left
52+
53+ // Create the sine wave path
54+ for (x in 0 .. width.toInt()) {
55+ val xPos = box.left + startPadding + x
56+ val yPos = box.bottom + topPadding +
57+ (amplitude * sin(x * frequency * 2 * PI )).toFloat()
58+
59+ if (x == 0 ) {
60+ path.moveTo(xPos, yPos)
61+ } else {
62+ path.lineTo(xPos, yPos)
63+ }
64+ }
4165
4266 drawPath(
4367 path = path,
4468 color = strokeColor,
4569 style = Stroke (
46- width = 2 .dp.toPx(),
70+ width = 1 .dp.toPx(),
71+ cap = StrokeCap .Round ,
72+ join = StrokeJoin .Round
4773 )
4874 )
4975 }
5076 }
5177
5278 override val acceptNewTextInTheEdges: Boolean = false
53- }
79+ }
0 commit comments