diff options
author | Jari Vetoniemi <mailRoxas@gmail.com> | 2019-06-01 22:09:52 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-01 22:09:52 +0300 |
commit | 572470ef8cc4725728b239fe5fa65f62f9d70dd4 (patch) | |
tree | 8fa42cf9f947df05dc5ee872f847deac2113a880 /lib/renderers/cairo.h | |
parent | dac040f659fe90a520591e7179de19d6279e4d29 (diff) | |
parent | 93cde4831bca7055c38a1d6246fdcb84df07f7ec (diff) | |
download | bemenu-572470ef8cc4725728b239fe5fa65f62f9d70dd4.tar.gz bemenu-572470ef8cc4725728b239fe5fa65f62f9d70dd4.tar.bz2 bemenu-572470ef8cc4725728b239fe5fa65f62f9d70dd4.zip |
Merge pull request #57 from alyssais/line-height
bemenu: add --line-height / -H option
Diffstat (limited to 'lib/renderers/cairo.h')
-rw-r--r-- | lib/renderers/cairo.h | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/lib/renderers/cairo.h b/lib/renderers/cairo.h index cdb477d..c5a3be4 100644 --- a/lib/renderers/cairo.h +++ b/lib/renderers/cairo.h @@ -166,10 +166,12 @@ bm_cairo_color_from_menu_color(const struct bm_menu *menu, enum bm_color color, } __attribute__((unused)) static void -bm_cairo_paint(struct cairo *cairo, uint32_t width, uint32_t height, uint32_t max_height, const struct bm_menu *menu, struct cairo_paint_result *out_result) +bm_cairo_paint(struct cairo *cairo, uint32_t width, uint32_t max_height, const struct bm_menu *menu, struct cairo_paint_result *out_result) { assert(cairo && menu && out_result); + uint32_t height = fmin(menu->line_height, max_height); + memset(out_result, 0, sizeof(struct cairo_paint_result)); out_result->displayed = 1; @@ -189,21 +191,23 @@ bm_cairo_paint(struct cairo *cairo, uint32_t width, uint32_t height, uint32_t ma ascii_height = result.height; paint.baseline = result.baseline; + int32_t vpadding = height == 0 ? 2 : (height - ascii_height) / 2; + memset(&result, 0, sizeof(result)); uint32_t title_x = 0; if (menu->title) { bm_cairo_color_from_menu_color(menu, BM_COLOR_TITLE_FG, &paint.fg); bm_cairo_color_from_menu_color(menu, BM_COLOR_TITLE_BG, &paint.bg); - paint.pos = (struct pos){ result.x_advance, 2 }; - paint.box = (struct box){ 4, 8, 2, 2, 0, ascii_height }; + paint.pos = (struct pos){ result.x_advance, vpadding }; + paint.box = (struct box){ 4, 8, vpadding, vpadding, 0, ascii_height }; bm_cairo_draw_line(cairo, &paint, &result, "%s", menu->title); title_x = result.x_advance; } bm_cairo_color_from_menu_color(menu, BM_COLOR_FILTER_FG, &paint.fg); bm_cairo_color_from_menu_color(menu, BM_COLOR_FILTER_BG, &paint.bg); - paint.pos = (struct pos){ (menu->title ? 2 : 0) + result.x_advance, 2 }; - paint.box = (struct box){ (menu->title ? 2 : 4), 0, 2, 2, width - paint.pos.x, ascii_height }; + paint.pos = (struct pos){ (menu->title ? 2 : 0) + result.x_advance, vpadding }; + paint.box = (struct box){ (menu->title ? 2 : 4), 0, vpadding, vpadding, width - paint.pos.x, ascii_height }; bm_cairo_draw_line(cairo, &paint, &result, "%s", (menu->filter ? menu->filter : "")); const uint32_t titleh = result.height; out_result->height = titleh; @@ -247,12 +251,12 @@ bm_cairo_paint(struct cairo *cairo, uint32_t width, uint32_t height, uint32_t ma } if (menu->prefix && highlighted) { - paint.pos = (struct pos){ 0, 2 + posy }; - paint.box = (struct box){ 4 + spacing_x, 0, 2, 2, width - paint.pos.x, ascii_height }; + paint.pos = (struct pos){ 0, vpadding + posy }; + paint.box = (struct box){ 4 + spacing_x, 0, vpadding, vpadding, width - paint.pos.x, ascii_height }; bm_cairo_draw_line(cairo, &paint, &result, "%s %s", menu->prefix, (items[i]->text ? items[i]->text : "")); } else { - paint.pos = (struct pos){ 0, 2 + posy }; - paint.box = (struct box){ 4 + spacing_x + prefix_x, 0, 2, 2, width - paint.pos.x, ascii_height }; + paint.pos = (struct pos){ 0, vpadding + posy }; + paint.box = (struct box){ 4 + spacing_x + prefix_x, 0, vpadding, vpadding, width - paint.pos.x, ascii_height }; bm_cairo_draw_line(cairo, &paint, &result, "%s", (items[i]->text ? items[i]->text : "")); } @@ -283,8 +287,8 @@ bm_cairo_paint(struct cairo *cairo, uint32_t width, uint32_t height, uint32_t ma uint32_t cl = fmin(title_x + result.x_advance, width / 4); if (menu->wrap || menu->index > 0) { - paint.pos = (struct pos){ cl, 2 }; - paint.box = (struct box){ 1, 2, 2, 2, 0, ascii_height }; + paint.pos = (struct pos){ cl, vpadding }; + paint.box = (struct box){ 1, 2, vpadding, vpadding, 0, ascii_height }; bm_cairo_draw_line(cairo, &paint, &result, "<"); cl += result.x_advance + 1; } @@ -303,8 +307,8 @@ bm_cairo_paint(struct cairo *cairo, uint32_t width, uint32_t height, uint32_t ma bm_cairo_color_from_menu_color(menu, BM_COLOR_ITEM_BG, &paint.bg); } - paint.pos = (struct pos){ cl, 2 }; - paint.box = (struct box){ 2, 4, 2, 2, 0, ascii_height }; + paint.pos = (struct pos){ cl, vpadding }; + paint.box = (struct box){ 2, 4, vpadding, vpadding, 0, ascii_height }; bm_cairo_draw_line(cairo, &paint, &result, "%s", (items[i]->text ? items[i]->text : "")); cl += result.x_advance + 2; out_result->displayed += (cl < width); @@ -315,8 +319,8 @@ bm_cairo_paint(struct cairo *cairo, uint32_t width, uint32_t height, uint32_t ma bm_cairo_color_from_menu_color(menu, BM_COLOR_FILTER_FG, &paint.fg); bm_cairo_color_from_menu_color(menu, BM_COLOR_FILTER_BG, &paint.bg); bm_pango_get_text_extents(cairo, &paint, &result, ">"); - paint.pos = (struct pos){ width - result.x_advance - 2, 2 }; - paint.box = (struct box){ 1, 2, 2, 2, 0, ascii_height }; + paint.pos = (struct pos){ width - result.x_advance - 2, vpadding }; + paint.box = (struct box){ 1, 2, vpadding, vpadding, 0, ascii_height }; bm_cairo_draw_line(cairo, &paint, &result, ">"); } } |