commit aaa7ab7d3e7388bab55dadb1407f6a80b598b6ea
parent 2193529a58210cc79a07051e721f624c086d4121
Author: Andrej Kacian <ticho@claws-mail.org>
Date: Sat, 5 Nov 2016 12:18:53 +0100
Minimize scrolling in gtkut_ctree_node_move_if_on_the_edge().
Instead of scrolling to get the target row to the middle of
the viewport (offset 0.5), scroll to offsets 0.2 or 0.8 if
the target row is above or below current viewport,
respectively. This makes it consistent with scrolling when
the target row is only partially visible.
Diffstat:
3 files changed, 49 insertions(+), 1 deletion(-)
diff --git a/src/gtk/gtkcmclist.c b/src/gtk/gtkcmclist.c
@@ -3310,6 +3310,42 @@ gtk_cmclist_row_is_visible (GtkCMCList *clist,
return GTK_VISIBILITY_FULL;
}
+gboolean
+gtk_cmclist_row_is_above_viewport (GtkCMCList *clist,
+ gint row)
+{
+ cm_return_val_if_fail(GTK_IS_CMCLIST (clist), 0);
+
+ if (row < 0 || row >= clist->rows)
+ return FALSE;
+
+ if (clist->row_height == 0)
+ return FALSE;
+
+ if (row < ROW_FROM_YPIXEL (clist, 0))
+ return TRUE;
+
+ return FALSE;
+}
+
+gboolean
+gtk_cmclist_row_is_below_viewport (GtkCMCList *clist,
+ gint row)
+{
+ cm_return_val_if_fail(GTK_IS_CMCLIST (clist), 0);
+
+ if (row < 0 || row >= clist->rows)
+ return FALSE;
+
+ if (clist->row_height == 0)
+ return FALSE;
+
+ if (row > ROW_FROM_YPIXEL (clist, clist->clist_window_height))
+ return TRUE;
+
+ return FALSE;
+}
+
void
gtk_cmclist_set_foreground (GtkCMCList *clist,
gint row,
diff --git a/src/gtk/gtkcmclist.h b/src/gtk/gtkcmclist.h
@@ -567,6 +567,12 @@ void gtk_cmclist_moveto (GtkCMCList *clist,
GtkVisibility gtk_cmclist_row_is_visible (GtkCMCList *clist,
gint row);
+/* returns whether the row is above or below current viewport */
+gboolean gtk_cmclist_row_is_above_viewport (GtkCMCList *clist,
+ gint row);
+gboolean gtk_cmclist_row_is_below_viewport (GtkCMCList *clist,
+ gint row);
+
/* returns the cell type */
GtkCMCellType gtk_cmclist_get_cell_type (GtkCMCList *clist,
gint row,
diff --git a/src/gtk/gtkutils.c b/src/gtk/gtkutils.c
@@ -232,6 +232,7 @@ void gtkut_ctree_node_move_if_on_the_edge(GtkCMCTree *ctree, GtkCMCTreeNode *nod
GtkCMCList *clist = GTK_CMCLIST(ctree);
gint row;
GtkVisibility row_visibility, prev_row_visibility, next_row_visibility;
+ gfloat row_align;
cm_return_if_fail(ctree != NULL);
cm_return_if_fail(node != NULL);
@@ -244,7 +245,12 @@ void gtkut_ctree_node_move_if_on_the_edge(GtkCMCTree *ctree, GtkCMCTreeNode *nod
next_row_visibility = gtk_cmclist_row_is_visible(clist, row + 1);
if (row_visibility == GTK_VISIBILITY_NONE) {
- gtk_cmclist_moveto(clist, row, -1, 0.5, 0);
+ row_align = 0.5;
+ if (gtk_cmclist_row_is_above_viewport(clist, row))
+ row_align = 0.2;
+ else if (gtk_cmclist_row_is_below_viewport(clist, row))
+ row_align = 0.8;
+ gtk_cmclist_moveto(clist, row, -1, row_align, 0);
return;
}
if (row_visibility == GTK_VISIBILITY_FULL &&