Skip to content

Commit

Permalink
fixes #16 fixes #8
Browse files Browse the repository at this point in the history
1.0.2 release
  • Loading branch information
yamin8000 committed Jan 23, 2024
1 parent ebcca26 commit aedbbe6
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 16 deletions.
4 changes: 1 addition & 3 deletions Gauge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/

private val artifact = "com.github.yamin8000.gauge"
private val version = "1.0.1"
private val version = "1.0.2"

plugins {
id("com.android.library")
Expand Down Expand Up @@ -74,9 +74,7 @@ android {
dependencies {
implementation(platform("androidx.compose:compose-bom:2023.10.01"))
implementation("androidx.compose.material3:material3")
// implementation("androidx.compose.foundation:foundation")
implementation("androidx.compose.ui:ui")
// implementation("androidx.compose.material3:material3-window-size-class")
implementation("androidx.compose.ui:ui-tooling-preview")
debugImplementation("androidx.compose.ui:ui-tooling")
}
Expand Down
25 changes: 17 additions & 8 deletions Gauge/src/main/java/com/github/yamin8000/gauge/main/Gauge.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@

package com.github.yamin8000.gauge.main

import androidx.compose.animation.animateColorAsState
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
Expand Down Expand Up @@ -103,7 +105,7 @@ fun Gauge(
ticksColors: GaugeTicksColors = GaugeTicksColors(
smallTicks = MaterialTheme.colorScheme.inversePrimary,
bigTicks = MaterialTheme.colorScheme.primary,
bigTicksLabels = MaterialTheme.colorScheme.tertiary
bigTicksLabels = MaterialTheme.colorScheme.primary
),
ticksColorProvider: (List<Pair<Int, Color>>) -> List<Pair<Int, Color>> = { it },
arcColorsProvider: (GaugeArcColors, Float, ClosedFloatingPointRange<Float>) -> GaugeArcColors = { _, _, _ -> arcColors }
Expand All @@ -112,7 +114,7 @@ fun Gauge(
require(numerics.sweepAngle in 1..360) { "Sweep angle: ${numerics.sweepAngle} must be from 1 to 360" }

BoxWithConstraints(
modifier = modifier,
modifier = modifier.padding(8.dp),
content = {
val textMeasurer = rememberTextMeasurer()
val size = if (totalSize > maxWidth) maxWidth
Expand All @@ -134,8 +136,15 @@ fun Gauge(
if (style.hasValueText) {
drawCompatibleText(
textMeasurer = textMeasurer,
text = "${decimalFormat.format(value)}\n$valueUnit".trim(),
topLeft = center.plus(Offset(0f, size.toPx() / 5)),
text = decimalFormat.format(value).trim(),
topLeft = center.plus(Offset(0f, size.toPx() / 12)),
color = valueColor,
totalSize = size
)
drawCompatibleText(
textMeasurer = textMeasurer,
text = valueUnit.trim(),
topLeft = center.plus(Offset(0f, size.toPx() / 7)),
color = valueColor,
totalSize = size
)
Expand Down Expand Up @@ -262,7 +271,7 @@ private fun DrawScope.drawTicks(
val isBigTick = isSmallTick && (value % numerics.bigTicksStep == 0)
val isStartOrEnd =
isBigTick && (degreeInt == numerics.startAngle || degreeInt == totalAngle)
val endRatio = if (isBigTick) size.toPx().div(6f) else size.toPx().div(7f)
val endRatio = if (isBigTick) size.toPx().div(5f) else size.toPx().div(6f)
val width = if (isBigTick) size.div(500f).toPx() else size.div(700f).toPx()
val tickColor = if (isBigTick) colors.bigTicks else ticksColors[value].second

Expand All @@ -288,7 +297,7 @@ private fun DrawScope.drawTicks(
)
}
if (hasNumbers && isBigTick) {
val textSizeFactor = 30f
val textSizeFactor = 20f
val textStyle = TextStyle(
color = colors.bigTicksLabels,
fontSize = size.toSp() / textSizeFactor
Expand All @@ -301,7 +310,7 @@ private fun DrawScope.drawTicks(
)
)
textOffset = textOffset.plus(
Offset(-1 * textSizeFactor * cos, -1 * textSizeFactor * sin)
Offset(-1f * textSizeFactor * cos, -1f * textSizeFactor * sin)
)
drawText(
textMeasurer = textMeasurer,
Expand Down Expand Up @@ -372,7 +381,7 @@ private fun DrawScope.drawCompatibleText(
textMeasurer: TextMeasurer,
topLeft: Offset
) {
val textSizeFactor = 30f
val textSizeFactor = 20f
val textStyle = TextStyle(
color = color,
fontSize = totalSize.toSp() / textSizeFactor
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ android {

dependencies {
implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2")
implementation("androidx.activity:activity-compose:1.8.0")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.7.0")
implementation("androidx.activity:activity-compose:1.8.2")
implementation(platform("androidx.compose:compose-bom:2023.10.01"))
implementation("androidx.compose.ui:ui")
implementation("androidx.compose.ui:ui-graphics")
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/com/github/yamin8000/gauge/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Slider
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
Expand Down Expand Up @@ -54,7 +56,9 @@ class MainActivity : ComponentActivity() {
modifier = Modifier.fillMaxSize(),
content = {
Column(
modifier = Modifier.padding(16.dp)
modifier = Modifier
.padding(16.dp)
.verticalScroll(rememberScrollState())
) {
val configuration = LocalConfiguration.current
val screenWidth = configuration.screenWidthDp.dp
Expand Down
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
*/

plugins {
id("com.android.application") version "8.1.2" apply false
id("com.android.application") version "8.2.1" apply false
id("com.android.library") version "8.2.1" apply false
id("org.jetbrains.kotlin.android") version "1.9.10" apply false
id("com.android.library") version "8.1.2" apply false
id("com.vanniktech.maven.publish") version "0.25.3"
}

0 comments on commit aedbbe6

Please sign in to comment.