Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Match/Page Counter(Addresses #204) #325

Merged
merged 8 commits into from
Dec 27, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/bemenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,6 @@ BM_PUBLIC void bm_menu_set_border_radius(struct bm_menu* menu, uint32_t border_r

BM_PUBLIC uint32_t bm_menu_get_border_radius(struct bm_menu* menu);


/**
* Set a hexadecimal color for element.
*
Expand Down
3 changes: 2 additions & 1 deletion lib/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -771,14 +771,15 @@ bm_menu_filter(struct bm_menu *menu)
list_free_list(&menu->filtered);
free(menu->old_filter);
menu->old_filter = NULL;

menu->filtered.count = menu->items.count;
return;
}

if (menu->old_filter) {
size_t oldLen = strlen(menu->old_filter);
addition = (oldLen < len && !memcmp(menu->old_filter, menu->filter, oldLen));
}

if (menu->old_filter && addition && menu->filtered.count <= 0)
return;

Expand Down
14 changes: 11 additions & 3 deletions lib/renderers/cairo_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,9 @@ bm_cairo_paint(struct cairo *cairo, uint32_t width, uint32_t max_height, const s

uint32_t border_radius = menu->border_radius;

uint32_t total_item_count = menu->items.count;
uint32_t filtered_item_count = menu->filtered.count;

cairo_set_source_rgba(cairo->cr, 0, 0, 0, 0);
cairo_rectangle(cairo->cr, 0, 0, width, height);

Expand Down Expand Up @@ -469,15 +472,20 @@ bm_cairo_paint(struct cairo *cairo, uint32_t width, uint32_t max_height, const s
out_result->displayed += (cl < width);
out_result->height = fmax(out_result->height, result.height);
}

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);
if (menu->wrap || menu->index + 1 < count) {
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/cairo->scale - result.x_advance - 2, vpadding + border_size };
paint.box = (struct box){ 1, 2, vpadding, -vpadding, 0, height };
bm_cairo_draw_line(cairo, &paint, &result, ">");
}
char counter[128];
snprintf(counter, sizeof(counter), "[%u/%u]", filtered_item_count, total_item_count);
bm_pango_get_text_extents(cairo, &paint, &result, "%s", counter);
paint.pos = (struct pos){ width/cairo->scale - result.x_advance - 10, vpadding + border_size };
paint.box = (struct box){ 1, 2, vpadding, -vpadding, 0, height };
bm_cairo_draw_line(cairo, &paint, &result, "%s", counter);
}

// Draw borders
Expand Down