X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=vg%2Fvg_ui.h;h=11728509ae0d9ac7fa03feae4fd5a83c39332cd3;hb=aad3ce335e5a67018359442ee1c3a849d675ea18;hp=3e4ae5e3717d272c90af5d9832368b5f5bb032c5;hpb=fa88b9de1e8416023822f91ec88971bfadcf1702;p=fishladder.git diff --git a/vg/vg_ui.h b/vg/vg_ui.h index 3e4ae5e..1172850 100644 --- a/vg/vg_ui.h +++ b/vg/vg_ui.h @@ -384,8 +384,8 @@ static void ui_new_node( ui_ctx *ctx ) if( parent->mouse_over ) { - if( ctx->mouse[0] >= node->rect[0] && ctx->mouse[0] <= node->rect[0]+node->rect[2] && - ctx->mouse[1] >= node->rect[1] && ctx->mouse[1] <= node->rect[1]+node->rect[3] ) + if( ctx->mouse[0] >= node->rect[0] && ctx->mouse[0] < node->rect[0]+node->rect[2] && + ctx->mouse[1] >= node->rect[1] && ctx->mouse[1] < node->rect[1]+node->rect[3] ) node->mouse_over = 1; else node->mouse_over = 0; @@ -573,10 +573,11 @@ static void ui_text_use_paragraph( ui_ctx *ctx ) enum text_alignment { k_text_alignment_left = 0, - k_text_alignment_center + k_text_alignment_center, + k_text_alignment_right }; -static void ui_text( ui_ctx *ctx, const char *str, ui_px scale, enum text_alignment alignment ) +static ui_px ui_text( ui_ctx *ctx, const char *str, ui_px scale, enum text_alignment alignment ) { ui_rect text_cursor; @@ -587,6 +588,24 @@ static void ui_text( ui_ctx *ctx, const char *str, ui_px scale, enum text_alignm u32 current_colour = ctx->override_colour; + ui_px offset = 0; + if( alignment != k_text_alignment_left ) + { + const char *pch = str; + for(;;) + { + offset += (ui_glyph_spacing_x*scale)/4; + if( !(*pch) || *pch == '\n' ) + break; + pch ++; + } + + if( alignment == k_text_alignment_right ) + text_cursor[0] = ctx->cursor[0]+ctx->cursor[2]-offset; + else + text_cursor[0] = (ctx->cursor[0]+(ctx->cursor[2]/2))-(offset/2); + } + const char *_c = str; char c; while( (c = *(_c ++)) ) @@ -655,6 +674,8 @@ static void ui_text( ui_ctx *ctx, const char *str, ui_px scale, enum text_alignm text_cursor[0] += (ui_glyph_spacing_x*scale)/4; } + + return text_cursor[0]; } // API control