]> git.mdlowis.com Git - proto/labwc.git/commitdiff
menu: Convert hardcoded item padding to theme vars
authorConsolatis <35009135+Consolatis@users.noreply.github.com>
Tue, 6 Dec 2022 13:38:56 +0000 (14:38 +0100)
committerJohan Malm <johanmalm@users.noreply.github.com>
Tue, 6 Dec 2022 21:08:43 +0000 (21:08 +0000)
Adds two new theme vars:
- menu.items.padding.x
- menu.items.padding.y

docs/labwc-theme.5.scd
include/theme.h
src/menu/menu.c
src/theme.c

index 6593728baafcf3f789ea5a09b916a9341793b588..af431479a117aa449554d5d09cc7544690139232 100644 (file)
@@ -41,6 +41,14 @@ A theme consists of a themerc file and optionally some xbm icons.
        Vertical padding size, used for spacing out elements in the window decorations.
        Default is 3.
 
+*menu.items.padding.x*
+       Horizontal padding of menu text entries in pixels.
+       Default is 7.
+
+*menu.items.padding.y*
+       Vertical padding of menu text entries in pixels.
+       Default is 4.
+
 *menu.overlap.x*
        Horizontal overlap in pixels between submenus and their parents. A
        positive value move submenus over the top of their parents, whereas a
index d869234969faa5282c6511b7da49ca2a37623277..359724814962f1d866571619587252450bcc2066 100644 (file)
@@ -45,6 +45,9 @@ struct theme {
        float window_inactive_button_close_unpressed_image_color[4];
        /* TODO: add pressed and hover colors for buttons */
 
+       int menu_item_padding_x;
+       int menu_item_padding_y;
+
        float menu_items_bg_color[4];
        float menu_items_text_color[4];
        float menu_items_active_bg_color[4];
index b27c6331a5eade1bece2541347ad2752398d8d8d..f02939ef08dc070db14e2b60e223a3f46aa2a577 100644 (file)
@@ -24,8 +24,6 @@
 #include "theme.h"
 
 #define MENUWIDTH (110)
-#define MENU_ITEM_PADDING_Y (4)
-#define MENU_ITEM_PADDING_X (7)
 
 /* state-machine variables for processing <item></item> */
 static bool in_item;
@@ -88,12 +86,12 @@ item_create(struct menu *menu, const char *text, bool show_arrow)
 
        if (!menu->item_height) {
                menu->item_height = font_height(&rc.font_menuitem)
-                       + 2 * MENU_ITEM_PADDING_Y;
+                       + 2 * theme->menu_item_padding_y;
        }
        menuitem->height = menu->item_height;
 
        int x, y;
-       int item_max_width = MENUWIDTH - 2 * MENU_ITEM_PADDING_X;
+       int item_max_width = MENUWIDTH - 2 * theme->menu_item_padding_x;
 
        /* Menu item root node */
        menuitem->tree = wlr_scene_tree_create(menu->scene_tree);
@@ -138,7 +136,7 @@ item_create(struct menu *menu, const char *text, bool show_arrow)
                &rc.font_menuitem, theme->menu_items_active_text_color, arrow);
 
        /* Center font nodes */
-       x = MENU_ITEM_PADDING_X;
+       x = theme->menu_item_padding_x;
        y = (menu->item_height - menuitem->normal.buffer->height) / 2;
        wlr_scene_node_set_position(menuitem->normal.text, x, y);
        y = (menu->item_height - menuitem->selected.buffer->height) / 2;
index f56ba8e5daf9ae4faa51b21e8d3f707ab02b7fd3..5ae471ce02a9fd87af8bcb64b757b38569d8ae80 100644 (file)
@@ -128,6 +128,9 @@ theme_builtin(struct theme *theme)
        parse_hexstr("#dddad6", theme->menu_items_active_bg_color);
        parse_hexstr("#000000", theme->menu_items_active_text_color);
 
+       theme->menu_item_padding_x = 7;
+       theme->menu_item_padding_y = 4;
+
        theme->menu_separator_line_thickness = 1;
        theme->menu_separator_padding_width = 6;
        theme->menu_separator_padding_height = 3;
@@ -167,6 +170,12 @@ entry(struct theme *theme, const char *key, const char *value)
        if (match(key, "padding.height")) {
                theme->padding_height = atoi(value);
        }
+       if (match(key, "menu.items.padding.x")) {
+               theme->menu_item_padding_x = atoi(value);
+       }
+       if (match(key, "menu.items.padding.y")) {
+               theme->menu_item_padding_y = atoi(value);
+       }
        if (match(key, "menu.overlap.x")) {
                theme->menu_overlap_x = atoi(value);
        }