[gtk/wip/otte/listview: 4/5] gridview: Implement minimum row height
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/listview: 4/5] gridview: Implement minimum row height
- Date: Sat, 19 Oct 2019 20:30:02 +0000 (UTC)
commit 2ce88cd80ee3b5e22b45ea16b0967d05fcdc2011
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 | 6 ++++--
2 files changed, 10 insertions(+), 6 deletions(-)
---
diff --git a/gtk/gtkgridview.c b/gtk/gtkgridview.c
index 76a6100c2d..a8eef0c48b 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)
@@ -357,8 +357,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 ||
@@ -853,13 +853,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)
@@ -896,6 +897,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 e89d34e0b8..9c0098b1bd 100644
--- a/tests/testlistview.c
+++ b/tests/testlistview.c
@@ -537,6 +537,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);
}
@@ -631,7 +633,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));
@@ -659,7 +661,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]