font: remove 4px padding on the right

Added `menu.items.padding.x` padding between item text and arrow instead.

Replaced `if (!string)` with `if (string_null_or_empty(string))` in
`font_extents()` just as a minor optimization.
This commit is contained in:
tokyo4j 2025-09-21 20:40:49 +09:00 committed by Johan Malm
parent 141f932efa
commit ebce406b11
3 changed files with 6 additions and 11 deletions

View file

@ -22,7 +22,7 @@ static PangoRectangle
font_extents(struct font *font, const char *string)
{
PangoRectangle rect = { 0 };
if (!string) {
if (string_null_or_empty(string)) {
return rect;
}
cairo_surface_t *surface;
@ -43,10 +43,6 @@ font_extents(struct font *font, const char *string)
pango_layout_get_extents(layout, NULL, &rect);
pango_extents_to_pixels(&rect, NULL);
/* we put a 2 px edge on each side - because Openbox does it :) */
/* TODO: remove the 4 pixel addition and always do the padding by the caller */
rect.width += 4;
cairo_destroy(c);
cairo_surface_destroy(surface);
pango_font_description_free(desc);

View file

@ -135,6 +135,7 @@ item_create(struct menu *menu, const char *text, const char *icon_name, bool sho
assert(menu);
assert(text);
struct theme *theme = menu->server->theme;
struct menuitem *menuitem = znew(*menuitem);
menuitem->parent = menu;
menuitem->selectable = true;
@ -151,7 +152,8 @@ item_create(struct menu *menu, const char *text, const char *icon_name, bool sho
menuitem->native_width = font_width(&rc.font_menuitem, text);
if (menuitem->arrow) {
menuitem->native_width += font_width(&rc.font_menuitem, menuitem->arrow);
menuitem->native_width += font_width(&rc.font_menuitem, menuitem->arrow)
+ theme->menu_items_padding_x;
}
wl_list_append(&menu->menuitems, &menuitem->link);
@ -177,7 +179,7 @@ item_create_scene_for_state(struct menuitem *item, float *text_color,
int bg_width = menu->size.width - 2 * theme->menu_border_width;
int arrow_width = item->arrow ?
font_width(&rc.font_menuitem, item->arrow) : 0;
font_width(&rc.font_menuitem, item->arrow) + theme->menu_items_padding_x : 0;
int label_max_width = bg_width - 2 * theme->menu_items_padding_x
- arrow_width - icon_width;
@ -227,7 +229,7 @@ item_create_scene_for_state(struct menuitem *item, float *text_color,
scaled_font_buffer_update(arrow_buffer, item->arrow, -1,
&rc.font_menuitem, text_color, bg_color);
/* Vertically center and right-align arrow */
x += label_max_width;
x += label_max_width + theme->menu_items_padding_x;
y = (theme->menu_item_height - label_buffer->height) / 2;
wlr_scene_node_set_position(&arrow_buffer->scene_buffer->node, x, y);

View file

@ -193,9 +193,6 @@ resize_indicator_update(struct view *view)
/* Let the indicator change width as required by the content */
int width = font_width(&rc.font_osd, text);
/* font_extents() adds 4 pixels to the calculated width */
width -= 4;
resize_indicator_set_size(indicator, width);
/* Center the indicator in the window */