mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-10 04:27:45 -05:00
search: move render() function to the 'render' module
This commit is contained in:
parent
af8682210e
commit
2c3ab701e7
3 changed files with 59 additions and 80 deletions
54
render.c
54
render.c
|
|
@ -691,6 +691,60 @@ frame_callback(void *data, struct wl_callback *wl_callback, uint32_t callback_da
|
|||
grid_render(term);
|
||||
}
|
||||
|
||||
void
|
||||
render_search_box(struct terminal *term)
|
||||
{
|
||||
assert(term->wl.search_sub_surface != NULL);
|
||||
|
||||
/* TODO: at least sway allows the subsurface to extend outside the
|
||||
* main window. Do we want that? */
|
||||
const int scale = term->scale >= 1 ? term->scale : 1;
|
||||
const int margin = scale * 3;
|
||||
const int width = 2 * margin + max(20, term->search.len) * term->cell_width;
|
||||
const int height = 2 * margin + 1 * term->cell_height;
|
||||
|
||||
struct buffer *buf = shm_get_buffer(term->wl.shm, width, height, 1);
|
||||
|
||||
/* Background - yellow on empty/match, red on mismatch */
|
||||
pixman_color_t color = color_hex_to_pixman(
|
||||
term->search.match_len == term->search.len ? 0xffff00 : 0xff0000);
|
||||
|
||||
pixman_image_fill_rectangles(
|
||||
PIXMAN_OP_SRC, buf->pix, &color,
|
||||
1, &(pixman_rectangle16_t){0, 0, width, height});
|
||||
|
||||
int x = margin;
|
||||
int y = margin;
|
||||
pixman_color_t fg = color_hex_to_pixman(0x000000);
|
||||
|
||||
/* Text (what the user entered - *not* match(es)) */
|
||||
for (size_t i = 0; i < term->search.len; i++) {
|
||||
const struct glyph *glyph = font_glyph_for_wc(&term->fonts[0], term->search.buf[i]);
|
||||
if (glyph == NULL)
|
||||
continue;
|
||||
|
||||
pixman_image_t *src = pixman_image_create_solid_fill(&fg);
|
||||
pixman_image_composite32(
|
||||
PIXMAN_OP_OVER, src, glyph->pix, buf->pix, 0, 0, 0, 0,
|
||||
x + glyph->x, y + term->fextents.ascent - glyph->y,
|
||||
glyph->width, glyph->height);
|
||||
pixman_image_unref(src);
|
||||
|
||||
x += glyph->width;
|
||||
}
|
||||
|
||||
LOG_INFO("match length: %zu", term->search.match_len);
|
||||
|
||||
wl_subsurface_set_position(
|
||||
term->wl.search_sub_surface,
|
||||
term->width - width - margin, term->height - height - margin);
|
||||
|
||||
wl_surface_damage_buffer(term->wl.search_surface, 0, 0, width, height);
|
||||
wl_surface_attach(term->wl.search_surface, buf->wl_buf, 0, 0);
|
||||
wl_surface_set_buffer_scale(term->wl.search_surface, scale);
|
||||
wl_surface_commit(term->wl.search_surface);
|
||||
}
|
||||
|
||||
static void
|
||||
reflow(struct row **new_grid, int new_cols, int new_rows,
|
||||
struct row *const *old_grid, int old_cols, int old_rows)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue