[gnome-shell] Support fixed position children
- From: Colin Walters <walters src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-shell] Support fixed position children
- Date: Thu, 15 Oct 2009 21:57:27 +0000 (UTC)
commit 7c954898a269cf23fc14e5ce0d2a5eb8f6cc98d5
Author: Colin Walters <walters verbum org>
Date: Thu Oct 15 14:45:54 2009 -0400
Support fixed position children
When doing layout, check for whether x/y have been explicitly
specified, and if so honor those positions.
https://bugzilla.gnome.org/show_bug.cgi?id=598462
src/st/st-box-layout.c | 54 ++++++++++++++++++++++++++++----------
tests/interactive/box-layout.js | 6 ++++
2 files changed, 46 insertions(+), 14 deletions(-)
---
diff --git a/src/st/st-box-layout.c b/src/st/st-box-layout.c
index 44f960c..180d893 100644
--- a/src/st/st-box-layout.c
+++ b/src/st/st-box-layout.c
@@ -428,6 +428,7 @@ get_content_preferred_width (StBoxLayout *self,
{
StBoxLayoutPrivate *priv = self->priv;
gint n_children = 0;
+ gint n_fixed = 0;
gfloat min_width, natural_width;
GList *l;
@@ -444,6 +445,12 @@ get_content_preferred_width (StBoxLayout *self,
n_children++;
+ if (clutter_actor_get_fixed_position_set (child))
+ {
+ n_fixed++;
+ continue;
+ }
+
clutter_actor_get_preferred_width (child,
(!priv->is_vertical) ? for_height : -1,
&child_min,
@@ -461,10 +468,10 @@ get_content_preferred_width (StBoxLayout *self,
}
}
- if (!priv->is_vertical && n_children > 1)
+ if (!priv->is_vertical && (n_children - n_fixed) > 1)
{
- min_width += priv->spacing * (n_children - 1);
- natural_width += priv->spacing * (n_children - 1);
+ min_width += priv->spacing * (n_children - n_fixed - 1);
+ natural_width += priv->spacing * (n_children - n_fixed - 1);
}
if (min_width_p)
@@ -499,6 +506,7 @@ get_content_preferred_height (StBoxLayout *self,
{
StBoxLayoutPrivate *priv = self->priv;
gint n_children = 0;
+ gint n_fixed = 0;
gfloat min_height, natural_height;
GList *l;
@@ -515,6 +523,12 @@ get_content_preferred_height (StBoxLayout *self,
n_children++;
+ if (clutter_actor_get_fixed_position_set (child))
+ {
+ n_fixed++;
+ continue;
+ }
+
clutter_actor_get_preferred_height (child,
(priv->is_vertical) ? for_width : -1,
&child_min,
@@ -532,10 +546,10 @@ get_content_preferred_height (StBoxLayout *self,
}
}
- if (priv->is_vertical && n_children > 1)
+ if (priv->is_vertical && (n_children - n_fixed) > 1)
{
- min_height += priv->spacing * (n_children - 1);
- natural_height += priv->spacing * (n_children - 1);
+ min_height += priv->spacing * (n_children - n_fixed - 1);
+ natural_height += priv->spacing * (n_children - n_fixed - 1);
}
if (min_height_p)
@@ -605,14 +619,18 @@ compute_shrinks (StBoxLayout *self,
*/
/* Find the amount of possible shrink for each child */
- int n_visible_children = 0;
+ int n_possible_shrink_children = 0;
for (l = priv->children, i = 0; l; l = l->next, i++)
{
ClutterActor *child = l->data;
gfloat child_min, child_nat;
+ gboolean fixed;
+
+ child = (ClutterActor*) l->data;
+ fixed = clutter_actor_get_fixed_position_set (child);
shrinks[i].child_index = i;
- if (CLUTTER_ACTOR_IS_VISIBLE (child))
+ if (CLUTTER_ACTOR_IS_VISIBLE (child) && !fixed)
{
if (priv->is_vertical)
clutter_actor_get_preferred_height (child,
@@ -624,7 +642,7 @@ compute_shrinks (StBoxLayout *self,
&child_min, &child_nat);
shrinks[i].shrink_amount = MAX (0., child_nat - child_min);
- n_visible_children++;
+ n_possible_shrink_children++;
}
else
{
@@ -653,15 +671,15 @@ compute_shrinks (StBoxLayout *self,
/* Start by moving the line downward, top-of-bar by top-of-bar */
shrink_so_far = 0;
- for (n_shrink_children = 1; n_shrink_children <= n_visible_children; n_shrink_children++)
+ for (n_shrink_children = 1; n_shrink_children <= n_possible_shrink_children; n_shrink_children++)
{
- if (n_shrink_children < n_visible_children)
+ if (n_shrink_children < n_possible_shrink_children)
base_shrink = shrinks[n_shrink_children].shrink_amount;
else
base_shrink = 0;
shrink_so_far += n_shrink_children * (shrinks[n_shrink_children - 1].shrink_amount - base_shrink);
- if (shrink_so_far >= total_shrink || n_shrink_children == n_visible_children)
+ if (shrink_so_far >= total_shrink || n_shrink_children == n_possible_shrink_children)
break;
}
@@ -766,7 +784,8 @@ st_box_layout_allocate (ClutterActor *actor,
ClutterActor *child = l->data;
gboolean expand;
- if (!CLUTTER_ACTOR_IS_VISIBLE (child))
+ if (!CLUTTER_ACTOR_IS_VISIBLE (child) ||
+ clutter_actor_get_fixed_position_set (child))
continue;
clutter_container_child_get ((ClutterContainer *) actor,
@@ -808,12 +827,19 @@ st_box_layout_allocate (ClutterActor *actor,
ClutterActor *child = (ClutterActor*) l->data;
ClutterActorBox child_box;
gfloat child_min, child_nat, child_allocated;
- gboolean xfill, yfill, expand;
+ gboolean xfill, yfill, expand, fixed;
StAlign xalign, yalign;
if (!CLUTTER_ACTOR_IS_VISIBLE (child))
goto next_child;
+ fixed = clutter_actor_get_fixed_position_set (child);
+ if (fixed)
+ {
+ clutter_actor_allocate_preferred_size (child, flags);
+ goto next_child;
+ }
+
clutter_container_child_get ((ClutterContainer*) actor, child,
"x-fill", &xfill,
"y-fill", &yfill,
diff --git a/tests/interactive/box-layout.js b/tests/interactive/box-layout.js
index 4454cd0..547b128 100644
--- a/tests/interactive/box-layout.js
+++ b/tests/interactive/box-layout.js
@@ -44,6 +44,12 @@ colored_boxes.add(new St.Label({ text: "Default",
style: 'border: 1px solid #aaaaaa; '
+ 'background: #cceeff' }));
+b2.add(new St.Label({ x: 50,
+ y: 50,
+ text: "Fixed",
+ style: 'border: 1px solid #aaaaaa;'
+ + 'background: #ffffcc' }));
+
////////////////////////////////////////////////////////////////////////////////
function createCollapsableBox(width) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]