summaryrefslogtreecommitdiff
path: root/gtk/gtklistitem.c
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2019-10-04 06:50:47 +0200
committerMatthias Clasen <mclasen@redhat.com>2020-05-30 19:26:45 -0400
commitf57fca7a0017b0f9d1225e57f71cb92f8072eabc (patch)
treeed554b356fbb53dc479c11eeef725731fdfc018d /gtk/gtklistitem.c
parent7c38ac19540c91d651bbe868ec56321bb9d2829a (diff)
downloadgtk+-f57fca7a0017b0f9d1225e57f71cb92f8072eabc.tar.gz
listview: Add list.scroll_to_item action
The action scrolls the given item into view. Listitems activate this action when they gain focus.
Diffstat (limited to 'gtk/gtklistitem.c')
-rw-r--r--gtk/gtklistitem.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/gtk/gtklistitem.c b/gtk/gtklistitem.c
index f5a00ac036..842f04b70d 100644
--- a/gtk/gtklistitem.c
+++ b/gtk/gtklistitem.c
@@ -23,6 +23,7 @@
#include "gtkbinlayout.h"
#include "gtkcssnodeprivate.h"
+#include "gtkeventcontrollerfocus.h"
#include "gtkgestureclick.h"
#include "gtkintl.h"
#include "gtkmain.h"
@@ -269,6 +270,18 @@ gtk_list_item_click_gesture_pressed (GtkGestureClick *gesture,
}
static void
+gtk_list_item_enter_cb (GtkEventControllerFocus *controller,
+ GtkListItem *self)
+{
+ GtkWidget *widget = GTK_WIDGET (self);
+
+ gtk_widget_activate_action (widget,
+ "list.scroll-to-item",
+ "u",
+ self->position);
+}
+
+static void
gtk_list_item_click_gesture_released (GtkGestureClick *gesture,
int n_press,
double x,
@@ -289,6 +302,7 @@ gtk_list_item_click_gesture_canceled (GtkGestureClick *gesture,
static void
gtk_list_item_init (GtkListItem *self)
{
+ GtkEventController *controller;
GtkGesture *gesture;
self->selectable = TRUE;
@@ -308,6 +322,10 @@ gtk_list_item_init (GtkListItem *self)
g_signal_connect (gesture, "cancel",
G_CALLBACK (gtk_list_item_click_gesture_canceled), self);
gtk_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (gesture));
+
+ controller = gtk_event_controller_focus_new ();
+ g_signal_connect (controller, "enter", G_CALLBACK (gtk_list_item_enter_cb), self);
+ gtk_widget_add_controller (GTK_WIDGET (self), controller);
}
GtkListItem *