add debug ui btn support
parent
eb65910d15
commit
b4701807f3
|
@ -63,6 +63,7 @@ void UIDrawText(const char *text, float posX, float posY, int fontSize, Color co
|
||||||
int UIMeasureText(const char *text, int fontSize);
|
int UIMeasureText(const char *text, int fontSize);
|
||||||
|
|
||||||
#include "debug_ui_widgets.c"
|
#include "debug_ui_widgets.c"
|
||||||
|
#include "debug_ui_actions.c"
|
||||||
|
|
||||||
static debug_item items[] = {
|
static debug_item items[] = {
|
||||||
{
|
{
|
||||||
|
@ -91,6 +92,11 @@ static debug_item items[] = {
|
||||||
//.is_collapsed = 1
|
//.is_collapsed = 1
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
.kind = DITEM_BUTTON,
|
||||||
|
.name = "exit game",
|
||||||
|
.on_click = ActExitGame,
|
||||||
|
},
|
||||||
{.kind = DITEM_END},
|
{.kind = DITEM_END},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -134,6 +140,21 @@ debug_draw_result debug_draw_list(debug_item *list, float xpos, float ypos, bool
|
||||||
ypos = res.y;
|
ypos = res.y;
|
||||||
}break;
|
}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: {
|
default: {
|
||||||
|
|
||||||
}break;
|
}break;
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
#include "debug_ui.h"
|
||||||
|
#include "raylib.h"
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
ActExitGame(void) {
|
||||||
|
CloseWindow();
|
||||||
|
}
|
|
@ -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};
|
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
|
//~ NOTE(zaklaus): widgets
|
||||||
|
|
||||||
static inline debug_draw_result
|
static inline debug_draw_result
|
||||||
|
|
Loading…
Reference in New Issue