[gtk/wip/otte/listview: 8/23] listitemmanager: Allow properties assigned to trackers
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/listview: 8/23] listitemmanager: Allow properties assigned to trackers
- Date: Sat, 26 Feb 2022 03:03:22 +0000 (UTC)
commit 4a50cb914b3c31147eaf00730a1c5e00b666669e
Author: Benjamin Otte <otte redhat com>
Date: Sun Feb 13 16:39:18 2022 +0100
listitemmanager: Allow properties assigned to trackers
In theory, we could also use callback(s) here, but if the callbacks just
notify, it's easier to do it this way.
gtk/gtklistbase.c | 10 +++++-----
gtk/gtklistitemmanager.c | 20 +++++++++++++++++++-
gtk/gtklistitemmanagerprivate.h | 4 +++-
3 files changed, 27 insertions(+), 7 deletions(-)
---
diff --git a/gtk/gtklistbase.c b/gtk/gtklistbase.c
index 2548e61b31..f29ffec23a 100644
--- a/gtk/gtklistbase.c
+++ b/gtk/gtklistbase.c
@@ -1527,7 +1527,7 @@ gtk_list_base_start_rubberband (GtkListBase *self,
priv->rubberband = g_new0 (RubberbandData, 1);
- priv->rubberband->start_tracker = gtk_list_item_tracker_new (priv->item_manager);
+ priv->rubberband->start_tracker = gtk_list_item_tracker_new (priv->item_manager, NULL, NULL);
gtk_list_item_tracker_set_position (priv->item_manager, priv->rubberband->start_tracker, pos, 0, 0);
priv->rubberband->start_align_across = item_area.width ? (double) (list_x - item_area.x) / item_area.width
: 0.5;
priv->rubberband->start_align_along = item_area.height ? (double) (list_y - item_area.y) /
item_area.height : 0.5;
@@ -1801,11 +1801,11 @@ gtk_list_base_init_real (GtkListBase *self,
g_class->list_item_size,
g_class->list_item_augment_size,
g_class->list_item_augment_func);
- priv->anchor = gtk_list_item_tracker_new (priv->item_manager);
+ priv->anchor = gtk_list_item_tracker_new (priv->item_manager, NULL, NULL);
priv->anchor_side_along = GTK_PACK_START;
priv->anchor_side_across = GTK_PACK_START;
- priv->selected = gtk_list_item_tracker_new (priv->item_manager);
- priv->focus = gtk_list_item_tracker_new (priv->item_manager);
+ priv->selected = gtk_list_item_tracker_new (priv->item_manager, NULL, NULL);
+ priv->focus = gtk_list_item_tracker_new (priv->item_manager, NULL, NULL);
priv->adjustment[GTK_ORIENTATION_HORIZONTAL] = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
g_object_ref_sink (priv->adjustment[GTK_ORIENTATION_HORIZONTAL]);
@@ -2077,7 +2077,7 @@ gtk_list_base_grab_focus_on_item (GtkListBase *self,
if (!item->widget)
{
- GtkListItemTracker *tracker = gtk_list_item_tracker_new (priv->item_manager);
+ GtkListItemTracker *tracker = gtk_list_item_tracker_new (priv->item_manager, NULL, NULL);
/* We need a tracker here to create the widget.
* That needs to have happened or we can't grab it.
diff --git a/gtk/gtklistitemmanager.c b/gtk/gtklistitemmanager.c
index 896d714182..b623dbd9f9 100644
--- a/gtk/gtklistitemmanager.c
+++ b/gtk/gtklistitemmanager.c
@@ -48,6 +48,9 @@ struct _GtkListItemManagerClass
struct _GtkListItemTracker
{
+ GParamSpec *position_property;
+ GParamSpec *item_property;
+
guint position;
GtkListItemWidget *widget;
guint n_before;
@@ -264,6 +267,9 @@ gtk_list_item_tracker_update_widget (GtkListItemManager *self,
return;
tracker->widget = widget;
+
+ if (tracker->item_property)
+ g_object_notify_by_pspec (G_OBJECT (self->widget), tracker->item_property);
}
static void
@@ -275,6 +281,9 @@ gtk_list_item_tracker_update_position (GtkListItemManager *self,
return;
tracker->position = position;
+
+ if (tracker->position_property)
+ g_object_notify_by_pspec (G_OBJECT (self->widget), tracker->position_property);
}
static void
@@ -286,6 +295,11 @@ gtk_list_item_tracker_unset_position (GtkListItemManager *self,
tracker->widget = NULL;
tracker->position = GTK_INVALID_LIST_POSITION;
+
+ if (tracker->position_property)
+ g_object_notify_by_pspec (G_OBJECT (self->widget), tracker->position_property);
+ if (tracker->item_property)
+ g_object_notify_by_pspec (G_OBJECT (self->widget), tracker->item_property);
}
static gboolean
@@ -1172,7 +1186,9 @@ gtk_list_item_manager_get_single_click_activate (GtkListItemManager *self)
}
GtkListItemTracker *
-gtk_list_item_tracker_new (GtkListItemManager *self)
+gtk_list_item_tracker_new (GtkListItemManager *self,
+ GParamSpec *position_property,
+ GParamSpec *item_property)
{
GtkListItemTracker *tracker;
@@ -1181,6 +1197,8 @@ gtk_list_item_tracker_new (GtkListItemManager *self)
tracker = g_slice_new0 (GtkListItemTracker);
tracker->position = GTK_INVALID_LIST_POSITION;
+ tracker->position_property = position_property;
+ tracker->item_property = item_property;
self->trackers = g_slist_prepend (self->trackers, tracker);
diff --git a/gtk/gtklistitemmanagerprivate.h b/gtk/gtklistitemmanagerprivate.h
index 096c1adbb2..cb4655e3fc 100644
--- a/gtk/gtklistitemmanagerprivate.h
+++ b/gtk/gtklistitemmanagerprivate.h
@@ -101,7 +101,9 @@ void gtk_list_item_manager_set_single_click_activate
gboolean gtk_list_item_manager_get_single_click_activate
(GtkListItemManager *self);
-GtkListItemTracker * gtk_list_item_tracker_new (GtkListItemManager *self);
+GtkListItemTracker * gtk_list_item_tracker_new (GtkListItemManager *self,
+ GParamSpec *position_property,
+ GParamSpec *item_property);
void gtk_list_item_tracker_free (GtkListItemManager *self,
GtkListItemTracker *tracker);
void gtk_list_item_tracker_set_position (GtkListItemManager *self,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]