Colors in Raylib

Mike Parker aldacron at
Mon Feb 28 12:18:37 UTC 2022

On Monday, 28 February 2022 at 11:48:59 UTC, Salih Dincer wrote:
> Hi All,
> Is there a namespace I should implement in Raylib? For example, 
> I cannot compile without writing Colors at the beginning of the 
> colors: ```Colors.GRAY```
> SDB at 79

Assuming you mean the raylib-d binding, it implements the values 
as a named enum, so the `Colors` namespace is required.

If you have a situation where you need to type it multiple times 
in consecutive code lines, you can use `with`:

with(Colors) {


Then you can drop the namespace and just used the values. Very 
useful for switches:

with(Colors) switch(myColor) {


You can also generate aliases, so that e.g., `LIGHTGRAY` is 
equivalent to `Colors.LIGHTGRAY`). Just throw this template 
function in an appropriate module:

enum expandEnum(EnumType, string fqnEnumType = EnumType.stringof) 
= (){
     string expandEnum;
     foreach(m;__traits(allMembers, EnumType)) {
         expandEnum ~= "alias " ~ m ~ " = " ~ fqnEnumType ~ "." ~ 
m ~ ";";
     return expandEnum;

Then you can mixin aliases for any named enum members you'd like:


More information about the Digitalmars-d-learn mailing list