mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-30 15:31:34 +00:00
columnview: Take expand into account
When allocating columns, distribute extra space to columns that have expand set to TRUE.
This commit is contained in:
parent
2ab1b13092
commit
067df8d4dd
@ -194,11 +194,12 @@ gtk_column_view_allocate_columns (GtkColumnView *self,
|
||||
{
|
||||
GtkScrollablePolicy scroll_policy;
|
||||
int col_min, col_nat, extra, col_size, x;
|
||||
int n, n_expand, expand_size, n_extra;
|
||||
guint i;
|
||||
int n;
|
||||
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++)
|
||||
{
|
||||
@ -206,7 +207,11 @@ gtk_column_view_allocate_columns (GtkColumnView *self,
|
||||
|
||||
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);
|
||||
{
|
||||
gtk_column_view_column_measure (column, &sizes[i].minimum_size, &sizes[i].natural_size);
|
||||
if (gtk_column_view_column_get_expand (column))
|
||||
n_expand++;
|
||||
}
|
||||
else
|
||||
sizes[i].minimum_size = sizes[i].natural_size = 0;
|
||||
g_object_unref (column);
|
||||
@ -216,10 +221,18 @@ gtk_column_view_allocate_columns (GtkColumnView *self,
|
||||
|
||||
scroll_policy = gtk_scrollable_get_hscroll_policy (GTK_SCROLLABLE (self->listview));
|
||||
if (scroll_policy == GTK_SCROLL_MINIMUM)
|
||||
extra = MAX (width - col_min, 0);
|
||||
else
|
||||
extra = MAX (width - col_min, col_nat - col_min);
|
||||
|
||||
extra = gtk_distribute_natural_allocation (extra, n, sizes);
|
||||
if (n_expand > 0)
|
||||
{
|
||||
extra = MAX (width - col_min, 0);
|
||||
gtk_distribute_natural_allocation (extra, n, sizes);
|
||||
expand_size = extra / n_expand;
|
||||
n_extra = extra % n_expand;
|
||||
}
|
||||
else
|
||||
expand_size = n_extra = 0;
|
||||
|
||||
x = 0;
|
||||
for (i = 0; i < n; i++)
|
||||
@ -229,10 +242,16 @@ gtk_column_view_allocate_columns (GtkColumnView *self,
|
||||
column = g_list_model_get_item (G_LIST_MODEL (self->columns), i);
|
||||
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;
|
||||
col_size = sizes[i].minimum_size;
|
||||
if (gtk_column_view_column_get_expand (column))
|
||||
{
|
||||
col_size += expand_size;
|
||||
if (n_extra > 0)
|
||||
{
|
||||
col_size++;
|
||||
n_extra--;
|
||||
}
|
||||
}
|
||||
|
||||
gtk_column_view_column_allocate (column, x, col_size);
|
||||
if (self->in_column_reorder && i == self->drag_pos)
|
||||
|
Loading…
Reference in New Issue
Block a user