save file .sv2 format read/write
[fishladder.git] / vg / vg_ui.h
index 3e4ae5e3717d272c90af5d9832368b5f5bb032c5..7e676545546355c7819f9f5c81b2e68a6ae8b5c8 100644 (file)
@@ -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