[gtk/columnview-scrolling: 31/32] columnview: Revise scroll-minimum handling
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/columnview-scrolling: 31/32] columnview: Revise scroll-minimum handling
- Date: Wed, 3 Jun 2020 16:19:27 +0000 (UTC)
commit 8a9777d969b372bf1b8c7219feadfaf5401a9240
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Dec 16 19:22:03 2019 -0500
columnview: Revise scroll-minimum handling
Tweak the behavior slightly. We don't show
a scrollbar as long as we have at least
min-size available, but we still give the
entire size to the child, up to nat-size.
This matches how viewports handle scroll-minimum.
gtk/gtkcolumnview.c | 52 ++++++++++++++++++++++++++++++----------------------
1 file changed, 30 insertions(+), 22 deletions(-)
---
diff --git a/gtk/gtkcolumnview.c b/gtk/gtkcolumnview.c
index e94875ae71..2f62aec830 100644
--- a/gtk/gtkcolumnview.c
+++ b/gtk/gtkcolumnview.c
@@ -34,6 +34,7 @@
#include "gtkprivate.h"
#include "gtkscrollable.h"
#include "gtkwidgetprivate.h"
+#include "gtksizerequest.h"
/**
* SECTION:gtkcolumnview
@@ -171,46 +172,53 @@ gtk_column_view_allocate_columns (GtkColumnView *self,
GtkScrollablePolicy scroll_policy;
int col_min, col_nat, widget_min, widget_nat, extra, col_size, x;
guint i;
+ int n;
+ GtkRequestedSize *sizes;
+
+ n = g_list_model_get_n_items (G_LIST_MODEL (self->columns));
+ sizes = g_newa (GtkRequestedSize, n);
+ for (i = 0; i < n; i++)
+ {
+ GtkColumnViewColumn *column;
+
+ column = g_list_model_get_item (G_LIST_MODEL (self->columns), i);
+ if (gtk_column_view_column_get_visible (column))
+ gtk_column_view_column_measure (column, &sizes[i].minimum_size, &sizes[i].natural_size);
+ else
+ sizes[i].minimum_size = sizes[i].natural_size = 0;
+ g_object_unref (column);
+ }
gtk_column_view_measure_across (self, &col_min, &col_nat);
- gtk_widget_measure (GTK_WIDGET (self),
- GTK_ORIENTATION_HORIZONTAL, -1,
- &widget_min, &widget_nat,
- NULL, NULL);
scroll_policy = gtk_scrollable_get_hscroll_policy (GTK_SCROLLABLE (self->listview));
if (scroll_policy == GTK_SCROLL_MINIMUM)
{
- extra = widget_min - col_min;
- col_size = col_min;
+ extra = MAX (width - col_min, 0);
+ gtk_distribute_natural_allocation (extra, n, sizes);
}
- else
- {
- extra = widget_nat - col_nat;
- col_size = col_nat;
- }
- width -= extra;
- width = MAX (width, col_size);
x = 0;
- for (i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (self->columns)); i++)
+ for (i = 0; i < n; i++)
{
GtkColumnViewColumn *column;
column = g_list_model_get_item (G_LIST_MODEL (self->columns), i);
- gtk_column_view_column_measure (column, &col_min, &col_nat);
- if (scroll_policy == GTK_SCROLL_MINIMUM)
- col_size = col_min;
- else
- col_size = col_nat;
+ if (gtk_column_view_column_get_visible (column))
+ {
+ if (scroll_policy == GTK_SCROLL_MINIMUM)
+ col_size = sizes[i].minimum_size;
+ else
+ col_size = sizes[i].natural_size;
- gtk_column_view_column_allocate (column, x, col_size);
- x += col_size;
+ gtk_column_view_column_allocate (column, x, col_size);
+ x += col_size;
+ }
g_object_unref (column);
}
- return width + extra;
+ return x;
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]