mirror of
https://github.com/labwc/labwc.git
synced 2025-11-03 09:01:51 -05:00
font: remove arrow character from font buffer
Arrow signs are specific to submenu items, so they would be more natural to be handled in menu.c rather than accepting "arrow" in font_buffer_create(). Also I allowed non-positive numbers for max_width in font_buffer_create(), in which case the natural font width is used as the buffer width.
This commit is contained in:
parent
10fc656c23
commit
01032ef3bd
7 changed files with 28 additions and 43 deletions
|
|
@ -168,18 +168,32 @@ item_create_scene_for_state(struct menuitem *item, float *text_color,
|
|||
|
||||
int arrow_width = item->arrow ?
|
||||
font_width(&rc.font_menuitem, item->arrow) : 0;
|
||||
int text_width = bg_width - 2 * theme->menu_items_padding_x - arrow_width;
|
||||
int label_max_width = bg_width - 2 * theme->menu_items_padding_x - arrow_width;
|
||||
|
||||
/* Create label */
|
||||
struct scaled_font_buffer *label_buffer = scaled_font_buffer_create(tree);
|
||||
assert(label_buffer);
|
||||
scaled_font_buffer_update(label_buffer, item->text, text_width,
|
||||
&rc.font_menuitem, text_color, bg_color, item->arrow);
|
||||
scaled_font_buffer_update(label_buffer, item->text, label_max_width,
|
||||
&rc.font_menuitem, text_color, bg_color);
|
||||
/* Vertically center and left-align label */
|
||||
int x = theme->menu_items_padding_x;
|
||||
int y = (theme->menu_item_height - label_buffer->height) / 2;
|
||||
wlr_scene_node_set_position(&label_buffer->scene_buffer->node, x, y);
|
||||
|
||||
if (!item->arrow) {
|
||||
return tree;
|
||||
}
|
||||
|
||||
/* Create arrow for submenu items */
|
||||
struct scaled_font_buffer *arrow_buffer = scaled_font_buffer_create(tree);
|
||||
assert(arrow_buffer);
|
||||
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;
|
||||
y = (theme->menu_item_height - label_buffer->height) / 2;
|
||||
wlr_scene_node_set_position(&arrow_buffer->scene_buffer->node, x, y);
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
|
|
@ -298,7 +312,7 @@ title_create_scene(struct menuitem *menuitem, int *item_y)
|
|||
assert(title_font_buffer);
|
||||
scaled_font_buffer_update(title_font_buffer, menuitem->text,
|
||||
bg_width - 2 * theme->menu_items_padding_x,
|
||||
&rc.font_menuheader, text_color, bg_color, /* arrow */ NULL);
|
||||
&rc.font_menuheader, text_color, bg_color);
|
||||
|
||||
int title_x = 0;
|
||||
switch (theme->menu_title_text_justify) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue