From f8b92ce3aa08b1445c9f956d8166830946562d12 Mon Sep 17 00:00:00 2001 From: navewindre Date: Wed, 3 Sep 2025 20:10:09 +0200 Subject: a --- src/gui/label.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/gui/label.cpp (limited to 'src/gui/label.cpp') diff --git a/src/gui/label.cpp b/src/gui/label.cpp new file mode 100644 index 0000000..b5d6290 --- /dev/null +++ b/src/gui/label.cpp @@ -0,0 +1,40 @@ +#include "base.h" +#include +#include + +void gui_label_draw_fn( void* ptr ) { + GUI_LABEL* label = (GUI_LABEL*)ptr; + + I32 x = gui_relx( label ); + I32 y = gui_rely( label ); + + gui_draw_get_str_bounds( &label->w, &label->h, FNT_JPN12, label->name ); + label->xbound = label->w; + label->ybound = label->h; + gui_draw_str( x, y, ALIGN_L, FNT_JPN12, ui_clr.txt, label->name ); +} + +GUI_LABEL* gui_label( I32 x, I32 y, const char* title, ... ) { + if( !gui_check_target() ) return 0; + char buf[GUI_NAME_LEN]; + + va_list args; + va_start( args, title ); + vsprintf( buf, title, args ); + va_end( args ); + + GUI_LABEL* label = new GUI_LABEL; + label->x = x; + label->y = y; + label->draw_fn = gui_label_draw_fn; + strcpy( label->name, buf ); + + gui_draw_get_str_bounds( &label->w, &label->h, FNT_JPN12, label->name ); + label->xbound = label->w; + label->ybound = label->h; + + label->parent = gui_get_view(); + label->parent->children.push( label ); + + return label; +} -- cgit v1.2.3