Represents a color that can be used with canvas APIs.
Android
public open class RemoteColor
internal constructor(
@get:Suppress("AutoBoxing") public override val constantValueOrNull: Color?,
internal override val cacheKey: RemoteStateCacheKey,
alpha: RemoteFloat?,
red: RemoteFloat?,
green: RemoteFloat?,
blue: RemoteFloat?,
internal val idProvider: (creationState: RemoteComposeCreationState) -> Int,
) : BaseRemoteState<Color>()
Represents a color that can be used with canvas APIs.
RemoteColor represents a color value that can be a constant, a named variable, or a dynamic expression (e.g., a color interpolation).
Secondary Constructors
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public constructor(
alpha: RemoteFloat,
red: RemoteFloat,
green: RemoteFloat,
blue: RemoteFloat,
) : this(
constantValueOrNull = constantColorOrNull(alpha, red, green, blue),
alpha = alpha,
red = red,
green = green,
blue = blue,
cacheKey = RemoteOperationCacheKey.create(OperationKey.FromArgb, alpha, red, green, blue),
idProvider = { creationState ->
creationState.getOrPutVariableId(
RemoteOperationCacheKey.create(OperationKey.FromArgb, alpha, red, green, blue)
) {
creationState.document
.addColorExpression(
alpha.getFloatIdForCreationState(creationState),
red.getFloatIdForCreationState(creationState),
green.getFloatIdForCreationState(creationState),
blue.getFloatIdForCreationState(creationState),
)
.toInt()
}
},
)
internal constructor(
cacheKey: RemoteStateCacheKey,
idProvider: (creationState: RemoteComposeCreationState) -> Int,
) : this(
constantValueOrNull = null,
cacheKey = cacheKey,
alpha = null,
red = null,
green = null,
blue = null,
idProvider = idProvider,
)
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public constructor(
color: Color
) : this(
constantValueOrNull = color,
alpha = color.alpha.rf,
red = color.red.rf,
green = color.green.rf,
blue = color.blue.rf,
cacheKey = RemoteConstantCacheKey(color.toArgb()),
idProvider = { creationState -> creationState.document.addColor(color.toArgb()) },
)
Constructor for creating a RemoteColor from a Color value. This creates a constant remote color that is added to the remote document.
Parameters
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public constructor(@ColorInt color: Int) : this(Color(color))
Constructor for creating a RemoteColor from a direct ARGB integer color value. This creates a constant remote color that is added to the remote document.
Parameters
|
|
| color |
The ARGB integer representation of the color. |
Functions
times
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public operator fun times(other: RemoteColor): RemoteColor
Computes the pairwise product of this RemoteColor with other.
Parameters
Returns
copy
public fun copy(
alpha: RemoteFloat? = null,
red: RemoteFloat? = null,
green: RemoteFloat? = null,
blue: RemoteFloat? = null,
): RemoteColor
Creates a copy of this RemoteColor with the ability to override individual ARGB components. If a component is not specified, it defaults to the corresponding component of the original RemoteColor.
Parameters
|
|
| alpha |
Optional RemoteFloat to override the alpha component. |
| red |
Optional RemoteFloat to override the red component. |
| green |
Optional RemoteFloat to override the green component. |
| blue |
Optional RemoteFloat to override the blue component. |
Returns
|
|
|
A new RemoteColor with the specified components overridden. |
Companion Object
Methods
invoke
Android
public operator fun invoke(value: Color): RemoteColor
Creates a RemoteColor from a literal Color value.
Parameters
Returns
createNamedRemoteColor
Android
@JvmStatic
public fun createNamedRemoteColor(
name: String,
defaultValue: Color,
domain: RemoteState.Domain = RemoteState.Domain.User,
): RemoteColor
Creates a named RemoteColor with an initial value.
Named remote colors can be set via AndroidRemoteContext.setNamedColor.
Parameters
|
|
| name |
A unique name to identify this state within its domain. |
| defaultValue |
The initial Color value for the named remote color. |
| domain |
The domain for the named state. Defaults to RemoteState.Domain.User. |
Returns
hsv
Android
public fun hsv(
hue: RemoteFloat,
saturation: RemoteFloat,
value: RemoteFloat,
alpha: RemoteFloat = 1.rf,
): RemoteColor
Creates a RemoteColor from remote hue, saturation, and value (brightness) components. The resulting color is expressed as a RemoteColor expression that combines these inputs.
Parameters
|
|
| hue |
A RemoteFloat representing the hue in the range [0..1]. |
| saturation |
A RemoteFloat representing the saturation in the range [0..1]. |
| value |
A RemoteFloat representing the brightness in the range [0..1]. |
| alpha |
The fixed alpha value the range [0..1]. |
Returns
|
|
|
A new RemoteColor derived from the provided HSV components. |
fromAHSV
Android
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public fun fromAHSV(
alpha: Int,
hue: RemoteFloat,
saturation: RemoteFloat,
value: RemoteFloat,
): RemoteColor
Creates a RemoteColor from a fixed alpha value and remote hue, saturation, and value (brightness) components. This allows creating a remote color with a constant opacity and dynamic HSV.
Parameters
|
|
| alpha |
The fixed alpha value the range [0..255]. |
| hue |
A RemoteFloat representing the hue in the range [0..1]. |
| saturation |
A RemoteFloat representing the saturation in the range [0..1]. |
| value |
A RemoteFloat representing the brightness in the range [0..1]. |
Returns
|
|
|
A new RemoteColor derived from the provided AHSV components. |
rgb
Android
public fun rgb(
red: RemoteFloat,
green: RemoteFloat,
blue: RemoteFloat,
alpha: RemoteFloat = 1.rf,
): RemoteColor
Creates a RemoteColor from remote alpha, red, green, and blue components.
Parameters
|
|
| alpha |
RemoteFloat representing the alpha in the range [0..1]. |
| red |
A RemoteFloat representing red in the range [0..1]. |
| green |
A RemoteFloat representing green in the range [0..1]. |
| blue |
A RemoteFloat representing blue in the range [0..1]. |
Returns
|
|
|
A new RemoteColor derived from the provided ARGB components. |
rgb
Android
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public fun rgb(alpha: Float, red: Float, green: Float, blue: Float): RemoteColor
Creates a RemoteColor from alpha, red, green, and blue components.
Parameters
|
|
| alpha |
Float representing the alpha in the range [0..1]. |
| red |
A Float representing red in the range [0..1]. |
| green |
A Float representing green in the range [0..1]. |
| blue |
A Float representing blue in the range [0..1]. |
Returns
|
|
|
A new RemoteColor derived from the provided ARGB components. |