From e374ba61a7470413011eafd332ab68e936724acf Mon Sep 17 00:00:00 2001 From: Gwenhael Le Moine Date: Thu, 5 Sep 2024 20:08:54 +0200 Subject: [PATCH] [sdl2] all keys' labels rightfully placed --- src/ui_inner.h | 2 +- src/ui_sdl2.c | 30 +++++++++++++----------------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/ui_inner.h b/src/ui_inner.h index 7dc5a24..f36d01a 100644 --- a/src/ui_inner.h +++ b/src/ui_inner.h @@ -49,7 +49,7 @@ typedef struct button_t { const char* name; int x, y; - unsigned int w, h; + int w, h; int lc; const char* label; diff --git a/src/ui_sdl2.c b/src/ui_sdl2.c index 5c1e092..99d7486 100644 --- a/src/ui_sdl2.c +++ b/src/ui_sdl2.c @@ -696,6 +696,7 @@ static void _draw_keypad( void ) int total_top_labels_width; for ( int i = FIRST_HPKEY; i <= LAST_HPKEY; i++ ) { + total_top_labels_width = 0; // Background if ( BUTTONS[ i ].is_menu ) { x = KEYBOARD_OFFSET_X + BUTTONS[ i ].x; @@ -740,18 +741,16 @@ static void _draw_keypad( void ) y = KEYBOARD_OFFSET_Y + BUTTONS[ i ].y - small_descent; left_label_width = SmallTextWidth( BUTTONS[ i ].left, strlen( BUTTONS[ i ].left ) ); + total_top_labels_width = left_label_width; - if ( BUTTONS[ i ].right == ( char* )0 ) - // centered label - x += ( 1 + BUTTONS[ i ].w - left_label_width ) / 2; - else { + if ( BUTTONS[ i ].right != ( char* )0 ) { // label to the left right_label_width = SmallTextWidth( BUTTONS[ i ].right, strlen( BUTTONS[ i ].right ) ); - - /* x += ( 1 + BUTTONS[ i ].w - ( left_label_width + right_label_width + space_char_width ) ) / 2; */ - x -= 6; + total_top_labels_width += space_char_width + right_label_width; } + x += ( 1 + BUTTONS[ i ].w - total_top_labels_width ) / 2; + write_text( x, y, BUTTONS[ i ].left, LEFT, BUTTONS[ i ].is_menu ? UNDERLAY : PAD ); } @@ -760,18 +759,15 @@ static void _draw_keypad( void ) x = KEYBOARD_OFFSET_X + BUTTONS[ i ].x; y = KEYBOARD_OFFSET_Y + BUTTONS[ i ].y - small_descent; - if ( BUTTONS[ i ].left == ( char* )0 ) - // centered label - x += ( 1 + BUTTONS[ i ].w - right_label_width ) / 2; - else { - // label to the right - /* x += ( 1 + BUTTONS[ i ].w - ( left_label_width + right_label_width + space_char_width ) ) / 2 + left_label_width + - * space_char_width; */ - - x += ( left_label_width + space_char_width ) - 6; - /* x += BUTTONS[ i ].w - right_label_width; */ + if ( BUTTONS[ i ].left == ( char* )0 ) { + right_label_width = SmallTextWidth( BUTTONS[ i ].right, strlen( BUTTONS[ i ].right ) ); + total_top_labels_width = right_label_width; + } else { + x += space_char_width + left_label_width; } + x += ( 1 + BUTTONS[ i ].w - total_top_labels_width ) / 2; + write_text( x, y, BUTTONS[ i ].right, RIGHT, PAD ); } }