~sircmpwn/visurf

2f549e4d2685013a927403c7500af01bb88553db — Drew DeVault a month ago d3f92ab
nsvi: initial UI for rendering completions
2 files changed, 56 insertions(+), 0 deletions(-)

M frontends/visurf/window.c
M frontends/visurf/window.h
M frontends/visurf/window.c => frontends/visurf/window.c +47 -0
@@ 216,6 216,44 @@ draw_insert_statusbar(struct nsvi_window *win, struct pool_buffer *buf)
}

static int
draw_exline_completions(struct nsvi_window *win, struct pool_buffer *buf, int bottom)
{
	struct exline_state *exline = &win->exline;

	int height = 0;
	size_t nitems = 0;
	for (size_t i = 0; i < exline->ncomp; ++i, ++nitems) {
		int itemwidth, itemheight;
		get_text_size(buf->cairo, config.font,
				&itemwidth, &itemheight,
				NULL, "%s", exline->comps[i]);
		if (height + itemheight + (int)config.margin > win->height / 2) {
			break;
		}
		height += itemheight + config.margin;
	}

	cairo_set_source_u32(buf->cairo, config.status.exline.bg);
	cairo_rectangle(buf->cairo, 0, bottom - (config.margin * 2 + height),
			win->width, config.margin * 2 + height);
	cairo_fill(buf->cairo);

	int y = bottom;
	cairo_set_source_u32(buf->cairo, config.status.exline.fg);
	for (size_t i = 0; i < nitems; i += 1) {
		int itemwidth, itemheight;
		get_text_size(buf->cairo, config.font,
				&itemwidth, &itemheight,
				NULL, "%s", exline->comps[i]);
		y -= itemheight + config.margin;
		cairo_move_to(buf->cairo, config.margin, y);
		pango_printf(buf->cairo, config.font, "%s", exline->comps[i]);
	}

	return height;
}

static int
draw_exline_statusbar(struct nsvi_window *win, struct pool_buffer *buf)
{
	struct exline_state *exline = &win->exline;


@@ 251,6 289,8 @@ draw_exline_statusbar(struct nsvi_window *win, struct pool_buffer *buf)
			win->height - height - config.margin);
	pango_printf(buf->cairo, config.font, "%s", &exline->cmd[exline->index]);

	int top = win->height - (config.margin + height);
	height += draw_exline_completions(win, buf, top);
	return height + config.margin * 2;
}



@@ 687,6 727,13 @@ nsvi_window_create(void)
	win->scale = 1;
	win->mouse.shape = GUI_POINTER_DEFAULT;

	// TEMP
	win->exline.ncomp = 3;
	win->exline.comps = calloc(3, sizeof(char *));
	win->exline.comps[0] = strdup("completion 1");
	win->exline.comps[1] = strdup("completion 2");
	win->exline.comps[2] = strdup("completion 3");

	win->wl_surface = wl_compositor_create_surface(
		global_state->wl_compositor);
	wl_surface_add_listener(win->wl_surface,

M frontends/visurf/window.h => frontends/visurf/window.h +9 -0
@@ 24,6 24,15 @@ struct exline_state {
	char *cmd;
	size_t cmdln, cmdsz;
	size_t index;

	// Completions are the list of items above the prompt, ordered from most
	// to least relevant candidate and rendered in this order from bottom to
	// top above the exline prompt. The contents of this array depends on
	// the text already entered in the prompt; for example, an incomplete
	// "open" command might show a list of URLs from the history.
	char **comps;
	size_t ncomp, zcomp;
	size_t compix;
};

enum touch_operation {