columnview: Split gtk_column_view_allocate_columns

Split off a helper function that just distributes
the widths, without actually allocating the columns.

This will be used in measuring in the future.
This commit is contained in:
Matthias Clasen 2020-06-05 11:24:55 -04:00
parent 11a18bd61a
commit f6da324670
2 changed files with 42 additions and 7 deletions

View File

@ -236,19 +236,19 @@ gtk_column_view_measure (GtkWidget *widget,
}
}
static int
gtk_column_view_allocate_columns (GtkColumnView *self,
int width)
void
gtk_column_view_distribute_width (GtkColumnView *self,
int width,
GtkRequestedSize *sizes)
{
GtkScrollablePolicy scroll_policy;
int col_min, col_nat, extra, col_size, x;
int col_min, col_nat, extra, col_size;
int n, n_expand, expand_size, n_extra;
guint i;
GtkRequestedSize *sizes;
n = g_list_model_get_n_items (G_LIST_MODEL (self->columns));
n_expand = 0;
sizes = g_newa (GtkRequestedSize, n);
for (i = 0; i < n; i++)
{
GtkColumnViewColumn *column;
@ -282,7 +282,6 @@ gtk_column_view_allocate_columns (GtkColumnView *self,
else
expand_size = n_extra = 0;
x = 0;
for (i = 0; i < n; i++)
{
GtkColumnViewColumn *column;
@ -300,6 +299,37 @@ gtk_column_view_allocate_columns (GtkColumnView *self,
n_extra--;
}
}
sizes[i].minimum_size = col_size;
}
g_object_unref (column);
}
}
static int
gtk_column_view_allocate_columns (GtkColumnView *self,
int width)
{
guint i, n;
int x;
GtkRequestedSize *sizes;
n = g_list_model_get_n_items (G_LIST_MODEL (self->columns));
sizes = g_newa (GtkRequestedSize, n);
gtk_column_view_distribute_width (self, width, sizes);
x = 0;
for (i = 0; i < n; i++)
{
GtkColumnViewColumn *column;
int col_size;
column = g_list_model_get_item (G_LIST_MODEL (self->columns), i);
if (gtk_column_view_column_get_visible (column))
{
col_size = sizes[i].minimum_size;
gtk_column_view_column_allocate (column, x, col_size);
if (self->in_column_reorder && i == self->drag_pos)

View File

@ -22,6 +22,7 @@
#include "gtk/gtkcolumnview.h"
#include "gtk/gtklistview.h"
#include "gtk/gtksizerequest.h"
#include "gtk/gtkcolumnviewsorterprivate.h"
#include "gtk/gtklistitemwidgetprivate.h"
@ -33,4 +34,8 @@ void gtk_column_view_measure_across (GtkColumnView
int *minimum,
int *natural);
void gtk_column_view_distribute_width (GtkColumnView *self,
int width,
GtkRequestedSize *sizes);
#endif /* __GTK_COLUMN_VIEW_PRIVATE_H__ */