Compare commits
	
		
			No commits in common. "dad95ef444cd8599707d20ed436aaf8e38fab25a" and "8529f24a464013f31253d8c3aa0886cbd47cf86b" have entirely different histories.
		
	
	
		
			dad95ef444
			...
			8529f24a46
		
	
		
							
								
								
									
										38
									
								
								nncmpp.c
									
									
									
									
									
								
							
							
						
						
									
										38
									
								
								nncmpp.c
									
									
									
									
									
								
							| @ -2014,7 +2014,7 @@ app_layout_header (void) | ||||
| } | ||||
| 
 | ||||
| static int | ||||
| app_visible_items_height (void) | ||||
| app_visible_items (void) | ||||
| { | ||||
| 	struct widget *list = NULL; | ||||
| 	LIST_FOR_EACH (struct widget, w, g.widgets.head) | ||||
| @ -2024,13 +2024,7 @@ app_visible_items_height (void) | ||||
| 	hard_assert (list != NULL); | ||||
| 
 | ||||
| 	// The raw number of items that would have fit on the terminal
 | ||||
| 	return MAX (0, list->height); | ||||
| } | ||||
| 
 | ||||
| static int | ||||
| app_visible_items (void) | ||||
| { | ||||
| 	return app_visible_items_height () / g.ui_vunit; | ||||
| 	return MAX (0, list->height / g.ui_vunit); | ||||
| } | ||||
| 
 | ||||
| /// Figure out scrollbar appearance.  @a s is the minimal slider length as well
 | ||||
| @ -2038,7 +2032,7 @@ app_visible_items (void) | ||||
| struct scrollbar { long length, start; } | ||||
| app_compute_scrollbar (struct tab *tab, long visible, long s) | ||||
| { | ||||
| 	long top = s * tab->item_top, total = s * tab->item_count; | ||||
| 	long top = tab->item_top, total = tab->item_count; | ||||
| 	if (total < visible) | ||||
| 		return (struct scrollbar) { 0, 0 }; | ||||
| 	if (visible == 1) | ||||
| @ -2048,7 +2042,7 @@ app_compute_scrollbar (struct tab *tab, long visible, long s) | ||||
| 
 | ||||
| 	// Only be at the top or bottom when the top or bottom item can be seen.
 | ||||
| 	// The algorithm isn't optimal but it's a bitch to get right.
 | ||||
| 	double available_length = visible - 2 - s + 1; | ||||
| 	double available_length = s * visible - 2 - s + 1; | ||||
| 
 | ||||
| 	double lenf = s + available_length * visible / total, length = 0.; | ||||
| 	long offset = 1 + available_length * top / total + modf (lenf, &length); | ||||
| @ -2056,7 +2050,7 @@ app_compute_scrollbar (struct tab *tab, long visible, long s) | ||||
| 	if (top == 0) | ||||
| 		return (struct scrollbar) { length, 0 }; | ||||
| 	if (top + visible >= total) | ||||
| 		return (struct scrollbar) { length, visible - length }; | ||||
| 		return (struct scrollbar) { length, s * visible - length }; | ||||
| 
 | ||||
| 	return (struct scrollbar) { length, offset }; | ||||
| } | ||||
| @ -2105,7 +2099,7 @@ app_sublayout_list (struct widget *list) | ||||
| { | ||||
| 	struct tab *tab = g.active_tab; | ||||
| 	int to_show = MIN ((int) tab->item_count - tab->item_top, | ||||
| 		ceil ((double) list->height / g.ui_vunit)); | ||||
| 		list->height / g.ui_vunit); | ||||
| 
 | ||||
| 	struct layout l = {}; | ||||
| 	for (int row = 0; row < to_show; row++) | ||||
| @ -2845,8 +2839,9 @@ app_process_left_mouse_click (struct widget *w, int x, int y, int modifiers) | ||||
| 		else if (tab->item_mark < 0) | ||||
| 			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; | ||||
| 		app_ensure_selection_visible (); | ||||
| 		app_invalidate (); | ||||
| 
 | ||||
| 		if (modifiers & APP_KEYMOD_DOUBLE_CLICK) | ||||
| @ -2857,7 +2852,7 @@ app_process_left_mouse_click (struct widget *w, int x, int y, int modifiers) | ||||
| 	{ | ||||
| 		struct tab *tab = g.active_tab; | ||||
| 		int visible_items = app_visible_items (); | ||||
| 		tab->item_top = (double) y / w->height | ||||
| 		tab->item_top = (float) y / w->height | ||||
| 			* (int) tab->item_count - visible_items / 2; | ||||
| 		app_invalidate (); | ||||
| 		break; | ||||
| @ -5176,7 +5171,7 @@ tui_render_scrollbar (struct widget *self) | ||||
| 		return; | ||||
| 	} | ||||
| 
 | ||||
| 	struct scrollbar bar = app_compute_scrollbar (tab, visible_items * 8, 8); | ||||
| 	struct scrollbar bar = app_compute_scrollbar (tab, visible_items, 8); | ||||
| 	bar.length += bar.start; | ||||
| 
 | ||||
| 	int start_part = bar.start  % 8; bar.start  /= 8; | ||||
| @ -5796,8 +5791,10 @@ x11_render_scrollbar (struct widget *self) | ||||
| 	x11_render_padding (self); | ||||
| 
 | ||||
| 	struct tab *tab = g.active_tab; | ||||
| 	// FIXME: This isn't an integer number in this case.
 | ||||
| 	int visible_items = app_visible_items (); | ||||
| 	struct scrollbar bar = | ||||
| 		app_compute_scrollbar (tab, app_visible_items_height (), g.ui_vunit); | ||||
| 		app_compute_scrollbar (tab, visible_items, g.ui_vunit); | ||||
| 
 | ||||
| 	XRenderFillRectangle (g.dpy, PictOpSrc, g.x11_pixmap_picture, | ||||
| 		x11_fg_attrs (self->attrs), | ||||
| @ -5817,22 +5814,17 @@ x11_make_scrollbar (chtype attrs) | ||||
| 	return w; | ||||
| } | ||||
| 
 | ||||
| // TODO: Handle partial items, otherwise this is the same as tui_render_list().
 | ||||
| static void | ||||
| x11_render_list (struct widget *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)) | ||||
| 	{ | ||||
| 		w->on_render (w); | ||||
| 		free (w); | ||||
| 	} | ||||
| 
 | ||||
| 	XRenderChangePicture (g.dpy, g.x11_pixmap_picture, CPClipMask, | ||||
| 		&(XRenderPictureAttributes) { .clip_mask = None }); | ||||
| } | ||||
| 
 | ||||
| static struct widget * | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user