[tepl] utils: add list_box_setup_scrolling()



commit 465ef62ef54096708d08f6acf39f388712d26f56
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Tue Nov 3 00:49:07 2020 +0100

    utils: add list_box_setup_scrolling()

 docs/reference/tepl-sections.txt        |  1 +
 tepl/tepl-style-scheme-chooser-widget.c |  5 ++---
 tepl/tepl-utils.c                       | 35 ++++++++++++++++++++++++++++++++-
 tepl/tepl-utils.h                       |  4 ++++
 4 files changed, 41 insertions(+), 4 deletions(-)
---
diff --git a/docs/reference/tepl-sections.txt b/docs/reference/tepl-sections.txt
index ef0627c..637831d 100644
--- a/docs/reference/tepl-sections.txt
+++ b/docs/reference/tepl-sections.txt
@@ -514,6 +514,7 @@ tepl_utils_file_query_exists_finish
 tepl_utils_create_close_button
 tepl_utils_show_warning_dialog
 tepl_utils_list_box_clear
+tepl_utils_list_box_setup_scrolling
 tepl_utils_list_box_scroll_to_row
 tepl_utils_list_box_scroll_to_selected_row
 tepl_utils_binding_transform_func_smart_bool
diff --git a/tepl/tepl-style-scheme-chooser-widget.c b/tepl/tepl-style-scheme-chooser-widget.c
index 5379334..95427cd 100644
--- a/tepl/tepl-style-scheme-chooser-widget.c
+++ b/tepl/tepl-style-scheme-chooser-widget.c
@@ -377,7 +377,6 @@ static void
 tepl_style_scheme_chooser_widget_init (TeplStyleSchemeChooserWidget *chooser)
 {
        GtkWidget *scrolled_window;
-       GtkAdjustment *vadjustment;
 
        chooser->priv = tepl_style_scheme_chooser_widget_get_instance_private (chooser);
 
@@ -399,8 +398,8 @@ tepl_style_scheme_chooser_widget_init (TeplStyleSchemeChooserWidget *chooser)
        gtk_widget_show_all (scrolled_window);
        gtk_container_add (GTK_CONTAINER (chooser), scrolled_window);
 
-       vadjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scrolled_window));
-       gtk_container_set_focus_vadjustment (GTK_CONTAINER (chooser->priv->list_box), vadjustment);
+       tepl_utils_list_box_setup_scrolling (chooser->priv->list_box,
+                                            GTK_SCROLLED_WINDOW (scrolled_window));
 
        g_signal_connect (chooser->priv->list_box,
                          "selected-rows-changed",
diff --git a/tepl/tepl-utils.c b/tepl/tepl-utils.c
index 760d60b..3aa6518 100644
--- a/tepl/tepl-utils.c
+++ b/tepl/tepl-utils.c
@@ -823,11 +823,42 @@ tepl_utils_list_box_clear (GtkListBox *list_box)
                               NULL);
 }
 
+/**
+ * tepl_utils_list_box_setup_scrolling:
+ * @list_box: a #GtkListBox.
+ * @scrolled_window: a #GtkScrolledWindow.
+ *
+ * Setup vertical scrolling between @list_box and @scrolled_window, to be able
+ * to use tepl_utils_list_box_scroll_to_row() afterwards.
+ *
+ * This function is intended to be called only once per #GtkListBox, when
+ * initializing the @list_box and @scrolled_window widgets.
+ *
+ * Since: 5.2
+ */
+void
+tepl_utils_list_box_setup_scrolling (GtkListBox        *list_box,
+                                    GtkScrolledWindow *scrolled_window)
+{
+       GtkAdjustment *vadjustment;
+
+       g_return_if_fail (GTK_IS_LIST_BOX (list_box));
+       g_return_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window));
+
+       vadjustment = gtk_scrolled_window_get_vadjustment (scrolled_window);
+       gtk_container_set_focus_vadjustment (GTK_CONTAINER (list_box), vadjustment);
+}
+
 /**
  * tepl_utils_list_box_scroll_to_row:
  * @list_box: a #GtkListBox.
  * @row: a #GtkListBoxRow.
  *
+ * Scrolls to a specific #GtkListBoxRow.
+ *
+ * Before using this function, tepl_utils_list_box_setup_scrolling() must have
+ * been called.
+ *
  * Since: 5.2
  */
 void
@@ -837,7 +868,6 @@ tepl_utils_list_box_scroll_to_row (GtkListBox    *list_box,
        g_return_if_fail (GTK_IS_LIST_BOX (list_box));
        g_return_if_fail (GTK_IS_LIST_BOX_ROW (row));
 
-       /* gtk_container_set_focus_vadjustment() must also be called beforehand. */
        gtk_container_set_focus_child (GTK_CONTAINER (list_box), GTK_WIDGET (row));
 }
 
@@ -849,6 +879,9 @@ tepl_utils_list_box_scroll_to_row (GtkListBox    *list_box,
  * gtk_list_box_get_selected_row(). This function assumes that there is either
  * zero or one selected row.
  *
+ * Before using this function, tepl_utils_list_box_setup_scrolling() must have
+ * been called.
+ *
  * Since: 5.2
  */
 void
diff --git a/tepl/tepl-utils.h b/tepl/tepl-utils.h
index 485f743..79f50d3 100644
--- a/tepl/tepl-utils.h
+++ b/tepl/tepl-utils.h
@@ -86,6 +86,10 @@ void         tepl_utils_show_warning_dialog                  (GtkWindow   *parent,
 _TEPL_EXTERN
 void           tepl_utils_list_box_clear                       (GtkListBox *list_box);
 
+_TEPL_EXTERN
+void           tepl_utils_list_box_setup_scrolling             (GtkListBox        *list_box,
+                                                                GtkScrolledWindow *scrolled_window);
+
 _TEPL_EXTERN
 void           tepl_utils_list_box_scroll_to_row               (GtkListBox    *list_box,
                                                                 GtkListBoxRow *row);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]