[gtk/wip/otte/listview] listitemmanager: Switch from "insert_before" to "insert_after" argumnet
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/listview] listitemmanager: Switch from "insert_before" to "insert_after" argumnet
- Date: Fri, 28 Sep 2018 02:19:27 +0000 (UTC)
commit 57dca2aec8007e0ea78a72505c1754cc863e3f55
Author: Benjamin Otte <otte redhat com>
Date: Fri Sep 28 02:05:46 2018 +0200
listitemmanager: Switch from "insert_before" to "insert_after" argumnet
We reorder widgets start to end, so when reusing a list item, we
correctly know the previous sibling for that list item, but not the
next sibling yet. We just know the widget it should ultimately be in
front of.
So we can do a more correct guess of the list item's place in the widget
tree if we think about where to place an item like this.
Actually using this change will come in the next commit.
gtk/gtklistitemmanager.c | 20 ++++++++++----------
gtk/gtklistitemmanagerprivate.h | 4 ++--
gtk/gtklistview.c | 24 +++++++++++++-----------
3 files changed, 25 insertions(+), 23 deletions(-)
---
diff --git a/gtk/gtklistitemmanager.c b/gtk/gtklistitemmanager.c
index df0022661f..63ed592ccd 100644
--- a/gtk/gtklistitemmanager.c
+++ b/gtk/gtklistitemmanager.c
@@ -238,8 +238,8 @@ gtk_list_item_manager_change_contains (GtkListItemManagerChange *change,
* gtk_list_item_manager_acquire_list_item:
* @self: a #GtkListItemManager
* @position: the row in the model to create a list item for
- * @next_sibling: the widget this widget should be inserted before or %NULL
- * if none
+ * @prev_sibling: the widget this widget should be inserted before or %NULL
+ * if it should be the first widget
*
* Creates a list item widget to use for @position. No widget may
* yet exist that is used for @position.
@@ -255,20 +255,20 @@ gtk_list_item_manager_change_contains (GtkListItemManagerChange *change,
GtkWidget *
gtk_list_item_manager_acquire_list_item (GtkListItemManager *self,
guint position,
- GtkWidget *next_sibling)
+ GtkWidget *prev_sibling)
{
GtkListItem *result;
gpointer item;
g_return_val_if_fail (GTK_IS_LIST_ITEM_MANAGER (self), NULL);
- g_return_val_if_fail (next_sibling == NULL || GTK_IS_WIDGET (next_sibling), NULL);
+ g_return_val_if_fail (prev_sibling == NULL || GTK_IS_WIDGET (prev_sibling), NULL);
result = gtk_list_item_factory_create (self->factory);
item = g_list_model_get_item (self->model, position);
gtk_list_item_factory_bind (self->factory, result, position, item);
g_object_unref (item);
- gtk_widget_insert_before (GTK_WIDGET (result), self->widget, next_sibling);
+ gtk_widget_insert_after (GTK_WIDGET (result), self->widget, prev_sibling);
return GTK_WIDGET (result);
}
@@ -277,8 +277,8 @@ gtk_list_item_manager_acquire_list_item (GtkListItemManager *self,
* gtk_list_item_manager_try_acquire_list_item_from_change:
* @self: a #GtkListItemManager
* @position: the row in the model to create a list item for
- * @next_sibling: the widget this widget should be inserted before or %NULL
- * if none
+ * @prev_sibling: the widget this widget should be inserted after or %NULL
+ * if it should be the first widget
*
* Like gtk_list_item_manager_acquire_list_item(), but only tries to acquire list
* items from those previously released as part of @change.
@@ -292,20 +292,20 @@ GtkWidget *
gtk_list_item_manager_try_reacquire_list_item (GtkListItemManager *self,
GtkListItemManagerChange *change,
guint position,
- GtkWidget *next_sibling)
+ GtkWidget *prev_sibling)
{
GtkListItem *result;
gpointer item;
g_return_val_if_fail (GTK_IS_LIST_ITEM_MANAGER (self), NULL);
- g_return_val_if_fail (next_sibling == NULL || GTK_IS_WIDGET (next_sibling), NULL);
+ g_return_val_if_fail (prev_sibling == NULL || GTK_IS_WIDGET (prev_sibling), NULL);
/* XXX: can we avoid temporarily allocating items on failure? */
item = g_list_model_get_item (self->model, position);
if (g_hash_table_steal_extended (change->items, item, NULL, (gpointer *) &result))
{
gtk_list_item_factory_update (self->factory, result, position);
- gtk_widget_insert_before (GTK_WIDGET (result), self->widget, next_sibling);
+ gtk_widget_insert_after (GTK_WIDGET (result), self->widget, prev_sibling);
/* XXX: Should we let the listview do this? */
gtk_widget_queue_resize (GTK_WIDGET (result));
}
diff --git a/gtk/gtklistitemmanagerprivate.h b/gtk/gtklistitemmanagerprivate.h
index cf7721bc6c..0f1d1bddd1 100644
--- a/gtk/gtklistitemmanagerprivate.h
+++ b/gtk/gtklistitemmanagerprivate.h
@@ -60,12 +60,12 @@ gboolean gtk_list_item_manager_change_contains (GtkListItemMana
GtkWidget * gtk_list_item_manager_acquire_list_item (GtkListItemManager *self,
guint position,
- GtkWidget *next_sibling);
+ GtkWidget *prev_sibling);
GtkWidget * gtk_list_item_manager_try_reacquire_list_item
(GtkListItemManager *self,
GtkListItemManagerChange *change,
guint position,
- GtkWidget *next_sibling);
+ GtkWidget *prev_sibling);
void gtk_list_item_manager_update_list_item (GtkListItemManager *self,
GtkWidget *item,
guint position);
diff --git a/gtk/gtklistview.c b/gtk/gtklistview.c
index f625dad8db..ea95e4e8b0 100644
--- a/gtk/gtklistview.c
+++ b/gtk/gtklistview.c
@@ -395,7 +395,7 @@ gtk_list_view_ensure_rows (GtkListView *self,
{
ListRow *row, *new_row;
guint i, offset;
- GtkWidget *insert_before;
+ GtkWidget *insert_after;
gtk_list_view_release_rows (self);
@@ -408,7 +408,7 @@ gtk_list_view_ensure_rows (GtkListView *self,
gtk_css_rb_tree_mark_dirty (self->rows, row);
}
- insert_before = gtk_widget_get_first_child (GTK_WIDGET (self));
+ insert_after = NULL;
for (i = self->anchor_start; i < self->anchor_end; i++)
{
@@ -431,21 +431,21 @@ gtk_list_view_ensure_rows (GtkListView *self,
new_row->widget = gtk_list_item_manager_try_reacquire_list_item (self->item_manager,
change,
i,
- insert_before);
+ insert_after);
}
if (new_row->widget == NULL)
{
new_row->widget = gtk_list_item_manager_acquire_list_item (self->item_manager,
i,
- insert_before);
+ insert_after);
}
}
else
{
if (update_start <= i)
gtk_list_item_manager_update_list_item (self->item_manager, new_row->widget, i);
- insert_before = gtk_widget_get_next_sibling (new_row->widget);
}
+ insert_after = new_row->widget;
}
}
@@ -912,18 +912,18 @@ gtk_list_view_model_items_changed_cb (GListModel *model,
/* The anchor was removed, do a more expensive rebuild trying to find if
* the anchor maybe got readded somewhere else */
ListRow *row, *new_row;
- GtkWidget *insert_before;
+ GtkWidget *insert_after;
guint i, offset, anchor_pos;
row = gtk_list_view_get_row (self, position, &offset);
- for (new_row = row;
+ for (new_row = gtk_css_rb_tree_get_previous (self->rows, row);
new_row && new_row->widget == NULL;
- new_row = gtk_css_rb_tree_get_next (self->rows, new_row))
+ new_row = gtk_css_rb_tree_get_previous (self->rows, new_row))
;
if (new_row)
- insert_before = new_row->widget;
+ insert_after = new_row->widget;
else
- insert_before = NULL; /* we're at the end */
+ insert_after = NULL; /* we're at the start */
for (i = 0; i < added; i++)
{
@@ -932,7 +932,7 @@ gtk_list_view_model_items_changed_cb (GListModel *model,
widget = gtk_list_item_manager_try_reacquire_list_item (self->item_manager,
change,
position + i,
- insert_before);
+ insert_after);
if (widget == NULL)
{
offset++;
@@ -962,6 +962,8 @@ gtk_list_view_model_items_changed_cb (GListModel *model,
}
new_row->widget = widget;
+ insert_after = widget;
+
if (widget == self->anchor)
{
anchor_pos = position + i;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]