Package-level declarations

Types

Link copied to clipboard
abstract class DominantColorState<T : Any>(defaultColor: Color, defaultOnColor: Color, cacheSize: Int = DEFAULT_CACHE_SIZE, coroutineContext: CoroutineContext = Dispatchers.Default, isSwatchValid: (Palette.Swatch) -> Boolean = { true }, builder: Palette.Builder.() -> Unit = {})

A class which stores and caches the result of any calculated dominant colors.

Link copied to clipboard
sealed interface PaletteResult

Represents the result of a palette generation operation.

Link copied to clipboard
abstract class PaletteState<T : Any>(cacheSize: Int = DEFAULT_CACHE_SIZE, coroutineContext: CoroutineContext = Dispatchers.Default, builder: Palette.Builder.() -> Unit = {})

A state object that generates a Palette from an ImageBitmap using loader.

Link copied to clipboard
sealed interface SwatchTarget

A class which allows custom selection of colors in a Palette's generation. Instances can be created via the Builder class.

Properties

Link copied to clipboard

Returns a color value in the RGB color space which represents the color of this Swatch

Link copied to clipboard
const val DEFAULT_CACHE_SIZE: Int = 6

The default number of results retained by the PaletteState and DominantColorState caches.

Link copied to clipboard

Returns an appropriate color to use for any 'title' text which is displayed over this Swatch's color. This color is guaranteed to have sufficient contrast.

Functions

Link copied to clipboard

Returns an appropriate color to use for any 'body' text which is displayed over this Swatch's color. This color is guaranteed to have sufficient contrast.

Link copied to clipboard
fun Palette.Companion.from(bitmap: ImageBitmap, scale: Boolean = true, block: Palette.Builder.() -> Unit = {}): Palette.Builder

Creates a Palette.Builder from an ImageBitmap.

Link copied to clipboard
suspend fun ImageBitmap.generatePalette(coroutineContext: CoroutineContext = Dispatchers.Default, block: Palette.Builder.() -> Unit = {}): Palette

Generates a Palette from this ImageBitmap.

Link copied to clipboard
operator fun Palette.get(target: SwatchTarget): Palette.Swatch?
operator fun Palette.get(target: Target): Palette.Swatch?

Returns the selected swatch for the given target from the palette, or null if one could not be found.

Link copied to clipboard

Returns the selected swatch for the given target from the palette, or null if one could not be found.

Link copied to clipboard
fun rememberDominantColorState(defaultColor: Color, defaultOnColor: Color, cacheSize: Int = DEFAULT_CACHE_SIZE, coroutineContext: CoroutineContext = Dispatchers.Default, isSwatchValid: (Palette.Swatch) -> Boolean = { true }, builder: Palette.Builder.() -> Unit = {}): DominantColorState<ImageBitmap>
fun <T : Any> rememberDominantColorState(loader: ImageBitmapLoader<T>, defaultColor: Color, defaultOnColor: Color, cacheSize: Int = DEFAULT_CACHE_SIZE, coroutineContext: CoroutineContext = Dispatchers.Default, isSwatchValid: (Palette.Swatch) -> Boolean = { true }, builder: Palette.Builder.() -> Unit = {}): DominantColorState<T>

Create a DominantColorState which will be remembered across compositions. Then can be used to generate a dominant color from an ImageBitmap.

Link copied to clipboard
fun rememberGeneratePalette(loader: suspend () -> ImageBitmap, coroutineContext: CoroutineContext = Dispatchers.Default, block: Palette.Builder.() -> Unit = {}): PaletteResult

Generates and remembers a Palette from an ImageBitmap loaded by the provided loader.

Link copied to clipboard
fun ImageBitmap.rememberGeneratePalette(coroutineContext: CoroutineContext = Dispatchers.Default, block: Palette.Builder.() -> Unit = {}): PaletteResult

Generates and remembers a Palette from this ImageBitmap across compositions.

Link copied to clipboard
fun rememberPaletteState(cacheSize: Int = DEFAULT_CACHE_SIZE, coroutineContext: CoroutineContext = Dispatchers.Default, builder: Palette.Builder.() -> Unit = {}): PaletteState<ImageBitmap>

Creates a PaletteState that will be remembered across compilation and can be used to generate a Palette from an ImageBitmap.

fun <T : Any> rememberPaletteState(loader: ImageBitmapLoader<T>, cacheSize: Int = DEFAULT_CACHE_SIZE, coroutineContext: CoroutineContext = Dispatchers.Default, builder: Palette.Builder.() -> Unit = {}): PaletteState<T>

Creates a PaletteState that will be remembered across compilation and can be used to generate a Palette from an ImageBitmap using loader.

Link copied to clipboard

Returns an appropriate color to use for any 'title' text which is displayed over this Swatch's color. This color is guaranteed to have sufficient contrast.