Skip to content
Myr

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

2 files+31 added−8 removed

modified:CHANGELOG.md+3 added
34 unmodified lines
35### Fixed3637* 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]).4142[401]: https://codeberg.org/dnkl/fuzzel/issues/40143[403]: https://codeberg.org/dnkl/fuzzel/issues/403444546### Security47### Contributors
785 unmodified lines
modified:render.c+28 added-8 removed
243 unmodified lines
244 }245}246247static int248render_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;253254 /*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;262263 return line_height - glyph_top_y - font->descent;264}265266static int267render_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 lines
368 return width;369}370371static void353render_cursor(const struct render *render, int x, int y, pixman_image_t *pix)372render_cursor(const struct render *render, int x, int baseline, pixman_image_t *pix)373{374 struct fcft_font *font = render->font;375376 if (true) {377 /* Bar cursor */378 const int height = min(font->ascent + font->descent, render->row_height);379380 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 lines
422 render->conf->colors.selection.a == 1.)423 ? render->subpixel : FCFT_SUBPIXEL_NONE;424425 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);427428 /* Erase background */429 pixman_color_t bg = render->pix_background_color;430 pixman_image_fill_rectangles(
607 unmodified lines
1038 match->application->render_title = match->application->title;1039 }1040 }10411022 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;10431044 /* Application title */1045 render_match_text(1046 pix, &cur_x, y, max_x - (ellipses != NULL ? ellipses->width : 0),
270 unmodified lines
1317 const unsigned border_size = render->conf->border.size * scale;13181319 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);13221323 const unsigned icon_height = max(0, row_height - font->descent);13241325 const unsigned height =
113 unmodified lines