Skip to content

Commit

Permalink
slightly better right-aligned accels in the dropdown menus
Browse files Browse the repository at this point in the history
  • Loading branch information
dk committed Dec 7, 2024
1 parent 59670c4 commit 51af27d
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions unix/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,18 @@ menu_window_delete_downlinks( PMenuSysData XX, PMenuWindow wx)
}

static int
get_text_width( PCachedFont font, const char * text, int byte_length, Bool utf8, uint32_t * fc_map8)
get_text_width( PCachedFont font, const char * text, int byte_length, Bool utf8, uint32_t * fc_map8, Bool for_right_align)
{
int ret = 0;
int char_len = utf8 ? utf8_length(( U8*) text, ( U8*) text + byte_length) : byte_length;
#ifdef USE_XFT
if ( font-> xft)
return prima_xft_get_text_width( font, text, char_len, utf8 ? toUTF8 : 0, fc_map8, NULL);
if ( font-> xft) {
int w;
Point ovx;
w = prima_xft_get_text_width( font, text, char_len, utf8 ? toUTF8 : 0, fc_map8, for_right_align ? &ovx : NULL);
if ( for_right_align ) w += ovx.y;
return w;
}
#endif
if ( utf8) {
XChar2b * xc = prima_alloc_utf8_to_wchar( text, char_len);
Expand Down Expand Up @@ -249,8 +254,9 @@ text_out( PCachedFont font, const char * text, int length, int x, int y,
xftcolor.color.blue = COLOR_B16(data-> rgb);
xftcolor.color.alpha = 0xffff;
xftcolor.pixel = data-> pixel;
XftDrawString32(( XftDraw*) data-> xft_drawable, &xftcolor,
font-> xft, x, y, ( FcChar32*)text, length);
XftDrawString32(
( XftDraw*) data-> xft_drawable, &xftcolor,
font-> xft, x, y, ( FcChar32*)text, length);
return;
}
#endif
Expand Down Expand Up @@ -499,9 +505,9 @@ update_menu_window( PMenuSysData XX, PMenuWindow w)
}
}
ix-> width += startx + get_text_width( kf, m-> text, i,
m-> flags. utf8_text, fc_map8);
m-> flags. utf8_text, fc_map8, false);
if ( ntildas)
ix-> width -= ntildas * get_text_width( kf, "~", 1, false, fc_map8);
ix-> width -= ntildas * get_text_width( kf, "~", 1, false, fc_map8, false);
} else if ( create_menu_bitmap(m->bitmap, &ix->bitmap, layered, m->flags.disabled, &w, &h)) {
ix-> height += (( h < kf-> font. height) ? kf-> font. height : h) +
MENU_ITEM_GAP * 2;
Expand All @@ -518,7 +524,7 @@ update_menu_window( PMenuSysData XX, PMenuWindow w)

if ( m-> accel && ( l = strlen( m-> accel))) {
ix-> accel_width = get_text_width( kf, m-> accel, l,
m-> flags. utf8_accel, fc_map8);
m-> flags. utf8_accel, fc_map8, true);
}
if ( ix-> accel_width + ix-> width > x) x = ix-> accel_width + ix-> width;
}
Expand Down Expand Up @@ -658,7 +664,7 @@ menu_item_size( PMenuSysData XX, PMenuWindow w, int index)
while ( index--) m = m-> next;
if ( m-> flags. divider) return ret;
ret. x = MENU_XOFFSET * 2 + ix-> width;
if ( m-> accel) ret. x += MENU_XOFFSET / 2+ ix-> accel_width;
if ( m-> accel) ret. x += MENU_XOFFSET / 2 + ix-> accel_width;
} else if ( index == w-> last + 1) {
ret. x = MENU_XOFFSET * 2 + XX-> guillemots;
} else
Expand Down Expand Up @@ -961,7 +967,7 @@ DECL_DRAW(text)
haveDash = 1;
lineEnd = lineStart + 1 +
get_text_width( kf, t + i + 1, 1,
m-> flags. utf8_text, draw-> fc_map8);
m-> flags. utf8_text, draw-> fc_map8, false);
}
i++;
}
Expand Down

0 comments on commit 51af27d

Please sign in to comment.