[gtk/prop-list: 28/31] columnview: Implement horizontal scrolling
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/prop-list: 28/31] columnview: Implement horizontal scrolling
- Date: Wed, 18 Dec 2019 16:22:15 +0000 (UTC)
commit 05d488a589389e54cfd8017f239a35b897486c3e
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Dec 17 00:34:14 2019 -0500
columnview: Implement horizontal scrolling
The listview inside always thinks it gets its full size,
and updates its horizontal adjustment accordingly.
So keep our own adjustment, and update it in size_allocate.
gtk/gtkcolumnview.c | 57 +++++++++++++++++++++++++++++++++++++++++++----------
1 file changed, 47 insertions(+), 10 deletions(-)
---
diff --git a/gtk/gtkcolumnview.c b/gtk/gtkcolumnview.c
index c4e0702696..745af7dc08 100644
--- a/gtk/gtkcolumnview.c
+++ b/gtk/gtkcolumnview.c
@@ -35,6 +35,7 @@
#include "gtkscrollable.h"
#include "gtkwidgetprivate.h"
#include "gtksizerequest.h"
+#include "gtkadjustment.h"
/**
* SECTION:gtkcolumnview
@@ -64,6 +65,8 @@ struct _GtkColumnView
GtkColumnListItemFactory *factory;
GtkSorter *sorter;
+
+ GtkAdjustment *hadjustment;
};
struct _GtkColumnViewClass
@@ -166,10 +169,11 @@ gtk_column_view_measure (GtkWidget *widget,
static int
gtk_column_view_allocate_columns (GtkColumnView *self,
+ int pos,
int width)
{
GtkScrollablePolicy scroll_policy;
- int col_min, col_nat, widget_min, widget_nat, extra, col_size, x;
+ int col_min, col_nat, extra, col_size, x;
guint i;
int n;
GtkRequestedSize *sizes;
@@ -204,7 +208,7 @@ gtk_column_view_allocate_columns (GtkColumnView *self,
}
}
- x = 0;
+ x = - pos;
for (i = 0; i < n; i++)
{
GtkColumnViewColumn *column;
@@ -226,7 +230,7 @@ gtk_column_view_allocate_columns (GtkColumnView *self,
g_object_unref (column);
}
- return x;
+ return x + pos;
}
static void
@@ -236,20 +240,24 @@ gtk_column_view_allocate (GtkWidget *widget,
int baseline)
{
GtkColumnView *self = GTK_COLUMN_VIEW (widget);
- int full_width, header_height, min, nat;
+ int full_width, header_height, min, nat, x;
- full_width = gtk_column_view_allocate_columns (self, width);
+ x = gtk_adjustment_get_value (self->hadjustment);
+ full_width = gtk_column_view_allocate_columns (self, x, width);
gtk_widget_measure (self->header, GTK_ORIENTATION_VERTICAL, full_width, &min, &nat, NULL, NULL);
if (gtk_scrollable_get_vscroll_policy (GTK_SCROLLABLE (self->listview)) == GTK_SCROLL_MINIMUM)
header_height = min;
else
header_height = nat;
- gtk_widget_allocate (self->header, full_width, header_height, -1, NULL);
+ gtk_widget_allocate (self->header, full_width, header_height, -1,
+ gsk_transform_translate (NULL, &GRAPHENE_POINT_INIT (-x, 0)));
gtk_widget_allocate (GTK_WIDGET (self->listview),
full_width, height - header_height, -1,
- gsk_transform_translate (NULL, &GRAPHENE_POINT_INIT (0, header_height)));
+ gsk_transform_translate (NULL, &GRAPHENE_POINT_INIT (-x, header_height)));
+
+ gtk_adjustment_configure (self->hadjustment, x, 0, full_width, width * 0.1, width * 0.9, width);
}
static void
@@ -260,6 +268,23 @@ gtk_column_view_activate_cb (GtkListView *listview,
g_signal_emit (self, signals[ACTIVATE], 0, pos);
}
+static void
+adjustment_value_changed_cb (GtkAdjustment *adjustment,
+ GtkColumnView *self)
+{
+ gtk_widget_queue_allocate (GTK_WIDGET (self));
+}
+
+static void
+clear_adjustment (GtkColumnView *self)
+{
+ if (self->hadjustment == NULL)
+ return;
+
+ g_signal_handlers_disconnect_by_func (self->hadjustment, adjustment_value_changed_cb, self);
+ g_clear_object (&self->hadjustment);
+}
+
static void
gtk_column_view_dispose (GObject *object)
{
@@ -278,6 +303,7 @@ gtk_column_view_dispose (GObject *object)
g_clear_object (&self->factory);
g_clear_object (&self->sorter);
+ clear_adjustment (self);
G_OBJECT_CLASS (gtk_column_view_parent_class)->dispose (object);
}
@@ -307,7 +333,7 @@ gtk_column_view_get_property (GObject *object,
break;
case PROP_HADJUSTMENT:
- g_value_set_object (value, gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (self->listview)));
+ g_value_set_object (value, self->hadjustment);
break;
case PROP_HSCROLL_POLICY:
@@ -347,13 +373,24 @@ gtk_column_view_set_property (GObject *object,
GParamSpec *pspec)
{
GtkColumnView *self = GTK_COLUMN_VIEW (object);
+ GtkAdjustment *adjustment;
switch (property_id)
{
case PROP_HADJUSTMENT:
- if (gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (self->listview)) != g_value_get_object (value))
+ adjustment = g_value_get_object (value);
+ if (adjustment == NULL)
+ adjustment = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
+ g_object_ref_sink (adjustment);
+
+ if (self->hadjustment != adjustment)
{
- gtk_scrollable_set_hadjustment (GTK_SCROLLABLE (self->listview), g_value_get_object (value));
+ clear_adjustment (self);
+
+ self->hadjustment = adjustment;
+
+ g_signal_connect (adjustment, "value-changed", G_CALLBACK (adjustment_value_changed_cb), self);
+
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_HADJUSTMENT]);
}
break;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]