render: regression: cursor alignment with custom line-height
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Implement a common function that calculates a lines baseline, and use this when positioning both text and the cursor. Closes #403
authored by Daniel Eklöf · committed by Daniel Eklöf · parent b6b9d5a · Browse files · 2 files·+31 added−8 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+31 added−8 removed
- other:+31 added−8 removed
Provenance
- Commit
20660ef- Tree
e80d352- Author
Daniel Eklöf <daniel@ekloef.se>- Committer
Daniel Eklöf <daniel@ekloef.se>- Parent
b6b9d5a
2 files changed+31 added−8 removed
modified:CHANGELOG.md+3 added
34 unmodified lines35 ### Fixed36 37 * Crash when the border size is larger than the border radius38 ([#401][401]).39+* Regression: cursor not centered when using a custom line height40+ ([#403][403]).41 42 [401]: https://codeberg.org/dnkl/fuzzel/issues/40143+[403]: https://codeberg.org/dnkl/fuzzel/issues/40344 45 46 ### Security47 ### Contributors785 unmodified linesmodified:render.c+28 added-8 removed
243 unmodified lines244 }245 }246 247 static int248+render_baseline(const struct render *render)249+{250+ const struct fcft_font *font = render->font;251+ const int line_height = render->row_height;252+ const int font_height = font->ascent + font->descent;253+254+ /*255+ * Center glyph on the line *if* using a custom line height,256+ * otherwise the baseline is simply 'descent' pixels above the257+ * bottom of the cell258+ */259+ const int glyph_top_y = render->conf->line_height.px >= 0260+ ? round((line_height - font_height) / 2.)261+ : 0;262+263+ return line_height - glyph_top_y - font->descent;264+}265+266+static int267 render_match_count(const struct render *render, struct buffer *buf,268 const struct prompt *prompt, const struct matches *matches)269 {270 struct fcft_font *font = render->font;97 unmodified lines368 return width;369 }370 371 static void353-render_cursor(const struct render *render, int x, int y, pixman_image_t *pix)372+render_cursor(const struct render *render, int x, int baseline, pixman_image_t *pix)373 {374 struct fcft_font *font = render->font;375 376 if (true) {377 /* Bar cursor */378+ const int height = min(font->ascent + font->descent, render->row_height);379+380 pixman_image_fill_rectangles(381 PIXMAN_OP_SRC, pix, &render->pix_input_color,382 1, &(pixman_rectangle16_t){383 x,363- render->border_size + render->y_margin,384+ baseline - render->font->ascent,385 font->underline.thickness,365- min(font->ascent + font->descent, render->row_height)});386+ height});387 } else {388 /* TODO: future: underline cursor */389 pixman_image_fill_rectangles(390 PIXMAN_OP_SRC, pix, &render->pix_input_color,391 1, &(pixman_rectangle16_t){371- x, y - font->underline.position,392+ x, baseline - font->underline.position,393 font->max_advance.x,394 font->underline.thickness});395 }396 }25 unmodified lines422 render->conf->colors.selection.a == 1.)423 ? render->subpixel : FCFT_SUBPIXEL_NONE;424 425 int x = render->border_size + render->x_margin;405- int y = render->border_size + render->y_margin +406- (render->row_height + font->height) / 2 - font->descent;426+ int y = render->border_size + render->y_margin + render_baseline(render);427 428 /* Erase background */429 pixman_color_t bg = render->pix_background_color;430 pixman_image_fill_rectangles(607 unmodified lines1038 match->application->render_title = match->application->title;1039 }1040 }1041 1022- const int y = first_row + (render->row_height + render->font->height) / 2 - render->font->descent + idx * render->row_height;1042+ const int y = first_row + render_baseline(render) + idx * render->row_height;1043 1044 /* Application title */1045 render_match_text(1046 pix, &cur_x, y, max_x - (ellipses != NULL ? ellipses->width : 0),270 unmodified lines1317 const unsigned border_size = render->conf->border.size * scale;1318 1319 const unsigned row_height = render->conf->line_height.px >= 01320 ? pt_or_px_as_pixels(render, &render->conf->line_height)1301- : font->height;1321+ : max(font->height, font->ascent + font->descent);1322 1323 const unsigned icon_height = max(0, row_height - font->descent);1324 1325 const unsigned height =113 unmodified lines