diff options
| author | Matthias Clasen <mclasen@redhat.com> | 2019-12-16 19:22:03 -0500 |
|---|---|---|
| committer | Matthias Clasen <mclasen@redhat.com> | 2020-05-30 20:01:14 -0400 |
| commit | cbabb85e6d00e3d58d7be5eb404d71625afc9e99 (patch) | |
| tree | b5663a1e68e8b0f527d97fa4033beee03473547b | |
| parent | 1031625bd44d4d2d8c970f75e0b61a29ea9d3896 (diff) | |
| download | gtk+-cbabb85e6d00e3d58d7be5eb404d71625afc9e99.tar.gz | |
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.
| -rw-r--r-- | gtk/gtkcolumnview.c | 52 |
1 files changed, 30 insertions, 22 deletions
diff --git a/gtk/gtkcolumnview.c b/gtk/gtkcolumnview.c index 7ae41f8b1c..503c4c41b1 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 |
