diff options
author | Emmanuele Bassi <ebassi@gnome.org> | 2013-09-19 18:30:50 +0100 |
---|---|---|
committer | Emmanuele Bassi <ebassi@gnome.org> | 2013-09-19 18:33:42 +0100 |
commit | 2c8f2c033972da05773007ce13f6100bbd05b7fb (patch) | |
tree | 4f94543a4b52d271cc126f112016a6848a7b33a6 | |
parent | af21e2ef88fe21b5ad955d5b3b59aae2e06f87a5 (diff) |
Ensure a correct minimum height for EosFlexyGrid
The FlexyGrid cannot really have a fixed minimum height, since we don't
support width-for-height layout. This means that the FlexyGrid needs a
minimum height equal to its natural height - and we need to compute the
latter depending on the passed width.
This fixes the height handling when packing a EosFlexyGrid inside a
GtkScrolledWindow.
[endlessm/eos-sdk#1015]
[endlessm/eos-sdk#1015]
-rw-r--r-- | endless/eosflexygrid.c | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/endless/eosflexygrid.c b/endless/eosflexygrid.c index 267e546..14e0229 100644 --- a/endless/eosflexygrid.c +++ b/endless/eosflexygrid.c @@ -118,10 +118,11 @@ static inline void add_new_empty_line (GArray *array, guint n_cols) { - static gboolean empty = TRUE; + guint start = array->len; - for (guint i = 0; i < n_cols; i++) - g_array_append_val (array, empty); + g_array_set_size (array, array->len + n_cols); + for (guint i = start; i < array->len; i++) + g_array_index (array, gboolean, i) = TRUE; } static guint @@ -325,7 +326,7 @@ distribute_layout (GSequence *children, guint real_width = cell_width; GArray *array = g_array_new (FALSE, FALSE, sizeof (gboolean)); guint current_pos = 0; - int max_height = 0; + int max_height = cell_width; add_new_empty_line (array, n_columns); @@ -371,14 +372,12 @@ distribute_layout (GSequence *children, break; } - max_height = MAX (max_height, request.y + request.height); + max_height = MAX (max_height, request.y + request.height + spacing); if (allocate) gtk_widget_size_allocate (GTK_WIDGET (cell), &request); } - max_height = MAX (max_height, (array->len * (real_width + spacing) / n_columns) + 50); - g_array_unref (array); DEBUG (g_print ("%s size: { %d x %d }\n", @@ -471,21 +470,18 @@ eos_flexy_grid_get_preferred_height_for_width (GtkWidget *widget, gint *natural_height_out) { EosFlexyGridPrivate *priv = EOS_FLEXY_GRID (widget)->priv; - int minimum_height, natural_height; int cell_size = priv->cell_size < 0 ? DEFAULT_CELL_SIZE : priv->cell_size; + int cell_spacing = priv->cell_spacing < 0 ? DEFAULT_SPACING : priv->cell_spacing; int layout_height; - /* minimum height: the maximum height of all the cells on a single row */ - minimum_height = cell_size * 2; - - layout_height = distribute_layout (priv->children, for_width, cell_size, priv->cell_spacing, FALSE); + layout_height = distribute_layout (priv->children, for_width, cell_size, cell_spacing, FALSE); if (minimum_height_out) - *minimum_height_out = minimum_height; + *minimum_height_out = layout_height; if (natural_height_out) - *natural_height_out = MAX (layout_height, minimum_height); + *natural_height_out = layout_height; } static void @@ -516,9 +512,10 @@ eos_flexy_grid_size_allocate (GtkWidget *widget, EosFlexyGridPrivate *priv = EOS_FLEXY_GRID (widget)->priv; int cell_size = priv->cell_size < 0 ? DEFAULT_CELL_SIZE : priv->cell_size; + int cell_spacing = priv->cell_spacing < 0 ? DEFAULT_SPACING : priv->cell_spacing; int available_width = allocation->width; - distribute_layout (priv->children, available_width, cell_size, priv->cell_spacing, TRUE); + distribute_layout (priv->children, available_width, cell_size, cell_spacing, TRUE); } static void |