[gtk/wip/otte/listview: 61/79] listview: Add gtk_list_view_get_position_at_y()
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/listview: 61/79] listview: Add gtk_list_view_get_position_at_y()
- Date: Tue, 22 Oct 2019 02:44:18 +0000 (UTC)
commit ef14fe2e61941016c12b9b67a5fa222bc80c47a5
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 7918eee88d..0a1236ae49 100644
--- a/gtk/gtklistview.c
+++ b/gtk/gtklistview.c
@@ -204,6 +204,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)
@@ -279,18 +310,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]