[gtk/wip/otte/listview: 140/199] gridview: Implement minimum row height



commit ad98b3c166ecb9e253a0ac2c677e7faf8ae9ea7a
Author: Benjamin Otte <otte redhat com>
Date:   Sat Oct 19 21:45:24 2019 +0200

    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.

 gtk/gtkgridview.c    | 10 ++++++----
 tests/testlistview.c |  8 +++++---
 2 files changed, 11 insertions(+), 7 deletions(-)
---
diff --git a/gtk/gtkgridview.c b/gtk/gtkgridview.c
index 35fecbf9f3..18b95b7507 100644
--- a/gtk/gtkgridview.c
+++ b/gtk/gtkgridview.c
@@ -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);
         }
diff --git a/tests/testlistview.c b/tests/testlistview.c
index 46003f803d..28a43678a0 100644
--- a/tests/testlistview.c
+++ b/tests/testlistview.c
@@ -513,6 +513,8 @@ setup_widget (GtkListItem *list_item,
   gtk_container_add (GTK_CONTAINER (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_container_add (GTK_CONTAINER (box), data->name);
 }
 
@@ -601,7 +603,7 @@ main (int argc, char *argv[])
   gtk_init ();
 
   win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
-  gtk_window_set_default_size (GTK_WINDOW (win), 400, 600);
+  gtk_window_set_default_size (GTK_WINDOW (win), 800, 600);
   g_signal_connect (win, "destroy", G_CALLBACK (gtk_main_quit), win);
 
   vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
@@ -615,7 +617,7 @@ main (int argc, char *argv[])
   gtk_search_entry_set_key_capture_widget (GTK_SEARCH_ENTRY (search_entry), sw);
   gtk_container_add (GTK_CONTAINER (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);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]