diff --git a/README.md b/README.md index c15344d..3ababb1 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ - Handle mouse & keyboard inputs. - Handle custom fonts. - Draw controls on screen. +- All symbols are namespaced (prefixed) with either `MURL_` or `murl_`. ## examples @@ -15,7 +16,8 @@ There are some code examples in the [`examples`](examples) folder. > [!NOTE] > To compile the examples with the given `Makefile`, make sure you have the -> `microui.c` file in the `vendor` folder. Then simply run `make`. +> `microui.c` and `microui.h` files in the `vendor` folder. +> Then simply run `make`. All available functions are listed in [`src/murl.h`](src/murl.h). diff --git a/src/murl.c b/src/murl.c index b69613b..217f0da 100644 --- a/src/murl.c +++ b/src/murl.c @@ -14,13 +14,13 @@ void murl_setup_font_ex(mu_Context *ctx, const Font *font) { int murl_text_width(mu_Font font, const char *str, int len) { (void)len; - Font rlfont = RL_FONT_FROM_MU(font); + Font rlfont = MURL_FONT_FROM_MU(font); Vector2 size = MeasureTextEx(rlfont, str, rlfont.baseSize, MURL_TEXT_SPACING); return size.x; } int murl_text_height(mu_Font font) { - Font rlfont = RL_FONT_FROM_MU(font); + Font rlfont = MURL_FONT_FROM_MU(font); return rlfont.baseSize; } @@ -112,22 +112,22 @@ void murl_render(mu_Context *ctx) { while (mu_next_command(ctx, &cmd)) { switch (cmd->type) { case MU_COMMAND_TEXT: { - Font font = RL_FONT_FROM_MU(cmd->text.font); - Vector2 text_position = RL_VECTOR2_FROM_MU(cmd->text.pos); + Font font = MURL_FONT_FROM_MU(cmd->text.font); + Vector2 text_position = MURL_VECTOR2_FROM_MU(cmd->text.pos); int font_size = ctx->text_height(&font); - Color text_color = RL_COLOR_FROM_MU(cmd->text.color); + Color text_color = MURL_COLOR_FROM_MU(cmd->text.color); DrawTextEx(font, cmd->text.str, text_position, font_size, ctx->style->spacing, text_color); } break; case MU_COMMAND_RECT: { - Rectangle rect = RL_RECTANGLE_FROM_MU(cmd->rect.rect); - Color rect_color = RL_COLOR_FROM_MU(cmd->rect.color); + Rectangle rect = MURL_RECTANGLE_FROM_MU(cmd->rect.rect); + Color rect_color = MURL_COLOR_FROM_MU(cmd->rect.color); DrawRectangleRec(rect, rect_color); } break; case MU_COMMAND_ICON: { - Color icon_color = RL_COLOR_FROM_MU(cmd->icon.color); + Color icon_color = MURL_COLOR_FROM_MU(cmd->icon.color); char *icon = "?"; switch (cmd->icon.id) { case MU_ICON_CLOSE: { diff --git a/src/murl.h b/src/murl.h index bc462ff..3e76d13 100644 --- a/src/murl.h +++ b/src/murl.h @@ -7,15 +7,27 @@ #define MURL_TEXT_SPACING 1 -#define RL_COLOR_FROM_MU(c) ((Color){c.r, c.g, c.b, c.a}) -#define RL_FONT_FROM_MU(f) ((f == NULL) ? GetFontDefault() : *(Font *)f) -#define RL_RECTANGLE_FROM_MU(r) ((Rectangle){r.x, r.y, r.w, r.h}) -#define RL_VECTOR2_FROM_MU(v) ((Vector2){v.x, v.y}) +// Create a raylib Color from a microui mu_Color. +#define MURL_COLOR_FROM_MU(c) ((Color){c.r, c.g, c.b, c.a}) -#define murl_setup_font(ctx) murl_setup_font_ex(ctx, NULL) +// Create a raylib Font from a microui mu_Font. +// If `f` is `NULL` get the default raylib font. +#define MURL_FONT_FROM_MU(f) ((f == NULL) ? GetFontDefault() : *(Font *)f) + +// Create a raylib Rectangle from a microui mu_Rect. +#define MURL_RECTANGLE_FROM_MU(r) ((Rectangle){r.x, r.y, r.w, r.h}) + +// Create a raylib Vector2 from a microui mu_Vec2. +#define MURL_VECTOR2_FROM_MU(v) ((Vector2){v.x, v.y}) + +// Set the text height/width callbacks and the font. void murl_setup_font_ex(mu_Context *ctx, const Font *font); +#define murl_setup_font(ctx) murl_setup_font_ex(ctx, NULL) +// `mu_Context.text_width` callback. See `murl_setup_font`. int murl_text_width(mu_Font font, const char *str, int len); + +// `mu_Context.text_height` callback. See `murl_setup_font`. int murl_text_height(mu_Font font); // Handle all keyboard & mouse events.