X11: render partially visible list items

This commit is contained in:
Přemysl Eric Janouch 2022-09-03 13:23:07 +02:00
parent 7e74d1a80a
commit dad95ef444
Signed by: p
GPG Key ID: A0420B94F92B9493
1 changed files with 10 additions and 6 deletions

View File

@ -2105,7 +2105,7 @@ app_sublayout_list (struct widget *list)
{ {
struct tab *tab = g.active_tab; struct tab *tab = g.active_tab;
int to_show = MIN ((int) tab->item_count - tab->item_top, int to_show = MIN ((int) tab->item_count - tab->item_top,
list->height / g.ui_vunit); ceil ((double) list->height / g.ui_vunit));
struct layout l = {}; struct layout l = {};
for (int row = 0; row < to_show; row++) for (int row = 0; row < to_show; row++)
@ -2845,9 +2845,8 @@ app_process_left_mouse_click (struct widget *w, int x, int y, int modifiers)
else if (tab->item_mark < 0) else if (tab->item_mark < 0)
tab->item_mark = tab->item_selected; tab->item_mark = tab->item_selected;
// TODO: Probably will need to fix up item->top
// for partially visible items in X11.
tab->item_selected = row_index + tab->item_top; tab->item_selected = row_index + tab->item_top;
app_ensure_selection_visible ();
app_invalidate (); app_invalidate ();
if (modifiers & APP_KEYMOD_DOUBLE_CLICK) if (modifiers & APP_KEYMOD_DOUBLE_CLICK)
@ -2858,7 +2857,7 @@ app_process_left_mouse_click (struct widget *w, int x, int y, int modifiers)
{ {
struct tab *tab = g.active_tab; struct tab *tab = g.active_tab;
int visible_items = app_visible_items (); int visible_items = app_visible_items ();
tab->item_top = (float) y / w->height tab->item_top = (double) y / w->height
* (int) tab->item_count - visible_items / 2; * (int) tab->item_count - visible_items / 2;
app_invalidate (); app_invalidate ();
break; break;
@ -5818,17 +5817,22 @@ x11_make_scrollbar (chtype attrs)
return w; return w;
} }
// TODO: Handle partial items, otherwise this is the same as tui_render_list().
static void static void
x11_render_list (struct widget *self) x11_render_list (struct widget *self)
{ {
x11_render_padding (self); // We could do that for all widgets, but it would be kind-of pointless.
XRenderSetPictureClipRectangles (g.dpy, g.x11_pixmap_picture, 0, 0,
&(XRectangle) { self->x, self->y, self->width, self->height }, 1);
x11_render_padding (self);
LIST_FOR_EACH (struct widget, w, self->on_sublayout (self)) LIST_FOR_EACH (struct widget, w, self->on_sublayout (self))
{ {
w->on_render (w); w->on_render (w);
free (w); free (w);
} }
XRenderChangePicture (g.dpy, g.x11_pixmap_picture, CPClipMask,
&(XRenderPictureAttributes) { .clip_mask = None });
} }
static struct widget * static struct widget *