@@ -2,6 +2,8 @@ package com.mohamedrejeb.richeditor.compose.spellcheck
2
2
3
3
import androidx.compose.ui.graphics.Color
4
4
import androidx.compose.ui.graphics.Path
5
+ import androidx.compose.ui.graphics.StrokeCap
6
+ import androidx.compose.ui.graphics.StrokeJoin
5
7
import androidx.compose.ui.graphics.drawscope.DrawScope
6
8
import androidx.compose.ui.graphics.drawscope.Stroke
7
9
import androidx.compose.ui.text.SpanStyle
@@ -13,9 +15,15 @@ import com.mohamedrejeb.richeditor.annotation.ExperimentalRichTextApi
13
15
import com.mohamedrejeb.richeditor.model.RichSpanStyle
14
16
import com.mohamedrejeb.richeditor.model.RichTextConfig
15
17
import com.mohamedrejeb.richeditor.utils.getBoundingBoxes
18
+ import kotlin.math.PI
19
+ import kotlin.math.sin
16
20
21
+ /* *
22
+ * RichSpanStyle that draws a Spell Check style red squiggle below the Spanned text.
23
+ */
17
24
@OptIn(ExperimentalRichTextApi ::class )
18
25
public object SpellCheck: RichSpanStyle {
26
+
19
27
override val spanStyle: (RichTextConfig ) -> SpanStyle = {
20
28
SpanStyle ()
21
29
}
@@ -37,17 +45,35 @@ public object SpellCheck: RichSpanStyle {
37
45
38
46
boxes.fastForEach { box ->
39
47
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
+ }
41
65
42
66
drawPath(
43
67
path = path,
44
68
color = strokeColor,
45
69
style = Stroke (
46
- width = 2 .dp.toPx(),
70
+ width = 1 .dp.toPx(),
71
+ cap = StrokeCap .Round ,
72
+ join = StrokeJoin .Round
47
73
)
48
74
)
49
75
}
50
76
}
51
77
52
78
override val acceptNewTextInTheEdges: Boolean = false
53
- }
79
+ }
0 commit comments