diff --git a/demos/gtk-demo/listview_settings.ui b/demos/gtk-demo/listview_settings.ui index 12466a8a5b..0dd3daa793 100644 --- a/demos/gtk-demo/listview_settings.ui +++ b/demos/gtk-demo/listview_settings.ui @@ -161,6 +161,7 @@ Default 1 + 1 header_menu @@ -190,6 +191,7 @@ Summary 1 0 + 1 header_menu @@ -222,6 +224,7 @@ Description 1 0 + 1 header_menu diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt index 20f8352592..dc19164f0c 100644 --- a/docs/reference/gtk/gtk4-sections.txt +++ b/docs/reference/gtk/gtk4-sections.txt @@ -541,6 +541,8 @@ gtk_column_view_column_set_header_menu gtk_column_view_column_get_header_menu gtk_column_view_column_set_fixed_width gtk_column_view_column_get_fixed_width +gtk_column_view_column_set_expand +gtk_column_view_column_get_expand GTK_COLUMN_VIEW_COLUMN diff --git a/gtk/gtkcolumnview.c b/gtk/gtkcolumnview.c index 7a223d17e7..a3640fc64e 100644 --- a/gtk/gtkcolumnview.c +++ b/gtk/gtkcolumnview.c @@ -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) diff --git a/gtk/gtkcolumnviewcolumn.c b/gtk/gtkcolumnviewcolumn.c index 8879457a7f..0567931905 100644 --- a/gtk/gtkcolumnviewcolumn.c +++ b/gtk/gtkcolumnviewcolumn.c @@ -64,8 +64,9 @@ struct _GtkColumnViewColumn int fixed_width; - guint visible : 1; - guint resizable : 1; + guint visible : 1; + guint resizable : 1; + guint expand : 1; GMenuModel *menu; @@ -88,6 +89,7 @@ enum PROP_VISIBLE, PROP_HEADER_MENU, PROP_RESIZABLE, + PROP_EXPAND, PROP_FIXED_WIDTH, N_PROPS @@ -151,6 +153,10 @@ gtk_column_view_column_get_property (GObject *object, g_value_set_boolean (value, self->resizable); break; + case PROP_EXPAND: + g_value_set_boolean (value, self->expand); + break; + case PROP_FIXED_WIDTH: g_value_set_int (value, self->fixed_width); break; @@ -195,6 +201,10 @@ gtk_column_view_column_set_property (GObject *object, gtk_column_view_column_set_resizable (self, g_value_get_boolean (value)); break; + case PROP_EXPAND: + gtk_column_view_column_set_expand (self, g_value_get_boolean (value)); + break; + case PROP_FIXED_WIDTH: gtk_column_view_column_set_fixed_width (self, g_value_get_int (value)); break; @@ -298,6 +308,18 @@ gtk_column_view_column_class_init (GtkColumnViewColumnClass *klass) FALSE, G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS); + /** + * GtkColumnViewColumn:expand: + * + * Column gets share of extra width allocated to the view + */ + properties[PROP_EXPAND] = + g_param_spec_boolean ("expand", + P_("Expand"), + P_("column gets share of extra width"), + FALSE, + G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS); + /** * GtkColumnViewColumn:fixed-width: * @@ -321,6 +343,7 @@ gtk_column_view_column_init (GtkColumnViewColumn *self) self->natural_size_request = -1; self->visible = TRUE; self->resizable = FALSE; + self->expand = FALSE; self->fixed_width = -1; } @@ -845,6 +868,49 @@ gtk_column_view_column_get_header_menu (GtkColumnViewColumn *self) return self->menu; } +/** + * gtk_column_view_column_set_expand: + * @self: a #GtkColumnViewColumn + * @expand: %TRUE if this column should expand to fill available sace + * + * Sets the column to take available extra space. + * + * The extra space is shared equally amongst all columns that + * have the expand set to %TRUE. + */ +void +gtk_column_view_column_set_expand (GtkColumnViewColumn *self, + gboolean expand) +{ + g_return_if_fail (GTK_IS_COLUMN_VIEW_COLUMN (self)); + + if (self->expand == expand) + return; + + self->expand = expand; + + if (self->visible && self->view) + gtk_widget_queue_resize (GTK_WIDGET (self->view)); + + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_EXPAND]); +} + +/** + * gtk_column_view_get_expand: + * @self: a #GtkColumnViewColumn + * + * Returns whether this column should expand. + * + * Returns: %TRUE if this column expands + */ +gboolean +gtk_column_view_column_get_expand (GtkColumnViewColumn *self) +{ + g_return_val_if_fail (GTK_IS_COLUMN_VIEW_COLUMN (self), TRUE); + + return self->expand; +} + /** * gtk_column_view_column_set_resizable: * @self: a #GtkColumnViewColumn diff --git a/gtk/gtkcolumnviewcolumn.h b/gtk/gtkcolumnviewcolumn.h index 459c4d372f..a0e9bd946c 100644 --- a/gtk/gtkcolumnviewcolumn.h +++ b/gtk/gtkcolumnviewcolumn.h @@ -96,6 +96,12 @@ void gtk_column_view_column_set_resizable (GtkColu GDK_AVAILABLE_IN_ALL gboolean gtk_column_view_column_get_resizable (GtkColumnViewColumn *self); +GDK_AVAILABLE_IN_ALL +void gtk_column_view_column_set_expand (GtkColumnViewColumn *self, + gboolean expand); +GDK_AVAILABLE_IN_ALL +gboolean gtk_column_view_column_get_expand (GtkColumnViewColumn *self); + G_END_DECLS #endif /* __GTK_COLUMN_VIEW_COLUMN_H__ */ diff --git a/gtk/inspector/actions.ui b/gtk/inspector/actions.ui index 1dce62f250..558c5ae734 100644 --- a/gtk/inspector/actions.ui +++ b/gtk/inspector/actions.ui @@ -62,6 +62,7 @@ + 1 diff --git a/gtk/inspector/object-tree.ui b/gtk/inspector/object-tree.ui index ada53a08e6..06e7229e59 100644 --- a/gtk/inspector/object-tree.ui +++ b/gtk/inspector/object-tree.ui @@ -45,6 +45,7 @@ Type + 1 @@ -57,6 +58,7 @@ Name + 1 @@ -68,6 +70,7 @@ Label + 1 diff --git a/gtk/inspector/prop-list.ui b/gtk/inspector/prop-list.ui index 56b84661e7..9c952c3f41 100644 --- a/gtk/inspector/prop-list.ui +++ b/gtk/inspector/prop-list.ui @@ -54,6 +54,7 @@ Value + 1 diff --git a/gtk/inspector/resource-list.ui b/gtk/inspector/resource-list.ui index 9719153954..74882e7592 100644 --- a/gtk/inspector/resource-list.ui +++ b/gtk/inspector/resource-list.ui @@ -62,6 +62,7 @@ Path + 1 @@ -92,6 +93,11 @@ + + + 1 + +