mirror of
https://github.com/Cloudef/bemenu
synced 2025-03-11 10:17:28 +00:00
revert to single padding variable
but with height instead of ascii_height used as the box height
This commit is contained in:
parent
2eea64ad24
commit
b7f8db7128
@ -214,19 +214,10 @@ bm_cairo_paint(struct cairo *cairo, uint32_t width, uint32_t max_height, const s
|
|||||||
assert(cairo && menu && out_result);
|
assert(cairo && menu && out_result);
|
||||||
|
|
||||||
max_height /= cairo->scale;
|
max_height /= cairo->scale;
|
||||||
uint32_t height = fmin(menu->line_height, max_height);
|
|
||||||
|
|
||||||
memset(out_result, 0, sizeof(struct cairo_paint_result));
|
memset(out_result, 0, sizeof(struct cairo_paint_result));
|
||||||
out_result->displayed = 1;
|
out_result->displayed = 1;
|
||||||
|
|
||||||
cairo_set_source_rgba(cairo->cr, 0, 0, 0, 0);
|
|
||||||
cairo_rectangle(cairo->cr, 0, 0, width, height);
|
|
||||||
|
|
||||||
cairo_save(cairo->cr);
|
|
||||||
cairo_set_operator(cairo->cr, CAIRO_OPERATOR_CLEAR);
|
|
||||||
cairo_paint(cairo->cr);
|
|
||||||
cairo_restore(cairo->cr);
|
|
||||||
|
|
||||||
struct cairo_paint paint = {0};
|
struct cairo_paint paint = {0};
|
||||||
paint.font = menu->font.name;
|
paint.font = menu->font.name;
|
||||||
|
|
||||||
@ -237,16 +228,24 @@ bm_cairo_paint(struct cairo *cairo, uint32_t width, uint32_t max_height, const s
|
|||||||
ascii_height = result.height;
|
ascii_height = result.height;
|
||||||
paint.baseline = result.baseline;
|
paint.baseline = result.baseline;
|
||||||
|
|
||||||
int32_t vpadding_t = height == 0 ? 2 : (height - ascii_height) / 2;
|
uint32_t height = fmin(fmax(menu->line_height, ascii_height), max_height);
|
||||||
int32_t vpadding_b = vpadding_t + (height - ascii_height) % 2;
|
uint32_t vpadding = (height - ascii_height)/2;
|
||||||
|
|
||||||
|
cairo_set_source_rgba(cairo->cr, 0, 0, 0, 0);
|
||||||
|
cairo_rectangle(cairo->cr, 0, 0, width, height);
|
||||||
|
|
||||||
|
cairo_save(cairo->cr);
|
||||||
|
cairo_set_operator(cairo->cr, CAIRO_OPERATOR_CLEAR);
|
||||||
|
cairo_paint(cairo->cr);
|
||||||
|
cairo_restore(cairo->cr);
|
||||||
|
|
||||||
memset(&result, 0, sizeof(result));
|
memset(&result, 0, sizeof(result));
|
||||||
uint32_t title_x = 0;
|
uint32_t title_x = 0;
|
||||||
if (menu->title) {
|
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_FG, &paint.fg);
|
||||||
bm_cairo_color_from_menu_color(menu, BM_COLOR_TITLE_BG, &paint.bg);
|
bm_cairo_color_from_menu_color(menu, BM_COLOR_TITLE_BG, &paint.bg);
|
||||||
paint.pos = (struct pos){ result.x_advance, vpadding_t };
|
paint.pos = (struct pos){ result.x_advance, vpadding };
|
||||||
paint.box = (struct box){ 4, 8, vpadding_t, vpadding_b, 0, ascii_height };
|
paint.box = (struct box){ 4, 8, vpadding, -vpadding, 0, height };
|
||||||
bm_cairo_draw_line(cairo, &paint, &result, "%s", menu->title);
|
bm_cairo_draw_line(cairo, &paint, &result, "%s", menu->title);
|
||||||
title_x = result.x_advance;
|
title_x = result.x_advance;
|
||||||
}
|
}
|
||||||
@ -256,8 +255,8 @@ bm_cairo_paint(struct cairo *cairo, uint32_t width, uint32_t max_height, const s
|
|||||||
paint.draw_cursor = true;
|
paint.draw_cursor = true;
|
||||||
paint.cursor = menu->cursor;
|
paint.cursor = menu->cursor;
|
||||||
paint.cursor_height = menu->cursor_height;
|
paint.cursor_height = menu->cursor_height;
|
||||||
paint.pos = (struct pos){ (menu->title ? 2 : 0) + result.x_advance, vpadding_t };
|
paint.pos = (struct pos){ (menu->title ? 2 : 0) + result.x_advance, vpadding };
|
||||||
paint.box = (struct box){ (menu->title ? 2 : 4), 0, vpadding_t, vpadding_b, width - paint.pos.x, ascii_height };
|
paint.box = (struct box){ (menu->title ? 2 : 4), 0, vpadding, -vpadding, width - paint.pos.x, height };
|
||||||
|
|
||||||
const char *filter_text = (menu->filter ? menu->filter : "");
|
const char *filter_text = (menu->filter ? menu->filter : "");
|
||||||
if (menu->password) {
|
if (menu->password) {
|
||||||
@ -315,12 +314,12 @@ bm_cairo_paint(struct cairo *cairo, uint32_t width, uint32_t max_height, const s
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (menu->prefix && highlighted) {
|
if (menu->prefix && highlighted) {
|
||||||
paint.pos = (struct pos){ spacing_x, vpadding_t + posy };
|
paint.pos = (struct pos){ spacing_x, posy+vpadding };
|
||||||
paint.box = (struct box){ 4, 0, vpadding_t, vpadding_b, width - paint.pos.x, ascii_height };
|
paint.box = (struct box){ 4, 0, vpadding, -vpadding, width - paint.pos.x, height };
|
||||||
bm_cairo_draw_line(cairo, &paint, &result, "%s %s", menu->prefix, (items[i]->text ? items[i]->text : ""));
|
bm_cairo_draw_line(cairo, &paint, &result, "%s %s", menu->prefix, (items[i]->text ? items[i]->text : ""));
|
||||||
} else {
|
} else {
|
||||||
paint.pos = (struct pos){ spacing_x, vpadding_t + posy };
|
paint.pos = (struct pos){ spacing_x, posy+vpadding };
|
||||||
paint.box = (struct box){ 4 + prefix_x, 0, vpadding_t, vpadding_b, width - paint.pos.x, ascii_height };
|
paint.box = (struct box){ 4 + prefix_x, 0, vpadding, -vpadding, width - paint.pos.x, height };
|
||||||
bm_cairo_draw_line(cairo, &paint, &result, "%s", (items[i]->text ? items[i]->text : ""));
|
bm_cairo_draw_line(cairo, &paint, &result, "%s", (items[i]->text ? items[i]->text : ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -359,8 +358,8 @@ bm_cairo_paint(struct cairo *cairo, uint32_t width, uint32_t max_height, const s
|
|||||||
uint32_t cl = fmin(title_x + result.x_advance, width / 4);
|
uint32_t cl = fmin(title_x + result.x_advance, width / 4);
|
||||||
|
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
paint.pos = (struct pos){ cl, vpadding_t };
|
paint.pos = (struct pos){ cl, vpadding };
|
||||||
paint.box = (struct box){ 1, 2, vpadding_t, vpadding_b, 0, ascii_height };
|
paint.box = (struct box){ 1, 2, vpadding, -vpadding, 0, height };
|
||||||
bm_cairo_draw_line(cairo, &paint, &result, (count > 0 && (menu->wrap || menu->index > 0) ? "<" : " "));
|
bm_cairo_draw_line(cairo, &paint, &result, (count > 0 && (menu->wrap || menu->index > 0) ? "<" : " "));
|
||||||
cl += result.x_advance + 1;
|
cl += result.x_advance + 1;
|
||||||
}
|
}
|
||||||
@ -379,8 +378,8 @@ bm_cairo_paint(struct cairo *cairo, uint32_t width, uint32_t max_height, const s
|
|||||||
bm_cairo_color_from_menu_color(menu, BM_COLOR_ITEM_BG, &paint.bg);
|
bm_cairo_color_from_menu_color(menu, BM_COLOR_ITEM_BG, &paint.bg);
|
||||||
}
|
}
|
||||||
|
|
||||||
paint.pos = (struct pos){ cl, vpadding_t };
|
paint.pos = (struct pos){ cl, vpadding };
|
||||||
paint.box = (struct box){ 2, 4, vpadding_t, vpadding_b, 0, ascii_height };
|
paint.box = (struct box){ 2, 4, vpadding, -vpadding, 0, height };
|
||||||
bm_cairo_draw_line(cairo, &paint, &result, "%s", (items[i]->text ? items[i]->text : ""));
|
bm_cairo_draw_line(cairo, &paint, &result, "%s", (items[i]->text ? items[i]->text : ""));
|
||||||
cl += result.x_advance + 2;
|
cl += result.x_advance + 2;
|
||||||
out_result->displayed += (cl < width);
|
out_result->displayed += (cl < width);
|
||||||
@ -391,8 +390,8 @@ bm_cairo_paint(struct cairo *cairo, uint32_t width, uint32_t max_height, const s
|
|||||||
bm_cairo_color_from_menu_color(menu, BM_COLOR_FILTER_FG, &paint.fg);
|
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_cairo_color_from_menu_color(menu, BM_COLOR_FILTER_BG, &paint.bg);
|
||||||
bm_pango_get_text_extents(cairo, &paint, &result, ">");
|
bm_pango_get_text_extents(cairo, &paint, &result, ">");
|
||||||
paint.pos = (struct pos){ width/cairo->scale - result.x_advance - 2, vpadding_t };
|
paint.pos = (struct pos){ width/cairo->scale - result.x_advance - 2, vpadding };
|
||||||
paint.box = (struct box){ 1, 2, vpadding_t, vpadding_b, 0, ascii_height };
|
paint.box = (struct box){ 1, 2, vpadding, -vpadding, 0, height };
|
||||||
bm_cairo_draw_line(cairo, &paint, &result, ">");
|
bm_cairo_draw_line(cairo, &paint, &result, ">");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user