[gtk/wip/matthiasc/listview-2: 95/168] listview: Add gtk_list_view_get_position_at_y()
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/matthiasc/listview-2: 95/168] listview: Add gtk_list_view_get_position_at_y()
- Date: Fri, 29 May 2020 20:38:21 +0000 (UTC)
commit 50a50e44db7ecd97dbd12913d2679a1afaa7a4fe
Author: Benjamin Otte <otte redhat com>
Date: Wed Oct 16 21:31:00 2019 +0200
listview: Add gtk_list_view_get_position_at_y()
gtk/gtklistview.c | 42 +++++++++++++++++++++++++++++++++---------
1 file changed, 33 insertions(+), 9 deletions(-)
---
diff --git a/gtk/gtklistview.c b/gtk/gtklistview.c
index 90ae09854a..2b8c41de2f 100644
--- a/gtk/gtklistview.c
+++ b/gtk/gtklistview.c
@@ -203,6 +203,37 @@ gtk_list_view_get_row_at_y (GtkListView *self,
return row;
}
+static int
+gtk_list_view_get_position_at_y (GtkListView *self,
+ int y,
+ int *offset,
+ int *height)
+{
+ ListRow *row;
+ guint pos;
+ int remaining;
+
+ row = gtk_list_view_get_row_at_y (self, y, &remaining);
+ if (row == NULL)
+ {
+ pos = GTK_INVALID_LIST_POSITION;
+ if (offset)
+ *offset = 0;
+ if (height)
+ *height = 0;
+ return GTK_INVALID_LIST_POSITION;
+ }
+ pos = gtk_list_item_manager_get_item_position (self->item_manager, row);
+ g_assert (remaining < row->height * row->parent.n_items);
+ pos += remaining / row->height;
+ if (offset)
+ *offset = remaining % row->height;
+ if (height)
+ *height = row->height;
+
+ return pos;
+}
+
static int
list_row_get_y (GtkListView *self,
ListRow *row)
@@ -278,18 +309,11 @@ gtk_list_view_adjustment_value_changed_cb (GtkAdjustment *adjustment,
{
if (adjustment == self->adjustment[self->orientation])
{
- ListRow *row;
guint pos;
int dy;
- row = gtk_list_view_get_row_at_y (self, gtk_adjustment_get_value (adjustment), &dy);
- if (row)
- {
- pos = gtk_list_item_manager_get_item_position (self->item_manager, row) + dy / row->height;
- }
- else
- pos = 0;
-
+ pos = gtk_list_view_get_position_at_y (self, gtk_adjustment_get_value (adjustment), &dy, NULL);
+ g_return_if_fail (pos != GTK_INVALID_LIST_POSITION);
gtk_list_view_set_anchor (self, pos, 0);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]