Update HighlightStyle.Default constructor
This commit is contained in:
1 parent
8fe9c1828b
commit
feccbad6e5
4 files changed
+20
-8
No files matched your search
@@ -47,7 +47,7 @@ mavenPublishing {
|
||||
publishToMavenCentral()
|
||||
signAllPublications()
|
||||
|
||||
coordinates("io.github.kyant0", "backdrop", "1.0.2")
|
||||
coordinates("io.github.kyant0", "backdrop", "1.0.3")
|
||||
|
||||
pom {
|
||||
name.set("Backdrop")
|
||||
|
||||
@@ -161,6 +161,7 @@ half4 main(float2 coord) {
|
||||
internal const val DefaultHighlightShaderString = """
|
||||
uniform float2 size;
|
||||
uniform float4 cornerRadii;
|
||||
layout(color) uniform half4 color;
|
||||
uniform float angle;
|
||||
uniform float falloff;
|
||||
|
||||
@@ -176,7 +177,7 @@ half4 main(float2 coord) {
|
||||
float2 normal = float2(cos(angle), sin(angle));
|
||||
float d = dot(grad, normal);
|
||||
float intensity = pow(abs(d), falloff);
|
||||
return half4(1.0) * intensity;
|
||||
return color * intensity;
|
||||
}"""
|
||||
|
||||
@Language("AGSL")
|
||||
|
||||
@@ -11,6 +11,7 @@ import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.Shader
|
||||
import androidx.compose.ui.graphics.Shape
|
||||
import androidx.compose.ui.graphics.drawscope.DrawScope
|
||||
import androidx.compose.ui.graphics.toArgb
|
||||
import androidx.compose.ui.unit.LayoutDirection
|
||||
import androidx.compose.ui.util.fastCoerceAtMost
|
||||
import com.kyant.backdrop.AmbientHighlightShaderString
|
||||
@@ -46,14 +47,25 @@ interface HighlightStyle {
|
||||
|
||||
@Immutable
|
||||
data class Default(
|
||||
@param:FloatRange(from = 0.0, to = 1.0) val intensity: Float = 0.5f,
|
||||
override val color: Color = Color.White.copy(alpha = 0.5f),
|
||||
override val blendMode: BlendMode = BlendMode.Plus,
|
||||
val angle: Float = 45f,
|
||||
@param:FloatRange(from = 0.0) val falloff: Float = 1f
|
||||
) : HighlightStyle {
|
||||
|
||||
override val color: Color = Color.White.copy(alpha = intensity)
|
||||
|
||||
override val blendMode: BlendMode = BlendMode.Plus
|
||||
@Deprecated(
|
||||
"Use the constructor with color parameter instead.",
|
||||
ReplaceWith("HighlightStyle.Default(color = Color.White.copy(alpha = intensity), angle = angle, falloff = falloff)")
|
||||
)
|
||||
constructor(
|
||||
intensity: Float,
|
||||
angle: Float = 45f,
|
||||
falloff: Float = 1f
|
||||
) : this(
|
||||
color = Color.White.copy(alpha = intensity),
|
||||
angle = angle,
|
||||
falloff = falloff
|
||||
)
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.S)
|
||||
override fun DrawScope.createShader(
|
||||
@@ -67,6 +79,7 @@ interface HighlightStyle {
|
||||
).apply {
|
||||
setFloatUniform("size", size.width, size.height)
|
||||
setFloatUniform("cornerRadii", getCornerRadii(shape))
|
||||
setColorUniform("color", color.copy(alpha = 1f).toArgb())
|
||||
setFloatUniform("angle", angle * (PI / 180f).toFloat())
|
||||
setFloatUniform("falloff", falloff)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user