Skip to content

Commit

Permalink
refactor: correctly namespace symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
marionauta committed Sep 15, 2023
1 parent 85bf89f commit f996e01
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
- Handle mouse & keyboard inputs.
- Handle custom fonts.
- Draw controls on screen.
- All symbols are namespaced (prefixed) with either `MURL_` or `murl_`.

## examples

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).

Expand Down
16 changes: 8 additions & 8 deletions src/murl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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: {
Expand Down
22 changes: 17 additions & 5 deletions src/murl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit f996e01

Please sign in to comment.