add debug ui btn support

isolation_bkp/dynres
Dominik Madarász 2021-05-13 14:36:07 +02:00
parent eb65910d15
commit b4701807f3
3 changed files with 35 additions and 0 deletions

View File

@ -63,6 +63,7 @@ void UIDrawText(const char *text, float posX, float posY, int fontSize, Color co
int UIMeasureText(const char *text, int fontSize);
#include "debug_ui_widgets.c"
#include "debug_ui_actions.c"
static debug_item items[] = {
{
@ -91,6 +92,11 @@ static debug_item items[] = {
//.is_collapsed = 1
}
},
{
.kind = DITEM_BUTTON,
.name = "exit game",
.on_click = ActExitGame,
},
{.kind = DITEM_END},
};
@ -134,6 +140,21 @@ debug_draw_result debug_draw_list(debug_item *list, float xpos, float ypos, bool
ypos = res.y;
}break;
case DITEM_BUTTON: {
assert(it->on_click);
char const *text = TextFormat("> %s", it->name);
if (it->name_width == 0) {
it->name_width = UIMeasureText(text, DBG_FONT_SIZE);
}
Color color = RAYWHITE;
if (is_btn_pressed(xpos, ypos, it->name_width, DBG_FONT_SIZE, &color)) {
it->on_click();
}
debug_draw_result res = DrawColoredText(xpos, ypos, text, color);
ypos = res.y;
}break;
default: {
}break;

View File

@ -0,0 +1,7 @@
#include "debug_ui.h"
#include "raylib.h"
static inline void
ActExitGame(void) {
CloseWindow();
}

View File

@ -19,6 +19,13 @@ DrawFormattedText(float xpos, float ypos, char const *text) {
return (debug_draw_result){.x = xpos + UIMeasureText(text, DBG_FONT_SIZE), .y = ypos + DBG_FONT_SPACING};
}
static inline debug_draw_result
DrawColoredText(float xpos, float ypos, char const *text, Color color) {
assert(text);
UIDrawText(text, xpos, ypos, DBG_FONT_SIZE, color);
return (debug_draw_result){.x = xpos + UIMeasureText(text, DBG_FONT_SIZE), .y = ypos + DBG_FONT_SPACING};
}
//~ NOTE(zaklaus): widgets
static inline debug_draw_result