]> git.mdlowis.com Git - proto/labwc.git/commitdiff
menu: vertically center-align items
authorJohan Malm <jgm323@gmail.com>
Wed, 21 Oct 2020 19:32:08 +0000 (20:32 +0100)
committerJohan Malm <jgm323@gmail.com>
Wed, 21 Oct 2020 19:32:08 +0000 (20:32 +0100)
src/menu/menu.c

index c6c772bcc858df511f010bb6b383a25bb42e58e3..048e7d9e1ab1fdd58771f79e07deae995afbbdaa 100644 (file)
@@ -4,12 +4,17 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include "common/font.h"
 #include "labwc.h"
 #include "menu/menu.h"
 
 static float background[4] = { 0.3f, 0.1f, 0.1f, 1.0f };
 static float foreground[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
-static const char font[] = "Sans 11";
+static const char font[] = "Sans 10";
+
+#define MENUWIDTH (100)
+#define MENUHEIGHT (25)
+#define MENU_PADDING_WIDTH (7)
 
 struct wlr_texture *
 texture_create(struct server *server, struct wlr_box *geo, const char *text,
@@ -32,6 +37,12 @@ texture_create(struct server *server, struct wlr_box *geo, const char *text,
        pango_layout_set_font_description(layout, desc);
        pango_font_description_free(desc);
        pango_cairo_update_layout(cairo, layout);
+
+       /* center-align vertically */
+       int height;
+       pango_layout_get_pixel_size(layout, NULL, &height);
+       cairo_move_to(cairo, MENU_PADDING_WIDTH, (geo->height - height) / 2);
+
        pango_cairo_show_layout(cairo, layout);
        g_object_unref(layout);
 
@@ -46,9 +57,6 @@ texture_create(struct server *server, struct wlr_box *geo, const char *text,
        return texture;
 }
 
-#define MENUWIDTH (100)
-#define MENUHEIGHT (25)
-
 struct menuitem *
 menuitem_create(struct server *server, struct menu *menu, const char *text,
        const char *action, const char *command)
@@ -87,7 +95,7 @@ menu_move(struct menu *menu, int x, int y)
 
        int offset = 0;
        struct menuitem *menuitem;
-       wl_list_for_each (menuitem, &menu->menuitems, link) {
+       wl_list_for_each_reverse (menuitem, &menu->menuitems, link) {
                menuitem->geo_box.x = menu->x;
                menuitem->geo_box.y = menu->y + offset;
                offset += menuitem->geo_box.height;