/
GridLines.kt
47 lines (39 loc) · 1.28 KB
/
GridLines.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
* **************
* Charty Library : Android
*
* Copyright (c) 2023. Charty Contributor
* **************
*/
package com.himanshoe.charty.common.ui
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.DrawScope
fun DrawScope.drawGridLines(width: Float, height: Float, spacing: Float) {
// Calculate the dimensions of the grid area by subtracting the spacing
val newHeight = height.minus(spacing)
val newWidth = width.minus(spacing)
// Calculate the spacing between horizontal and vertical grid lines
val horizontalGridSpacing = newHeight / 5
val verticalGridSpacing = newWidth / 4
// Draw horizontal grid lines
repeat(4) { i ->
val y = (i + 1) * horizontalGridSpacing
drawLine(
start = Offset(0F, y + spacing),
end = Offset(newWidth + spacing, y + spacing),
color = Color.LightGray,
strokeWidth = 1f
)
}
// Draw vertical grid lines
repeat(3) { i ->
val x = (i + 1) * verticalGridSpacing
drawLine(
start = Offset(x + spacing, 0F),
end = Offset(x + spacing, newHeight + spacing),
color = Color.LightGray,
strokeWidth = 1f
)
}
}