AtomMaterialUI / color-highlighter

JetBrains plugin to preview colors directly from within the code.
MIT License
40 stars 23 forks source link

Add a parser for Compose Color(color: Long) #152

Open Qw4z1 opened 1 month ago

Qw4z1 commented 1 month ago

The standard way to specify colors in Jetpack Compose is by using a 32-bit ARGB hex value. The parser currently interprets the value as a normal hex color, which breaks the preview.

For example, this is how I would specify blue val blue = Color(0xFF0000FF), but the plugin shows this as red.

There are of cource other ways to specify colors, but since this is the standard all examples and generated code comes in this format.

Additional context: This is the implementation of the Color function in Compose

/**
 * Creates a new [Color] instance from an ARGB color int.
 * The resulting color is in the [sRGB][ColorSpaces.Srgb]
 * color space. This is useful for specifying colors with alpha
 * greater than 0x80 in numeric form without using [Long.toInt]:
 *
 *     val color = Color(0xFF000080)
 *
 * @param color The 32-bit ARGB color int to create a <code>Color</code>
 * from
 * @return A non-null instance of {@link Color}
 */
@Stable
fun Color(color: Long): Color {
    return Color(value = (color.toULong() and 0xffffffffUL) shl 32)
}