[gtk/wip/otte/listview: 94/139] gridview: Implement minimum row height
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/listview: 94/139] gridview: Implement minimum row height
- Date: Tue, 26 Nov 2019 16:48:00 +0000 (UTC)
commit bc0b2d98a3de7e11ef36e2da13b461e61d74f951
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 089ae36390..1e035be473 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 1b77f6ac38..7cb360dd00 100644
--- a/tests/testlistview.c
+++ b/tests/testlistview.c
@@ -535,6 +535,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);
}
@@ -623,7 +625,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);
@@ -637,7 +639,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));
@@ -664,7 +666,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]