Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net.youapps.calcyou.ui.screens.graphing

import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.text.TextMeasurer
Expand Down Expand Up @@ -46,7 +45,7 @@ fun DrawScope.drawGridLines(window: Window, lineWidth: Float, gridLinesColor: Co

internal fun Float.toDisplayString(): String {
return when {
(this % 1f == 0f) && (this in 0.0001f..10000f) -> {
(this % 1f == 0f) && (abs(this) in 0.0001f..10000f) -> {
this.toInt().toString()
}

Expand Down Expand Up @@ -108,20 +107,27 @@ fun DrawScope.drawAxes(
// Offset(xDraw, yDraw - halfTickLength),
// lineWidth
// )
val textWidth = 200 / canvasScale
val textHeight = 40 / canvasScale

val textSize = 36 / canvasScale
val textPadding = 20 / canvasScale
drawText(
textMeasurer,
xDisplayValue,
topLeft = Offset(xDraw - textWidth / 2, yDraw + textPadding),
size = Size(textWidth, textHeight),

val textLayoutResult = textMeasurer.measure(
text = xDisplayValue,
style = TextStyle(
color = axesColor,
fontSize = textSize.toSp(),
textAlign = TextAlign.Center,
fontWeight = FontWeight.Medium
)
)

drawText(
textLayoutResult,
topLeft = Offset(
xDraw - textLayoutResult.size.width / 2,
yDraw + textPadding
)
)
}

val yTickRange = IntRange(
Expand All @@ -143,15 +149,25 @@ fun DrawScope.drawAxes(
// Offset(xDraw + halfTickLength, yDraw),
// lineWidth
// )
val textWidth = 200 / canvasScale
val textHeight = 40 / canvasScale

val textSize = 36 / canvasScale
val textPadding = 20 / canvasScale
drawText(
textMeasurer,

val textLayoutResult = textMeasurer.measure(
yDisplayValue,
topLeft = Offset(xDraw + textPadding, yDraw - textHeight / 2),
size = Size(textWidth, textHeight),
style = TextStyle(color = axesColor, fontWeight = FontWeight.Medium)
style = TextStyle(
color = axesColor,
fontSize = textSize.toSp(),
fontWeight = FontWeight.Medium
)
)

drawText(
textLayoutResult,
topLeft = Offset(
xDraw + textPadding,
yDraw - textLayoutResult.size.height / 2
)
)
}
}
Expand Down