gridview: Implement minimum row height

We only allocate a certain amount of widgets - and we don't want to run
out of them. So we make all widgets high enough for this to never
happen.
This commit is contained in:
Benjamin Otte 2019-10-19 21:45:24 +02:00 committed by Matthias Clasen
parent cc68073af0
commit affd2737d5
2 changed files with 10 additions and 6 deletions

View File

@ -39,7 +39,7 @@
* We multiply this number with GtkGridView:max-columns so
* that we can always display at least this many rows.
*/
#define GTK_GRID_VIEW_MIN_VISIBLE_ROWS (30)
#define GTK_GRID_VIEW_MAX_VISIBLE_ROWS (30)
#define DEFAULT_MAX_COLUMNS (7)
@ -355,8 +355,8 @@ gtk_grid_view_set_anchor (GtkGridView *self,
gtk_list_item_tracker_set_position (self->item_manager,
self->anchor,
position,
(GTK_GRID_VIEW_MIN_VISIBLE_ROWS * yalign + 1) * self->max_columns,
(GTK_GRID_VIEW_MIN_VISIBLE_ROWS * (1 - yalign) + 1) * self->max_columns);
(ceil (GTK_GRID_VIEW_MAX_VISIBLE_ROWS * yalign) + 1) * self->max_columns,
(ceil (GTK_GRID_VIEW_MAX_VISIBLE_ROWS * (1 - yalign)) + 1) * self->max_columns);
if (self->anchor_xalign != xalign ||
self->anchor_xstart != xstart ||
@ -856,13 +856,14 @@ gtk_grid_view_size_allocate (GtkWidget *widget,
GtkGridView *self = GTK_GRID_VIEW (widget);
Cell *cell, *start;
GArray *heights;
int row_height, col_min, col_nat;
int min_row_height, row_height, col_min, col_nat;
GtkOrientation opposite_orientation;
gboolean known;
int x, y;
guint i;
opposite_orientation = OPPOSITE_ORIENTATION (self->orientation);
min_row_height = ceil ((double) height / GTK_GRID_VIEW_MAX_VISIBLE_ROWS);
/* step 0: exit early if list is empty */
if (gtk_list_item_manager_get_root (self->item_manager) == NULL)
@ -899,6 +900,7 @@ gtk_grid_view_size_allocate (GtkWidget *widget,
size = min;
else
size = nat;
size = MAX (size, min_row_height);
g_array_append_val (heights, size);
row_height = MAX (row_height, size);
}

View File

@ -513,6 +513,8 @@ setup_widget (GtkListItem *list_item,
gtk_box_append (GTK_BOX (box), data->icon);
data->name = gtk_label_new (NULL);
gtk_label_set_max_width_chars (GTK_LABEL (data->name), 25);
gtk_label_set_ellipsize (GTK_LABEL (data->name), PANGO_ELLIPSIZE_END);
gtk_box_append (GTK_BOX (box), data->name);
}
@ -615,7 +617,7 @@ main (int argc, char *argv[])
gtk_search_entry_set_key_capture_widget (GTK_SEARCH_ENTRY (search_entry), sw);
gtk_box_append (GTK_BOX (vbox), sw);
listview = gtk_list_view_new_with_factory (
listview = gtk_grid_view_new_with_factory (
gtk_functions_list_item_factory_new (setup_widget,
NULL,
NULL, NULL));
@ -642,7 +644,7 @@ main (int argc, char *argv[])
selectionmodel = file_info_selection_new (G_LIST_MODEL (filter));
g_object_unref (filter);
gtk_list_view_set_model (GTK_LIST_VIEW (listview), G_LIST_MODEL (selectionmodel));
gtk_grid_view_set_model (GTK_GRID_VIEW (listview), G_LIST_MODEL (selectionmodel));
statusbar = gtk_statusbar_new ();
gtk_widget_add_tick_callback (statusbar, (GtkTickCallback) update_statusbar, NULL, NULL);