menu: add title theme options (#2097)

Add theme options `menu.title.text.color` and `menu.title.text.justify`.

Add font place MenuHeader: `<font place="MenuHeader">`

Add `Oblique` font style

```
<theme>
  <font>
    <slant>Oblique</slant>
  </font>
</theme>
```
This commit is contained in:
droc12345 2024-08-21 12:27:07 -05:00 committed by GitHub
parent 6564e1bc8d
commit 8fda9968e6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 79 additions and 7 deletions

View file

@ -141,6 +141,19 @@ menu_update_width(struct menu *menu)
wlr_scene_rect_set_size(
wlr_scene_rect_from_node(item->normal.text),
width, theme->menu_separator_line_thickness);
} else if (item->type == LAB_MENU_TITLE) {
if (item->native_width > max_width) {
scaled_font_buffer_set_max_width(item->normal.buffer,
max_width);
}
if (theme->menu_title_text_justify == LAB_JUSTIFY_CENTER) {
int x, y;
x = (max_width - theme->menu_item_padding_x -
item->native_width) / 2;
x = x < 0 ? 0 : x;
y = (theme->menu_item_height - item->normal.buffer->height) / 2;
wlr_scene_node_set_position(item->normal.text, x, y);
}
}
if (item->selectable) {
@ -295,7 +308,7 @@ separator_create(struct menu *menu, const char *label)
if (menuitem->type == LAB_MENU_TITLE) {
menuitem->height = theme->menu_item_height;
menuitem->native_width = font_width(&rc.font_menuitem, label);
menuitem->native_width = font_width(&rc.font_menuheader, label);
} else if (menuitem->type == LAB_MENU_SEPARATOR_LINE) {
menuitem->height = theme->menu_separator_line_thickness +
2 * theme->menu_separator_padding_height;
@ -312,6 +325,8 @@ separator_create(struct menu *menu, const char *label)
/* Item background nodes */
float *bg_color = menuitem->type == LAB_MENU_TITLE
? theme->menu_title_bg_color : theme->menu_items_bg_color;
float *text_color = menuitem->type == LAB_MENU_TITLE
? theme->menu_title_text_color : theme->menu_items_text_color;
menuitem->normal.background = &wlr_scene_rect_create(
menuitem->normal.tree,
menu->size.width, menuitem->height, bg_color)->node;
@ -328,8 +343,8 @@ separator_create(struct menu *menu, const char *label)
menuitem->normal.text = &menuitem->normal.buffer->scene_buffer->node;
/* Font buffer */
scaled_font_buffer_update(menuitem->normal.buffer, label,
menuitem->native_width, &rc.font_menuitem,
theme->menu_items_text_color, bg_color, /* arrow */ NULL);
menuitem->native_width, &rc.font_menuheader,
text_color, bg_color, /* arrow */ NULL);
/* Center font nodes */
int x, y;
x = theme->menu_item_padding_x;