Skip to content

Commit

Permalink
Expose compose-color interop (#440)
Browse files Browse the repository at this point in the history
  • Loading branch information
cedrickcooke authored Jan 6, 2025
1 parent 1254f9e commit 965ecf6
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 10 deletions.
5 changes: 5 additions & 0 deletions compose/api/android/compose.api
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public final class com/juul/krayon/compose/ElementViewKt {
public static final fun ElementView (Lkotlinx/coroutines/flow/Flow;Lcom/juul/krayon/element/UpdateElement;Landroidx/compose/ui/Modifier;Landroidx/compose/runtime/Composer;II)V
}

public final class com/juul/krayon/compose/InteropKt {
public static final fun toCompose-Z7dcaks (I)J
public static final fun toKrayon-8_81llA (J)I
}

public final class com/juul/krayon/compose/KanvasKt {
public static final fun Kanvas (Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;I)V
}
Expand Down
2 changes: 2 additions & 0 deletions compose/api/compose.klib.api
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ final val com.juul.krayon.compose/com_juul_krayon_compose_ComposePathMarker$stab
final val com.juul.krayon.compose/com_juul_krayon_compose_ResourceCache$stableprop // com.juul.krayon.compose/com_juul_krayon_compose_ResourceCache$stableprop|#static{}com_juul_krayon_compose_ResourceCache$stableprop[0]
final val com.juul.krayon.compose/com_juul_krayon_compose_SkiaIsPointInPath$stableprop // com.juul.krayon.compose/com_juul_krayon_compose_SkiaIsPointInPath$stableprop|#static{}com_juul_krayon_compose_SkiaIsPointInPath$stableprop[0]

final fun (androidx.compose.ui.graphics/Color).com.juul.krayon.compose/toKrayon(): com.juul.krayon.color/Color // com.juul.krayon.compose/toKrayon|toKrayon@androidx.compose.ui.graphics.Color(){}[0]
final fun (com.juul.krayon.color/Color).com.juul.krayon.compose/toCompose(): androidx.compose.ui.graphics/Color // com.juul.krayon.compose/toCompose|toCompose@com.juul.krayon.color.Color(){}[0]
final fun <#A: kotlin/Any?> com.juul.krayon.compose/ElementView(androidx.compose.runtime/State<#A>, com.juul.krayon.element/UpdateElement<#A>, androidx.compose.ui/Modifier?, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int) // com.juul.krayon.compose/ElementView|ElementView(androidx.compose.runtime.State<0:0>;com.juul.krayon.element.UpdateElement<0:0>;androidx.compose.ui.Modifier?;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int){0§<kotlin.Any?>}[0]
final fun <#A: kotlin/Any?> com.juul.krayon.compose/ElementView(kotlin/Function0<#A>, com.juul.krayon.element/UpdateElement<#A>, androidx.compose.ui/Modifier?, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int) // com.juul.krayon.compose/ElementView|ElementView(kotlin.Function0<0:0>;com.juul.krayon.element.UpdateElement<0:0>;androidx.compose.ui.Modifier?;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int){0§<kotlin.Any?>}[0]
final fun <#A: kotlin/Any?> com.juul.krayon.compose/ElementView(kotlinx.coroutines.flow/Flow<#A>, com.juul.krayon.element/UpdateElement<#A>, androidx.compose.ui/Modifier?, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int) // com.juul.krayon.compose/ElementView|ElementView(kotlinx.coroutines.flow.Flow<0:0>;com.juul.krayon.element.UpdateElement<0:0>;androidx.compose.ui.Modifier?;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int){0§<kotlin.Any?>}[0]
Expand Down
5 changes: 5 additions & 0 deletions compose/api/desktop/compose.api
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public final class com/juul/krayon/compose/ElementViewKt {
public static final fun ElementView (Lkotlinx/coroutines/flow/Flow;Lcom/juul/krayon/element/UpdateElement;Landroidx/compose/ui/Modifier;Landroidx/compose/runtime/Composer;II)V
}

public final class com/juul/krayon/compose/InteropKt {
public static final fun toCompose-Z7dcaks (I)J
public static final fun toKrayon-8_81llA (J)I
}

public final class com/juul/krayon/compose/KanvasKt {
public static final fun Kanvas (Landroidx/compose/ui/Modifier;Lkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;I)V
}
Expand Down
6 changes: 0 additions & 6 deletions compose/src/commonMain/kotlin/AsComposeColor.kt

This file was deleted.

2 changes: 1 addition & 1 deletion compose/src/commonMain/kotlin/ComposeKanvas.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class ComposeKanvas internal constructor(
}

override fun drawColor(color: Color) {
scope.drawRect(color.asComposeColor())
scope.drawRect(color.toCompose())
}

override fun drawLine(startX: Float, startY: Float, endX: Float, endY: Float, paint: Paint) {
Expand Down
9 changes: 9 additions & 0 deletions compose/src/commonMain/kotlin/Interop.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.juul.krayon.compose

import androidx.compose.ui.graphics.toArgb
import com.juul.krayon.color.Color
import androidx.compose.ui.graphics.Color as ComposeColor

public fun Color.toCompose(): ComposeColor = ComposeColor(argb)

public fun ComposeColor.toKrayon(): Color = Color(toArgb())
6 changes: 3 additions & 3 deletions compose/src/commonMain/kotlin/Paint.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ internal fun Paint.toBrush(): Brush = when (this) {
is Paint.GradientAndStroke -> throw UnsupportedOperationException("GradientAndStroke cannot be converted to a singular brush.")
}

internal fun Paint.Fill.toBrush(): Brush = SolidColor(color.asComposeColor())
internal fun Paint.Fill.toBrush(): Brush = SolidColor(color.toCompose())

internal fun Paint.Stroke.toBrush(): Brush = SolidColor(color.asComposeColor())
internal fun Paint.Stroke.toBrush(): Brush = SolidColor(color.toCompose())

internal fun Paint.Gradient.toBrush(): Brush = when (this) {
is Paint.Gradient.Linear -> this.toBrush()
Expand All @@ -94,7 +94,7 @@ internal fun Paint.Gradient.toBrush(): Brush = when (this) {
}

private val Paint.Gradient.composeStops: Array<Pair<Float, ComposeColor>>
get() = Array(stops.size) { index -> stops[index].let { (offset, color) -> offset to color.asComposeColor() } }
get() = Array(stops.size) { index -> stops[index].let { (offset, color) -> offset to color.toCompose() } }

private fun Paint.Gradient.Linear.toBrush(): Brush = Brush.linearGradient(
*composeStops,
Expand Down

0 comments on commit 965ecf6

Please sign in to comment.