[sdl2] all keys' labels rightfully placed

This commit is contained in:
Gwenhael Le Moine 2024-09-05 20:08:54 +02:00
parent 18557bb0f1
commit e374ba61a7
No known key found for this signature in database
GPG key ID: FDFE3669426707A7
2 changed files with 14 additions and 18 deletions

View file

@ -49,7 +49,7 @@ typedef struct button_t {
const char* name; const char* name;
int x, y; int x, y;
unsigned int w, h; int w, h;
int lc; int lc;
const char* label; const char* label;

View file

@ -696,6 +696,7 @@ static void _draw_keypad( void )
int total_top_labels_width; int total_top_labels_width;
for ( int i = FIRST_HPKEY; i <= LAST_HPKEY; i++ ) { for ( int i = FIRST_HPKEY; i <= LAST_HPKEY; i++ ) {
total_top_labels_width = 0;
// Background // Background
if ( BUTTONS[ i ].is_menu ) { if ( BUTTONS[ i ].is_menu ) {
x = KEYBOARD_OFFSET_X + BUTTONS[ i ].x; 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; y = KEYBOARD_OFFSET_Y + BUTTONS[ i ].y - small_descent;
left_label_width = SmallTextWidth( BUTTONS[ i ].left, strlen( BUTTONS[ i ].left ) ); left_label_width = SmallTextWidth( BUTTONS[ i ].left, strlen( BUTTONS[ i ].left ) );
total_top_labels_width = left_label_width;
if ( BUTTONS[ i ].right == ( char* )0 ) if ( BUTTONS[ i ].right != ( char* )0 ) {
// centered label
x += ( 1 + BUTTONS[ i ].w - left_label_width ) / 2;
else {
// label to the left // label to the left
right_label_width = SmallTextWidth( BUTTONS[ i ].right, strlen( BUTTONS[ i ].right ) ); right_label_width = SmallTextWidth( BUTTONS[ i ].right, strlen( BUTTONS[ i ].right ) );
total_top_labels_width += space_char_width + right_label_width;
/* x += ( 1 + BUTTONS[ i ].w - ( left_label_width + right_label_width + space_char_width ) ) / 2; */
x -= 6;
} }
x += ( 1 + BUTTONS[ i ].w - total_top_labels_width ) / 2;
write_text( x, y, BUTTONS[ i ].left, LEFT, BUTTONS[ i ].is_menu ? UNDERLAY : PAD ); 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; x = KEYBOARD_OFFSET_X + BUTTONS[ i ].x;
y = KEYBOARD_OFFSET_Y + BUTTONS[ i ].y - small_descent; y = KEYBOARD_OFFSET_Y + BUTTONS[ i ].y - small_descent;
if ( BUTTONS[ i ].left == ( char* )0 ) if ( BUTTONS[ i ].left == ( char* )0 ) {
// centered label right_label_width = SmallTextWidth( BUTTONS[ i ].right, strlen( BUTTONS[ i ].right ) );
x += ( 1 + BUTTONS[ i ].w - right_label_width ) / 2; total_top_labels_width = right_label_width;
else { } else {
// label to the right x += space_char_width + left_label_width;
/* 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; */
} }
x += ( 1 + BUTTONS[ i ].w - total_top_labels_width ) / 2;
write_text( x, y, BUTTONS[ i ].right, RIGHT, PAD ); write_text( x, y, BUTTONS[ i ].right, RIGHT, PAD );
} }
} }