### Glassmorphism Panel Example Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/LayerBackdropModifier.md An advanced example showcasing how to create a glassmorphism effect by capturing a gradient-filled box as a backdrop and applying blur, color controls, and opacity to a panel overlaid on it. ```kotlin @Composable fun GlassmorphismPanel() { val contentLayer = rememberLayerBackdrop() Column { // Content to capture as backdrop Box( modifier = Modifier .fillMaxWidth() .height(300.dp) .layerBackdrop(contentLayer) .background( brush = Brush.linearGradient( colors = listOf(Color.Blue, Color.Purple) ) ) ) // Glass panel with captured content as backdrop Box( modifier = Modifier .fillMaxWidth() .height(150.dp) .drawBackdrop( backdrop = contentLayer, shape = { RoundedCornerShape(12.dp) }, effects = { blur(radius = 16f) colorControls(brightness = 0.1f, saturation = 1.2f) opacity(0.8f) }, highlight = { Highlight.Default }, shadow = { Shadow.Default } ) .background(Color.White.copy(alpha = 0.1f)) .padding(16.dp), contentAlignment = Alignment.Center ) { Text( "Glass Panel", color = Color.White, fontSize = 20.sp, fontWeight = FontWeight.Bold ) } } } ``` -------------------------------- ### Usage of HighlightStyle.Plain Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/HighlightAndShadow.md Example of creating a Highlight instance using the `Plain` style. ```kotlin Highlight(style = HighlightStyle.Plain) ``` -------------------------------- ### Graphics Layer Configuration Example Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/DrawBackdropModifier.md This example shows how to customize compositing behavior using the optional layerBlock parameter within the drawBackdrop modifier. It demonstrates setting alpha, rotation, and scale for the backdrop layer. ```kotlin Modifier.drawBackdrop( backdrop = ..., shape = ..., effects = ..., layerBlock = { alpha = 0.9f rotationZ = 10f scaleX = 1.05f scaleY = 1.05f } ) ``` -------------------------------- ### Layer-Backed Backdrop Example Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/README.md Demonstrates capturing content into a layer backdrop and then using that captured content as a backdrop for another composable with blur effect. ```kotlin val contentLayer = rememberLayerBackdrop() // Capture content Box( modifier = Modifier .layerBackdrop(contentLayer) .background(Color.Blue) ) // Use as backdrop elsewhere Box( modifier = Modifier.drawBackdrop( backdrop = contentLayer, shape = { RoundedCornerShape(12.dp) }, effects = { blur(16f) } ) ) ``` -------------------------------- ### Layer Backdrop Example Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/GettingStarted.md Creates a glass panel that displays captured content from a layer backdrop. Use this to achieve depth effects. ```kotlin import androidx.compose.foundation.background import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.compose.ui.text.font.FontWeight import com.liquidmetal.liquidglass.compose.drawBackdrop import com.liquidglass.liquidglass.compose.emptyBackdrop import com.liquidglass.liquidglass.compose.rememberLayerBackdrop import com.liquidglass.liquidglass.compose.effects.blur import com.liquidglass.liquidglass.compose.effects.colorControls import com.liquidglass.liquidglass.compose.highlight.Highlight @Composable fun LayerBackdropExample() { val contentLayer = rememberLayerBackdrop() Column( modifier = Modifier.fillMaxSize() ) { // Source content (captured as backdrop) Box( modifier = Modifier .fillMaxWidth() .weight(1f) .layerBackdrop(contentLayer) .background( brush = Brush.linearGradient( colors = listOf( Color(0xFF667eea), Color(0xFF764ba2) ) ) ) ) // Glass panel with captured content Box( modifier = Modifier .fillMaxWidth() .height(200.dp) .drawBackdrop( backdrop = contentLayer, shape = { RoundedCornerShape(topStart = 24.dp, topEnd = 24.dp) }, effects = { blur(radius = 20f) colorControls(brightness = 0.15f) }, highlight = { Highlight.Default } ) .background(Color.White.copy(alpha = 0.1f)), contentAlignment = Alignment.Center ) { Text( "Glass Panel", color = Color.White, fontSize = 20.sp, fontWeight = FontWeight.Bold ) } } } ``` -------------------------------- ### Layered Gradients Example Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/BackdropComposables.md Demonstrates using `rememberCombinedBackdrop` to layer two gradient backdrops. The backdrops are drawn front-to-back in the order they are provided. ```kotlin @Composable fun LayeredBackdrop() { val gradient1 = rememberCanvasBackdrop { drawRect( brush = Brush.linearGradient( colors = listOf(Color.Blue, Color.Transparent), start = Offset.Zero, end = Offset(0f, size.height) ), size = size ) } val gradient2 = rememberCanvasBackdrop { drawRect( brush = Brush.linearGradient( colors = listOf(Color.Red.copy(alpha = 0.3f), Color.Transparent), start = Offset(size.width, 0f), end = Offset(0f, 0f) ), size = size ) } val combined = rememberCombinedBackdrop(gradient1, gradient2) Box( modifier = Modifier .size(200.dp) .drawBackdrop( backdrop = combined, shape = { RoundedCornerShape(12.dp) }, effects = { blur(8f) } ) ) } ``` -------------------------------- ### Usage of HighlightStyle.Default Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/HighlightAndShadow.md Example of configuring a Highlight with a custom `Default` style, specifying color, angle, and falloff. ```kotlin Highlight( style = HighlightStyle.Default( color = Color.White.copy(alpha = 0.7f), angle = 315f, // Top-left light source falloff = 2f ) ) ``` -------------------------------- ### Base With Overlay Example Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/BackdropComposables.md Illustrates combining a base backdrop with an overlay backdrop using `rememberCombinedBackdrop`. This creates a layered effect where the overlay is drawn on top of the base. ```kotlin @Composable fun BaseWithOverlay() { val base = rememberCanvasBackdrop { drawRect(Color(0xFF1A1A1A), size = size) } val overlay = rememberCanvasBackdrop { drawCircle( color = Color.White.copy(alpha = 0.1f), radius = 100f, center = size.center ) } val combined = rememberCombinedBackdrop(base, overlay) Box( modifier = Modifier .size(250.dp) .drawBackdrop( backdrop = combined, shape = { RoundedCornerShape(16.dp) }, effects = { blur(12f) } ) ) } ``` -------------------------------- ### Usage of HighlightStyle.Ambient Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/HighlightAndShadow.md Example of applying an ambient highlight with a specified intensity level. ```kotlin Highlight(style = HighlightStyle.Ambient(intensity = 0.5f)) ``` -------------------------------- ### Custom Canvas Backdrop Example Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/GettingStarted.md Create a backdrop using a custom canvas with a gradient and a decorative circle. Applies color controls effect. ```kotlin @Composable fun CustomBackdropExample() { val customBackdrop = rememberCanvasBackdrop { // Draw gradient background drawRect( brush = Brush.linearGradient( colors = listOf(Color.Blue, Color.Purple), start = Offset.Zero, end = Offset(size.width, size.height) ), size = size ) // Draw decorative circle drawCircle( color = Color.White.copy(alpha = 0.1f), radius = 100f, center = size.center ) } Box( modifier = Modifier .size(300.dp) .drawBackdrop( backdrop = customBackdrop, shape = { RoundedCornerShape(16.dp) }, effects = { colorControls(brightness = 0.2f) } ) ) } ``` -------------------------------- ### Full Glassmorphism Card Example Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/README.md Applies a full Glassmorphism effect to a card using drawBackdrop with blur, color controls, opacity, highlight, and shadow. ```kotlin Modifier.drawBackdrop( backdrop = emptyBackdrop(), shape = { RoundedCornerShape(20.dp) }, effects = { blur(radius = 20f) colorControls(brightness = 0.1f, saturation = 1.2f) opacity(0.9f) }, highlight = { Highlight.Default }, shadow = { Shadow.Default }, innerShadow = { InnerShadow.Default } ) ``` -------------------------------- ### Tinted Backdrop Example Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/BackdropComposables.md Demonstrates how to use `rememberBackdrop` to apply a tint to a base backdrop. The `onDraw` lambda draws the base backdrop and then applies a semi-transparent red overlay. ```kotlin @Composable fun TintedBackdrop() { val baseBackdrop = rememberCanvasBackdrop { drawRect(Color.Blue, size = size) } val tintedBackdrop = rememberBackdrop( backdrop = baseBackdrop, onDraw = { it() // Draw the base backdrop drawRect( color = Color.Red.copy(alpha = 0.3f), size = size ) } ) Box( modifier = Modifier .size(200.dp) .drawBackdrop( backdrop = tintedBackdrop, shape = { RoundedCornerShape(12.dp) }, effects = { blur(8f) } ) ) } ``` -------------------------------- ### Example Usage of Combined Backdrop Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/BackdropInterface.md Demonstrates combining two canvas backdrops, one drawing a blue rectangle and the other a red rectangle, into a single backdrop. ```kotlin val combined = rememberCombinedBackdrop( rememberCanvasBackdrop { drawRect(Color.Blue) }, rememberCanvasBackdrop { drawRect(Color.Red) } ) ``` -------------------------------- ### DrawBackdrop Modifier Usage Example Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/DrawBackdropModifier.md Example demonstrating how to use the `drawBackdrop` modifier with custom shape, blur, color controls, highlight, shadow, and inner shadow. ```kotlin Modifier.drawBackdrop( backdrop = emptyBackdrop(), shape = { RoundedCornerShape(12.dp) }, effects = { blur(radius = 8f) colorControls(brightness = 0.1f, saturation = 1.2f) }, highlight = { Highlight.Default }, shadow = { Shadow.Default }, innerShadow = { InnerShadow.Default } ) ``` -------------------------------- ### Color Adjustment Example Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/GettingStarted.md Applies color controls like brightness, contrast, and saturation to a backdrop effect. Use sliders to adjust these parameters in real-time. ```kotlin import androidx.compose.foundation.background import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.Slider import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableFloatStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.dp import com.liquidmetal.liquidglass.compose.drawBackdrop import com.liquidmetal.liquidglass.compose.emptyBackdrop import com.liquidmetal.liquidglass.compose.effects.blur import com.liquidglass.liquidglass.compose.effects.colorControls @Composable fun ColorAdjustmentExample() { var brightness by remember { mutableFloatStateOf(0f) } var contrast by remember { mutableFloatStateOf(1f) } var saturation by remember { mutableFloatStateOf(1f) } Column( modifier = Modifier .fillMaxSize() .padding(16.dp) ) { Box( modifier = Modifier .fillMaxWidth() .height(200.dp) .drawBackdrop( backdrop = emptyBackdrop(), shape = { RoundedCornerShape(12.dp) }, effects = { blur(radius = 16f) colorControls( brightness = brightness, contrast = contrast, saturation = saturation ) } ) .background(Color(0xFFE53935), RoundedCornerShape(12.dp)) ) // Sliders for controls SliderWithLabel("Brightness", brightness, -1f, 1f) { brightness = it } SliderWithLabel("Contrast", contrast, 0f, 2f) { contrast = it } SliderWithLabel("Saturation", saturation, 0f, 2f) { saturation = it } } } @Composable fun SliderWithLabel( label: String, value: Float, min: Float, max: Float, onValueChange: (Float) -> Unit ) { Column(modifier = Modifier.padding(vertical = 8.dp)) { Text("$label: ${"%.2f".format(value)}") Slider( value = value, onValueChange = onValueChange, valueRange = min..max, modifier = Modifier.fillMaxWidth() ) } } ``` -------------------------------- ### Example Usage of Canvas Backdrop Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/BackdropInterface.md Demonstrates how to create and apply a canvas backdrop that draws a blue rectangle. The backdrop is applied to a composable using the drawBackdrop modifier. ```kotlin val blueBackdrop = rememberCanvasBackdrop { drawRect(Color.Blue, size = size) } Modifier.drawBackdrop(blueBackdrop, { RoundedCornerShape(8.dp) }) { // effects } ``` -------------------------------- ### Effect Scope Example Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/README.md Demonstrates applying multiple render effects sequentially within the effects lambda, including blur, color controls, and lens refraction. ```kotlin effects = { blur(8f) // 1st effect colorControls(brightness = 0.2f) // 2nd effect lens(40f, 15f, depthEffect = true) // 3rd effect } ``` -------------------------------- ### Incorrect Lens Effect Usage with CircleShape (Resolution Example) Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/errors.md Illustrates the incorrect usage of the lens effect with CircleShape, which is not supported and will lead to an UnsupportedOperationException. This serves as a negative example for resolution. ```kotlin // ✗ Wrong: CircleShape not supported Modifier.drawBackdrop( backdrop = ..., shape = { CircleShape }, effects = { lens(40f, 15f) // Throws UnsupportedOperationException } ) ``` -------------------------------- ### Apply Highlight to Backdrop Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/HighlightAndShadow.md Example of applying a custom highlight effect to a backdrop using the `drawBackdrop` modifier. ```kotlin Modifier.drawBackdrop( backdrop = emptyBackdrop(), shape = { RoundedCornerShape(12.dp) }, effects = { blur(8f) }, highlight = { Highlight(width = 1f.dp, alpha = 0.8f) } ) ``` -------------------------------- ### Maven Central Dependency Setup Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/README.md Adds the Android Liquid Glass library to your project's dependencies by configuring Maven Central repository and adding the implementation. ```kotlin repositories { mavenCentral() } dependencies { implementation("io.github.kyant0:backdrop:2.0.0") } ``` -------------------------------- ### Scaled Backdrop Example Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/BackdropComposables.md Shows how to use `rememberBackdrop` to scale a backdrop. The `onDraw` lambda saves the canvas state, scales it, draws the base backdrop, and then restores the canvas state. ```kotlin @Composable fun ScaledBackdrop() { val baseBackdrop = rememberCanvasBackdrop { drawCircle(Color.Green, radius = 50f) } val scaledBackdrop = rememberBackdrop( backdrop = baseBackdrop, onDraw = { save() scale(2f, 2f, pivot = size.center) it() restore() } ) Box( modifier = Modifier .size(200.dp) .drawBackdrop( backdrop = scaledBackdrop, shape = { CircleShape }, effects = { } ) ) } ``` -------------------------------- ### drawPlainBackdrop Usage Example Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/DrawBackdropModifier.md An example demonstrating how to use the drawPlainBackdrop modifier with a canvas backdrop, a circular shape, and a blur effect. This is useful for creating visually distinct background elements. ```kotlin Modifier.drawPlainBackdrop( backdrop = rememberCanvasBackdrop { drawCircle(Color.Blue) }, shape = { CircleShape }, effects = { blur(4f) } ) ``` -------------------------------- ### Usage Example for Runtime Capability Detection Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/PlatformSupport.md Use the `isRenderEffectSupported` and `isRuntimeShaderSupported` functions to conditionally apply effects like blur and lens. Blur is available on API 31+ and lens on platforms with shader support. ```kotlin effects = { if (isRenderEffectSupported()) { blur(8f) // Only on API 31+ } if (isRuntimeShaderSupported()) { lens(40f, 15f) // Only on platforms with shader support } } ``` -------------------------------- ### Custom AGSL Shader Example Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/GettingStarted.md Applies a custom AGSL shader effect to create dynamic visual distortions, such as a wave effect. Requires runtime shader support. ```kotlin import androidx.compose.foundation.background import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.size import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableFloatStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.dp import kotlinx.coroutines.delay import com.liquidmetal.liquidglass.compose.drawBackdrop import com.liquidmetal.liquidglass.compose.emptyBackdrop import com.liquidmetal.liquidglass.compose.effects.runtimeShaderEffect import com.liquidmetal.liquidglass.compose.isRuntimeShaderSupported @Composable fun CustomShaderExample() { val customShader = """ uniform shader content; uniform float time; half4 main(float2 coord) { half4 color = content.eval(coord); // Add a subtle wave distortion float wave = sin(coord.y * 0.01 + time) * 2.0; return content.eval(coord + float2(wave, 0.0)); } """.trimIndent() var time by remember { mutableFloatStateOf(0f) } LaunchedEffect(Unit) { while (true) { delay(16) // ~60 FPS time += 0.016f } } Box( modifier = Modifier .size(300.dp) .drawBackdrop( backdrop = emptyBackdrop(), shape = { RoundedCornerShape(12.dp) }, effects = { if (isRuntimeShaderSupported()) { runtimeShaderEffect( key = "waveEffect", shaderString = customShader, uniformShaderName = "content" ) { setFloatUniform("time", time) } } } ) .background(Color(0xFF1A1A1A), RoundedCornerShape(12.dp)) ) } ``` -------------------------------- ### Animating Inner Shadow Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/HighlightAndShadow.md Example demonstrating how to animate an InnerShadow using `Animatable` and `LaunchedEffect`. This allows for dynamic changes in the inner shadow's appearance over time. ```kotlin import androidx.compose.animation.core.Animatable import androidx.compose.animation.core.tween import androidx.compose.runtime.remember import androidx.compose.runtime.LaunchedEffect val animatedShadow = remember { Animatable(InnerShadow.Default) } LaunchedEffect(Unit) { animatedShadow.animateTo( InnerShadow(radius = 8.dp, alpha = 0.5f), animationSpec = tween(300) ) } Modifier.drawBackdrop( backdrop = emptyBackdrop(), shape = { RoundedCornerShape(12.dp) }, effects = { blur(8f) }, innerShadow = { animatedShadow.value } ) ``` -------------------------------- ### Catching UnsupportedOperationException for Lens Effect Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/errors.md Provides an example of how to catch the UnsupportedOperationException that may be thrown when using the lens effect with an unsupported shape. This allows for graceful error handling. ```kotlin try { // Rendering with unsupported shape and lens effect } catch (e: UnsupportedOperationException) { Log.e("Backdrop", "Lens effect not supported: ${e.message}") // Fallback to blur or other effects } ``` -------------------------------- ### Applying a Shadow Effect Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/HighlightAndShadow.md Example of how to apply a custom drop shadow to a composable using the Modifier.drawBackdrop function. This snippet demonstrates configuring the shadow's radius and offset. ```kotlin Modifier.drawBackdrop( backdrop = emptyBackdrop(), shape = { RoundedCornerShape(12.dp) }, effects = { blur(8f) }, shadow = { Shadow(radius = 16.dp, offset = DpOffset(2.dp, 4.dp)) } ) ``` -------------------------------- ### Stacking Multiple Backdrop Effects Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/BackdropEffectScope.md Demonstrates how to apply multiple effects sequentially to a backdrop. Effects are applied in the order they are called, transforming the backdrop through each effect. ```kotlin effects = { blur(8f) // 1st: blur applied colorControls(brightness = 0.1f) // 2nd: color adjustment lens(40f, 15f, depthEffect = true) // 3rd: lens refraction } ``` -------------------------------- ### Basic Usage Pattern for LayerBackdrop Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/LayerBackdropModifier.md Demonstrates the typical pattern of creating a LayerBackdrop, applying it to a source composable to capture its content, and then using that captured content as a backdrop for another composable with effects. ```kotlin // 1. Create a LayerBackdrop to hold captured content val layerBackdrop = rememberLayerBackdrop() // 2. Apply it to the source composable (the one to capture) Box( modifier = Modifier .size(100.dp) .layerBackdrop(layerBackdrop) .background(Color.Blue) ) // 3. Use the captured content as a backdrop elsewhere Box( modifier = Modifier .size(200.dp) .drawBackdrop( backdrop = layerBackdrop, shape = { RoundedCornerShape(12.dp) }, effects = { blur(8f) } ) .background(Color.White) ) ``` -------------------------------- ### obtainRuntimeShader Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/RuntimeShader.md Retrieves a cached RuntimeShader or compiles and caches a new one if it doesn't exist. This is the primary method for getting a shader instance. ```APIDOC ## obtainRuntimeShader ### Description Get or compile a cached shader. If a shader with the given key exists in the cache, return it; otherwise compile and cache it. ### Method Signature ```kotlin fun obtainRuntimeShader(key: String, @Language("AGSL") string: String): RuntimeShader ``` ### Parameters #### Path Parameters - **key** (String) - Required - Cache key. Must be unique per shader variant. Reuse the same key across frames to avoid recompilation. - **string** (String) - Required - AGSL source code. Ignored if shader is cached. ### Return Compiled `RuntimeShader` (cached or newly compiled). ### Example ```kotlin val shader = cache.obtainRuntimeShader( key = "myBlurEffect", string = """ uniform shader content; uniform float blur; half4 main(float2 coord) { // blur implementation return half4(1.0); } """.trimIndent() ) ``` ``` -------------------------------- ### Highlight Constructor Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/HighlightAndShadow.md Provides a direct way to instantiate the Highlight data class with custom parameters. ```kotlin Highlight( width: Dp = 0.5f.dp, blurRadius: Dp = width / 2f, alpha: Float = 1f, style: HighlightStyle = HighlightStyle.Default ) ``` -------------------------------- ### Import Core Backdrop Classes Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/GettingStarted.md Import the necessary classes from the Backdrop library to use its features. ```kotlin import com.kyant.backdrop.* import com.kyant.backdrop.backdrops.* import com.kyant.backdrop.effects.* import com.kyant.backdrop.highlight.* import com.kyant.backdrop.shadow.* ``` -------------------------------- ### Explicitly Checking Render Effect Support Before Applying Blur Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/errors.md Demonstrates best practice by explicitly checking if render effects are supported before applying the blur effect. This allows for alternative handling or graceful degradation. ```kotlin effects = { if (isRenderEffectSupported()) { blur(8f) } else { // Use alternative effect or do nothing Log.d("Backdrop", "Blur not supported on this platform") } } ``` -------------------------------- ### Switch Between Dynamic Highlight Styles Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/GettingStarted.md Demonstrates switching between different highlight styles (Default, Ambient, Plain) for a liquid glass effect. Uses `remember` and `mutableStateOf` to manage the selected style. Requires `drawBackdrop` and `Highlight` objects. ```kotlin import androidx.compose.foundation.background import androidx.compose.foundation.layout.* import androidx.compose.foundation.shape.CircleShape import androidx.compose.material3.Button import androidx.compose.material3.Text import androidx.compose.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.dp import com.liquidmetal.liquidglass.compose.drawBackdrop import com.liquidglass.liquidglass.compose.effects.blur import com.liquidglass.liquidglass.compose.effects.colorControls import com.liquidglass.liquidglass.compose.emptyBackdrop import com.liquidglass.liquidglass.compose.highlight.Highlight import com.liquidglass.liquidglass.compose.shadow.Shadow @Composable fun HighlightStylesExample() { var selectedStyle by remember { mutableStateOf(0) } val styles = listOf( { Highlight.Default }, { Highlight.Ambient }, { Highlight.Plain } ) Column( modifier = Modifier .fillMaxSize() .padding(16.dp), horizontalAlignment = Alignment.CenterHorizontally ) { Box( modifier = Modifier .size(200.dp) .drawBackdrop( backdrop = emptyBackdrop(), shape = { CircleShape }, effects = { blur(radius = 16f) colorControls(brightness = 0.15f, saturation = 1.3f) }, highlight = styles[selectedStyle], shadow = { Shadow.Default } ) .background(Color(0xFF3A3A3A), CircleShape) ) Row( modifier = Modifier .fillMaxWidth() .padding(top = 24.dp), horizontalArrangement = Arrangement.SpaceEvenly ) { Button(onClick = { selectedStyle = 0 }) { Text("Default") } Button(onClick = { selectedStyle = 1 }) { Text("Ambient") } Button(onClick = { selectedStyle = 2 }) { Text("Plain") } } } } ``` -------------------------------- ### HighlightStyle.Ambient Implementation Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/HighlightAndShadow.md Provides a soft ambient highlight for general illumination without a specific direction. Control the light intensity. ```kotlin @Immutable data class Ambient( @param:FloatRange(from = 0.0, to = 1.0) val intensity: Float = 0.38f ) : HighlightStyle { override val color: Color = Color.White.copy(alpha = intensity) override val blendMode: BlendMode = DrawScope.DefaultBlendMode } ``` -------------------------------- ### HighlightStyle.Plain Implementation Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/HighlightAndShadow.md Represents a simple, flat-color highlight without complex shader effects. Customize its color and blend mode. ```kotlin @Immutable data class Plain( override val color: Color = Color.White.copy(alpha = 0.38f), override val blendMode: BlendMode = BlendMode.Plus ) : HighlightStyle ``` -------------------------------- ### Obtain and Cache a RuntimeShader Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/RuntimeShader.md Get or compile a cached shader using a unique key and AGSL source code. Reuse the same key across frames to avoid recompilation. ```kotlin fun obtainRuntimeShader(key: String, @Language("AGSL") string: String): RuntimeShader ``` ```kotlin val shader = cache.obtainRuntimeShader( key = "myBlurEffect", string = """ uniform shader content; uniform float blur; half4 main(float2 coord) { // blur implementation return half4(1.0); } """.trimIndent() ) ``` -------------------------------- ### Remember Backdrop Wrapper Creation Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/BackdropInterface.md Wraps an existing backdrop with custom drawing logic that executes before the wrapped backdrop. The custom drawing logic is provided as a lambda. ```kotlin @Composable fun rememberBackdrop( backdrop: Backdrop, onDraw: DrawScope.(drawBackdrop: DrawScope.() -> Unit) -> Unit ): Backdrop ``` -------------------------------- ### Empty Backdrop Implementation Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/BackdropInterface.md Provides a backdrop that draws nothing. Use this implementation when you need to disable backdrop effects. ```kotlin fun emptyBackdrop(): Backdrop ``` -------------------------------- ### Invalid Highlight Alpha Usage Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/errors.md Shows an example of using an alpha value outside the valid range [0.0, 1.0] for the Highlight parameter. The library does not enforce this at runtime, and values outside the range may render unexpectedly. ```kotlin // ❌ Not recommended: alpha outside [0, 1] Highlight(alpha = 2.5f) // Renders but may clip unexpectedly // ✓ Correct: alpha within valid range Highlight(alpha = 1f) ``` -------------------------------- ### Logging Platform Capability Checks Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/errors.md General logging statements to check and log the support status of RenderEffect and RuntimeShader features on the current platform. ```kotlin Log.d("Backdrop", "Render effect supported: ${isRenderEffectSupported()}") Log.d("Backdrop", "Runtime shader supported: ${isRuntimeShaderSupported()}") ``` -------------------------------- ### Add Backdrop Dependency Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/GettingStarted.md Add the Backdrop library dependency to your project's build.gradle.kts file. ```kotlin kotlin { sourceSets { commonMain.dependencies { implementation("io.github.kyant0:backdrop:2.0.0") } } } ``` -------------------------------- ### AGSL Main Function Signature Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/RuntimeShader.md Defines the entry point for an AGSL shader. It takes a 2D coordinate and returns a half4 color. ```glsl half4 main(float2 coord) { // coord = pixel coordinate in the canvas // return pixel color as half4 (RGBA) } ``` -------------------------------- ### Testing Platform Capability Checks Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/errors.md Unit test demonstrating how to conditionally test rendering features based on the availability of platform capabilities like RenderEffect. ```kotlin @Test fun testPlatformCapability() { if (isRenderEffectSupported()) { // Test blur and other render effects } else { // Test fallback behavior } } ``` -------------------------------- ### Custom Backdrop with Gradient Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/README.md Creates a custom backdrop using a linear gradient and applies it to a composable with specific shape and color control effects. ```kotlin val backdrop = rememberCanvasBackdrop { drawRect( brush = Brush.linearGradient(colors = listOf(Color.Blue, Color.Purple)), size = size ) } Modifier.drawBackdrop( backdrop = backdrop, shape = { RoundedCornerShape(16.dp) }, effects = { colorControls(brightness = 0.15f) } ``` -------------------------------- ### Exception Handling for Lens Effects Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/errors.md Shows how to use a try-catch block to handle UnsupportedOperationException when applying lens effects, falling back to a blur effect for unsupported shapes. ```kotlin if (shapeProvider.shape is CornerBasedShape) { effects = { try { lens(40f, 15f) } catch (e: UnsupportedOperationException) { Log.w("Backdrop", "Shape doesn't support lens effect, using blur instead") blur(8f) } } } else { effects = { blur(8f) // Fallback for non-rounded shapes } } ``` -------------------------------- ### Handling Platform-Specific Rendering Features Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/errors.md Illustrates conditional application of rendering effects like blur and color controls based on platform support for RenderEffect and RuntimeShader. ```kotlin effects = { if (isRenderEffectSupported()) { blur(16f) colorControls(brightness = 0.2f) } if (isRuntimeShaderSupported()) { lens(40f, 15f, depthEffect = true) } else { blur(12f) // Fallback to blur on platforms without shaders } } ``` -------------------------------- ### Provide Fallbacks for Unsupported Platforms Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/GettingStarted.md Implement fallback effects, like `opacity`, for scenarios where a specific effect, such as `blur`, is not supported by the platform. ```kotlin effects = { if (isRenderEffectSupported()) { blur(16f) } else { opacity(0.8f) // Fallback } } ``` -------------------------------- ### Create a Canvas Backdrop Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/BackdropComposables.md Use `rememberCanvasBackdrop` to create a backdrop that executes custom drawing code on each frame. This is the simplest way to define a custom backdrop. Ensure stable lambdas or use `remember` if passing derived state for optimal recomposition. ```kotlin import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.size import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableFloatStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.draw.blur import androidx.compose.ui.draw.drawBackdrop import androidx.compose.ui.geometry.Offset import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.drawscope.DrawScope import androidx.compose.ui.graphics.drawscope.drawIntoCanvas import androidx.compose.ui.graphics.drawscope.save import androidx.compose.ui.graphics.drawscope.restore import androidx.compose.ui.graphics.drawscope.translate import androidx.compose.ui.graphics.drawscope.rotate import androidx.compose.ui.unit.dp import com.kyant.backdrop.backdrops.rememberCanvasBackdrop import kotlinx.coroutines.delay @Composable fun GradientBackdrop() { val backdrop = rememberCanvasBackdrop { drawRect( brush = Brush.linearGradient( colors = listOf(Color.Blue, Color.Purple), start = Offset.Zero, end = Offset(size.width, size.height) ), size = size ) } Box( modifier = Modifier .size(300.dp) .drawBackdrop( backdrop = backdrop, shape = { RoundedCornerShape(12.dp) }, effects = { blur(8f) } ) ) } @Composable fun AnimatedCircleBackdrop() { var rotation by remember { mutableFloatStateOf(0f) } LaunchedEffect(Unit) { while (true) { delay(16) rotation = (rotation + 2f) % 360f } } val backdrop = rememberCanvasBackdrop { save() translate(size.width / 2, size.height / 2) rotate(rotation) drawCircle(Color.Blue, radius = 50f) restore() } Box( modifier = Modifier .size(200.dp) .drawBackdrop( backdrop = backdrop, shape = { CircleShape }, effects = { } ) ) } ``` -------------------------------- ### Gradle Dependency Configuration for Kotlin Multiplatform Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/PlatformSupport.md Configure the Backdrop library dependency in your project's build.gradle.kts file. Ensure the minimum SDK version for Android is set to 21. ```kotlin // build.gradle.kts kotlin { android { minSdk = 21 } iosArm64("iosArm64") iosSimulatorArm64("iosSimulatorArm64") macosArm64() jvm("desktop") sourceSets { commonMain.dependencies { implementation("io.github.kyant0:backdrop:2.0.0") } } } ``` -------------------------------- ### Use Stable Lambdas for Backdrop Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/BackdropComposables.md Employ stable lambdas for backdrop creation to optimize recomposition performance. This includes using `remember` with dependencies or ensuring lambda parameters are stable. ```kotlin // ✓ Good: Stable lambda val backdrop = rememberCanvasBackdrop { drawRect(Color.Blue, size = size) } // ✓ Good: Lambda with memoized state var color by remember { mutableStateOf(Color.Blue) } val backdrop = remember(color) { rememberCanvasBackdrop { drawRect(color, size = size) } } // ⚠ Less efficient: Derived state without remember val backdrop = rememberCanvasBackdrop { drawRect(someComputedColor(), size = size) } ``` -------------------------------- ### Check Platform Support for Features Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/GettingStarted.md Always verify feature compatibility using capability flags like `isRuntimeShaderSupported()` before applying effects like `lens`. ```kotlin if (isRuntimeShaderSupported()) { lens(40f, 15f) // Only on supported platforms } ``` -------------------------------- ### Create an Empty Backdrop Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/BackdropComposables.md Use `emptyBackdrop()` to create a backdrop that draws nothing. This is useful as a placeholder or to disable backdrop drawing while retaining effect configuration. ```kotlin fun emptyBackdrop(): Backdrop ``` ```kotlin @Composable fun EffectsOnlyModifier() { Box( modifier = Modifier .size(200.dp) .drawBackdrop( backdrop = emptyBackdrop(), // No backdrop drawing shape = { RoundedCornerShape(12.dp) }, effects = { blur(16f) colorControls(brightness = 0.2f) }, highlight = { Highlight.Default }, shadow = { Shadow.Default } ) .background(Color(0xFF333333)) ) } ``` -------------------------------- ### opacity Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/BackdropEffectScope.md Applies transparency to the backdrop. ```APIDOC ## opacity ### Description Applies transparency to the backdrop. ### Method `opacity(alpha: Float)` ### Parameters #### Parameters - **alpha** (Float) - Required - Opacity: 0 = fully transparent, 1 = fully opaque. Range: 0.0–1.0. ### Example ```kotlin effects = { opacity(0.5f) // 50% transparent } ``` ``` -------------------------------- ### Creating a RuntimeShader Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/RuntimeShader.md Use the RuntimeShader() function to compile AGSL code. The shader string must define a main function returning half4. ```kotlin expect fun RuntimeShader(@Language("AGSL") shaderString: String): RuntimeShader ``` ```kotlin val shader = RuntimeShader(""" uniform shader content; uniform float intensity; half4 main(float2 coord) { half4 color = content.eval(coord); return color * intensity; } """.trimIndent()) sHADER.setFloatUniform("intensity", 0.8f) ``` -------------------------------- ### Compose Complex Backdrops Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/BackdropComposables.md Build intricate backdrop effects by composing simpler backdrop composables. Use `rememberCombinedBackdrop` to merge multiple backdrops efficiently. ```kotlin @Composable fun ComplexBackdrop( baseColor: Color, enableOverlay: Boolean ) { val base = rememberCanvasBackdrop { drawRect(baseColor, size = size) } val backdrop = if (enableOverlay) { val overlay = rememberCanvasBackdrop { drawRect( Color.White.copy(alpha = 0.1f), size = size ) } rememberCombinedBackdrop(base, overlay) } else { base } return backdrop } ``` -------------------------------- ### Remember Layer Backdrop Creation Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/BackdropInterface.md Creates a memoized backdrop that is backed by a graphics layer. This is useful for complex or animated content and is dependent on layout coordinates. ```kotlin @Composable fun rememberLayerBackdrop( graphicsLayer: GraphicsLayer = rememberGraphicsLayer(), onDraw: ContentDrawScope.() -> Unit = DefaultOnDraw ): LayerBackdrop ``` -------------------------------- ### HighlightStyle.Plain Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/types.md Represents a simple flat-color highlight without shader effects. ```APIDOC ## HighlightStyle.Plain ### Description Simple flat-color highlight without shader effects. ### Properties - `color: Color` - Highlight color (Default: Color.White.copy(alpha = 0.38f)) - `blendMode: BlendMode` - Blend mode (how it combines with backdrop) (Default: BlendMode.Plus) ``` -------------------------------- ### Manually Apply RuntimeShader Effect Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/RuntimeShader.md Manually create a RuntimeShader and apply it as an effect. This involves obtaining the shader, setting uniforms, and then creating a RuntimeShaderEffect. ```kotlin effects = { val shader = obtainRuntimeShader("key", shaderString) shader.setFloatUniform("param", value) effect(RuntimeShaderEffect(shader, "content")) } ``` -------------------------------- ### Highlight Data Class Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/types.md Configuration for a specular (shiny) light reflection on the surface. Allows customization of width, blur, alpha, and style. ```APIDOC ## Highlight Data Class ### Description Configuration for a specular (shiny) light reflection on the surface. Allows customization of width, blur, alpha, and style. ### Fields - `width: Dp` - Required - Thickness of the highlight stroke (Default: 0.5.dp) - `blurRadius: Dp` - Required - Blur applied to the highlight (Default: width / 2f) - `alpha: Float` - Required - Opacity (0–1) (Default: 1f) - `style: HighlightStyle` - Required - Visual style (Plain, Default, Ambient) (Default: HighlightStyle.Default) ``` -------------------------------- ### Highlight Data Class Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/HighlightAndShadow.md Defines a specular light reflection on the surface. Customize width, blur, alpha, and style. ```kotlin @Immutable data class Highlight( val width: Dp = 0.5f.dp, val blurRadius: Dp = width / 2f, @param:FloatRange(from = 0.0, to = 1.0) val alpha: Float = 1f, val style: HighlightStyle = HighlightStyle.Default ) ``` -------------------------------- ### Simple Backdrop Button Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/GettingStarted.md Create a rounded button with a blur backdrop effect. The modifier clips content and applies effects. ```kotlin @Composable fun SimpleBackdropButton() { Button( onClick = { }, modifier = Modifier .size(120.dp, 48.dp) .drawBackdrop( backdrop = emptyBackdrop(), shape = { RoundedCornerShape(12.dp) }, effects = { blur(radius = 8f) } ) ) { Text("Click Me") } } ``` -------------------------------- ### Full Glassmorphism Card Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/GettingStarted.md Create a frosted glass card with blur, color controls, and opacity effects. Uses a semi-transparent white background. ```kotlin @Composable fun GlassCard() { Box( modifier = Modifier .fillMaxWidth() .height(200.dp) .padding(16.dp) .drawBackdrop( backdrop = emptyBackdrop(), shape = { RoundedCornerShape(20.dp) }, effects = { blur(radius = 20f) colorControls(brightness = 0.1f, saturation = 1.2f) opacity(0.9f) }, highlight = { Highlight.Default }, shadow = { Shadow.Default }, innerShadow = { InnerShadow.Default } ) .background( color = Color.White.copy(alpha = 0.15f), shape = RoundedCornerShape(20.dp) ) .padding(16.dp), contentAlignment = Alignment.Center ) { Column(horizontalAlignment = Alignment.CenterHorizontally) { Text( "Glassmorphism", fontSize = 24.sp, fontWeight = FontWeight.Bold, color = Color.White ) Text( "Modern UI Effect", fontSize = 14.sp, color = Color.White.copy(alpha = 0.7f) ) } } } ``` -------------------------------- ### emptyBackdrop() Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/BackdropInterface.md Provides a Backdrop implementation that draws nothing. This is useful for disabling visual effects. ```APIDOC ## Function: emptyBackdrop() ### Description Returns a backdrop that draws nothing. Use when you want to disable effects. ### Return - Backdrop: An empty Backdrop instance. ### Properties - `isCoordinatesDependent`: false ``` -------------------------------- ### Memoize Backdrops with rememberCanvasBackdrop Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/GettingStarted.md Use `rememberCanvasBackdrop` to memoize drawing code and avoid unnecessary recompositions, improving performance. ```kotlin val backdrop = rememberCanvasBackdrop { // Drawing code } ``` -------------------------------- ### Backdrop Interface Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/README.md Core abstraction for backdrop implementations. Includes `emptyBackdrop()`, `rememberCanvasBackdrop()`, `rememberLayerBackdrop()`, and combination utilities for creating and managing backdrop effects. ```APIDOC ## Backdrop Interface ### Description Core abstraction for backdrop implementations. Provides functions to create and manage different types of backdrops. ### Functions - `emptyBackdrop()`: Creates a no-operation backdrop. - `rememberCanvasBackdrop()`: Creates a custom drawing backdrop. - `rememberLayerBackdrop()`: Creates a layer-backed backdrop. - `rememberCombinedBackdrop()`: Combines multiple backdrops into a single effect. ``` -------------------------------- ### Handling Custom Shader Compilation Errors Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/errors.md Demonstrates error handling for custom shader effects using a try-catch block, logging any exceptions and allowing the composable to render without the shader. ```kotlin effects = { try { runtimeShaderEffect( key = "customEffect", shaderString = userProvidedShader, uniformShaderName = "content" ) { setFloatUniform("param1", value1) } } catch (e: Exception) { Log.e("Backdrop", "Shader effect failed", e) // Render without the shader effect } } ``` -------------------------------- ### rememberCombinedBackdrop(vararg backdrops) Source: https://github.com/kyant0/androidliquidglass/blob/kmp/_autodocs/api-reference/BackdropInterface.md Combines multiple backdrop instances so that they are all drawn in sequence. Overloads are provided for convenience when combining two or three backdrops. ```APIDOC ## Composable Function: rememberCombinedBackdrop(vararg backdrops: Backdrop) ### Description Combines multiple backdrops so they all draw in sequence. ### Parameters - **backdrops** (vararg Backdrop) - Required - A variable number of Backdrop instances to combine. ### Return - Backdrop: A combined Backdrop instance. ### Example ```kotlin val combined = rememberCombinedBackdrop( rememberCanvasBackdrop { drawRect(Color.Blue) }, rememberCanvasBackdrop { drawRect(Color.Red) } ) ``` ```