[gnome-shell] Add partial implementation of dynamic width/height layout to TidyGrid
- From: Owen Taylor <otaylor src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-shell] Add partial implementation of dynamic width/height layout to TidyGrid
- Date: Sat, 4 Jul 2009 16:37:07 +0000 (UTC)
commit e9966b4aff18712eff099c525bbb55ab2a50262d
Author: Owen W. Taylor <otaylor fishsoup net>
Date: Fri Jul 3 22:31:22 2009 -0400
Add partial implementation of dynamic width/height layout to TidyGrid
This is not a complete patch; it doesn't attempt to handle the homogenous
property or column major.
(Based on patch by Colin Walters <walters verbum org>)
http://bugzilla.gnome.org/show_bug.cgi?id=587720
src/tidy/tidy-grid.c | 75 +++++++++++++++++++++++++++++++++++++++----------
1 files changed, 59 insertions(+), 16 deletions(-)
---
diff --git a/src/tidy/tidy-grid.c b/src/tidy/tidy-grid.c
index fb035ed..0d01336 100644
--- a/src/tidy/tidy-grid.c
+++ b/src/tidy/tidy-grid.c
@@ -1,3 +1,5 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+
/* tidy-grid.h: Reflowing grid layout container for clutter.
*
* Copyright (C) 2008 Intel Corporation
@@ -102,7 +104,6 @@ G_DEFINE_TYPE_WITH_CODE (TidyGrid, tidy_grid,
struct _TidyGridPrivate
{
gfloat for_height, for_width;
- gfloat pref_width, pref_height;
gfloat alloc_width, alloc_height;
GHashTable *hash_table;
@@ -139,7 +140,6 @@ struct _TidyGridActorData
{
gboolean xpos_set, ypos_set;
gfloat xpos, ypos;
- gfloat pref_width, pref_height;
};
static void
@@ -660,21 +660,37 @@ tidy_grid_pick (ClutterActor *actor,
static void
tidy_grid_get_preferred_width (ClutterActor *self,
- gfloat for_height,
- gfloat *min_width_p,
- gfloat *natural_width_p)
+ gfloat for_height,
+ gfloat *min_width_p,
+ gfloat *natural_width_p)
{
TidyGrid *layout = (TidyGrid *) self;
TidyGridPrivate *priv = layout->priv;
- gfloat natural_width;
+ GList *iter;
+ gfloat natural_width = 0;
+ gfloat min_width = 0;
+
+ for (iter = priv->list; iter; iter=iter->next)
+ {
+ ClutterActor *child = iter->data;
+ gfloat child_natural_w, child_natural_h;
+ gfloat child_min_w, child_min_h;
+
+ clutter_actor_get_preferred_size (child, &child_min_w, &child_min_h,
+ &child_natural_w, &child_natural_h);
+
+ if (child_min_w > min_width)
+ min_width = child_min_w;
+ natural_width += child_natural_w;
+
+ if (iter->next)
+ natural_width += priv->column_gap;
+ }
- natural_width = 200.0;
if (min_width_p)
- *min_width_p = natural_width;
+ *min_width_p = min_width;
if (natural_width_p)
*natural_width_p = natural_width;
-
- priv->pref_width = natural_width;
}
static void
@@ -685,12 +701,42 @@ tidy_grid_get_preferred_height (ClutterActor *self,
{
TidyGrid *layout = (TidyGrid *) self;
TidyGridPrivate *priv = layout->priv;
+ gfloat current_natural_width;
+ gfloat row_height;
gfloat natural_height;
+ GList *iter;
+
+ current_natural_width = 0;
+ natural_height = 0;
+ row_height = 0;
+ for (iter = priv->list; iter; iter=iter->next)
+ {
+ ClutterActor *child = iter->data;
+ gfloat child_natural_w, child_natural_h;
+
+ clutter_actor_get_preferred_size (child, NULL, NULL,
+ &child_natural_w, &child_natural_h);
+
+ if (iter == priv->list)
+ {
+ current_natural_width = child_natural_w;
+ }
+ else if ((current_natural_width + child_natural_w) > for_width)
+ {
+ natural_height += row_height + priv->row_gap;
+ current_natural_width = child_natural_w;
+ row_height = child_natural_h;
+ }
+ else
+ {
+ current_natural_width += priv->column_gap + child_natural_w;
+ }
- natural_height = 200.0;
+ if (child_natural_h > row_height)
+ row_height = child_natural_h;
+ }
- priv->for_width = for_width;
- priv->pref_height = natural_height;
+ natural_height += row_height;
if (min_height_p)
*min_height_p = natural_height;
@@ -758,9 +804,6 @@ compute_row_height (GList *siblings,
return best_yet;
}
-
-
-
static gfloat
compute_row_start (GList *siblings,
gfloat start_x,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]