Package com.github.tommyettinger.textra
Interface ColorLookup
public interface ColorLookup
Allows looking up an RGBA8888 int color given a String key, returning either the color or 256 if none was found.
This is an extension point for games and libraries that may want their own way of looking up colors. This can be
treated as a functional interface in Java 8 and higher.
The default here is
The default here is
DESCRIPTIVE
, which allows using multiple color names, plus adjectives. There
is also INSTANCE
, which is older and only looks up one color name at a time from Colors
in libGDX.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ColorLookup
The default ColorLookup, this parses a description such as "peach red" or "DARK DULLEST GREEN" usingColorUtils.describe(String)
(See its docs for more information).static final ColorLookup
An alternative ColorLookup, this simply looks upkey
inColors
. -
Method Summary
-
Field Details
-
INSTANCE
An alternative ColorLookup, this simply looks upkey
inColors
. It returns 256 (fully transparent, extremely dark blue) if no Color exists by that exact name (case-sensitive), or returning the RGBA8888 value of the color otherwise. All color names areALL_CAPS
in libGDX's Colors collection by default. -
DESCRIPTIVE
The default ColorLookup, this parses a description such as "peach red" or "DARK DULLEST GREEN" usingColorUtils.describe(String)
(See its docs for more information). The colors available are inPalette
; there are adjectives that modify lightness and saturation (seeColorUtils.describe(String)
), and you can specify multiple colors to mix them, with or without weights per-color. Case is effectively ignored for adjectives, but it matters for color names -- ALL_CAPS names are ones from the libGDX classColors
, while lowercase ones are defined by this library.
-
-
Method Details
-
getRgba
Looks upkey
to get an RGBA8888 color, and returns that color as an int if one was found, or returns 256 if none was found. 256 is used because it is different from the more commonly-used 0 for fully-transparent, while still being easy to remember and very rare to ever want (it is fully transparent, very dark blue). This library will never call this method with a null key, and in most cases you can safely assume key is non-null.- Parameters:
key
- the String key to use to look up or build a color; should not be null.- Returns:
- an RGBA8888 color; if 256, this can be considered to not know how to look up the given key.
-