refactor: DRY repetive code to calculate row_bg_x()
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Adds new documented function and updates callers to use it.
authored by Mark Stosberg · committed by Daniel Eklöf · parent 1656dfb · Browse files · 1 file·+22 added−14 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+22 added−14 removed
- other:+22 added−14 removed
Provenance
- Commit
15b478d- Tree
7e31de6- Author
Mark Stosberg <mark@stosberg.com>- Committer
Daniel Eklöf <daniel@ekloef.se>- Parent
1656dfb
1 file changed+22 added−14 removed
modified:render.c+22 added-14 removed
621 unmodified lines622 }623 624 }625 626+/*627+ * Returns the x-coordinate of the left edge of the row background area.628+ * The background extends slightly past the text content edge (border + x_margin)629+ * by sel_margin (= x_margin / 3) on each side, so the selection highlight630+ * has a small gap from the window border while bleeding into the margin.631+ */632+static int633+row_bg_x(const struct render *render)634+{635+ const int sel_margin = render->x_margin / 3;636+ return render->border_size + render->x_margin - sel_margin;637+}638+639 void640 render_message(struct render *render, struct buffer *buf)641 {642 if (!render->conf->message) return;18 unmodified lines661 //pixman_color_t bg = (pixman_color_t){0xffff, 0, 0, 0xffff};662 pixman_image_fill_rectangles(663 PIXMAN_OP_SRC, buf->pix[0], &bg, 1,664 &(pixman_rectangle16_t){652- render->border_size + render->x_margin - render->x_margin / 3,665+ row_bg_x(render),666 render->border_size + render->y_margin,654- buf->width - 2 * (render->border_size + render->x_margin - render->x_margin / 3),667+ buf->width - 2 * row_bg_x(render),668 render->message_height});669 670 struct fcft_text_run *message_run = render->message_text_run;671 122 unmodified lines794 //pixman_color_t bg = (pixman_color_t){0xffff, 0, 0, 0xffff};795 pixman_image_fill_rectangles(796 PIXMAN_OP_SRC, buf->pix[0], &bg, 1,797 &(pixman_rectangle16_t){785- render->border_size + render->x_margin - render->x_margin / 3,798+ row_bg_x(render),799 render->border_size + render->y_margin + render->message_height,787- buf->width - 2 * (render->border_size + render->x_margin - render->x_margin / 3),800+ buf->width - 2 * row_bg_x(render),801 render->row_height});802 803 #if 0804 bg = (pixman_color_t){0, 0xffff, 0, 0xffff};796 unmodified lines1601 pixman_image_t *pix, int width)1602 {1603 pixman_color_t bg = render->pix_background_color;1604 1592- const int sel_margin = render->x_margin / 3;1593-1594- const int x = render->border_size + render->x_margin - sel_margin;1605+ const int x = row_bg_x(render);1606 const int y = first_row_y(render) + idx * render->row_height;1596- const int w = width - 2 * (render->border_size + render->x_margin - sel_margin);1607+ const int w = width - 2 * row_bg_x(render);1608 const int h = row_count * render->row_height;1609 1610 pixman_image_fill_rectangles(1611 PIXMAN_OP_SRC, pix, &bg, 1, &(pixman_rectangle16_t){x, y, w, h});4 unmodified lines1616 int idx, pixman_image_t *pix, int width)1617 {1618 pixman_color_t bg = render->pix_selection_color;1619 1609- const int sel_margin = render->x_margin / 3;1610-1611- const int x = render->border_size + render->x_margin - sel_margin;1620+ const int x = row_bg_x(render);1621 const int y = first_row_y(render) + idx * render->row_height;1613- const int w = width - 2 * (render->border_size + render->x_margin - sel_margin);1622+ const int w = width - 2 * row_bg_x(render);1623 const int h = 1 * render->row_height;1624 1625 // limit radius to half of height, any larger and it causes weird shapes1626 // also limit it when horizontal padding is small, to prevent icon pop out532 unmodified lines2159 ssize_t2160 render_get_row_num(const struct render *render, int width, int x, int y,2161 const struct matches *matches)2162 {2154- const int border_size = render->border_size;2163 const int row_height = render->row_height;2164 2157- const int min_x = border_size + render->x_margin - render->x_margin / 3;2165+ const int min_x = row_bg_x(render);2166 const int max_x = width - (min_x);2167 2168 const int first_row = first_row_y(render);2169 21 unmodified lines