[gnome-shell/shell-toolkit] Turn StBoxLayout:spacing into a style property



commit 1283f0b16069bba7cb732a0723acc8927d311820
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Tue Sep 29 23:03:41 2009 -0400

    Turn StBoxLayout:spacing into a style property
    
    Remove the StBoxLayout:spacing GObject property, and instead make
    BoxLayout look up the spacing from the CSS style. This makes it
    consistent with padding and will allow the use of units. (The
    removal of the GObject property entirely instead of making it an
    override is consistent with how we handle color, font, padding, etc.)
    
    https://bugzilla.gnome.org/show_bug.cgi?id=596803

 src/st/st-box-layout.c            |   79 +++++++++----------------------------
 src/st/st-box-layout.h            |    4 --
 tests/interactive/borders.js      |    5 +-
 tests/interactive/box-layout.js   |    4 +-
 tests/interactive/inline-style.js |    2 +-
 5 files changed, 25 insertions(+), 69 deletions(-)
---
diff --git a/src/st/st-box-layout.c b/src/st/st-box-layout.c
index b3f347c..efac522 100644
--- a/src/st/st-box-layout.c
+++ b/src/st/st-box-layout.c
@@ -61,7 +61,6 @@ enum {
 
   PROP_VERTICAL,
   PROP_PACK_START,
-  PROP_SPACING,
 
   PROP_HADJUST,
   PROP_VADJUST
@@ -348,10 +347,6 @@ st_box_layout_get_property (GObject    *object,
       g_value_set_boolean (value, priv->is_pack_start);
       break;
 
-    case PROP_SPACING:
-      g_value_set_uint (value, priv->spacing);
-      break;
-
     case PROP_HADJUST:
       scrollable_get_adjustments (ST_SCROLLABLE (object), &adjustment, NULL);
       g_value_set_object (value, adjustment);
@@ -385,10 +380,6 @@ st_box_layout_set_property (GObject      *object,
       st_box_layout_set_pack_start (box, g_value_get_boolean (value));
       break;
 
-    case PROP_SPACING:
-      st_box_layout_set_spacing (box, g_value_get_uint (value));
-      break;
-
     case PROP_HADJUST:
       scrollable_set_adjustments (ST_SCROLLABLE (object),
                                   g_value_get_object (value),
@@ -1073,10 +1064,27 @@ st_box_layout_pick (ClutterActor       *actor,
 }
 
 static void
+st_box_layout_style_changed (StWidget *self)
+{
+  StBoxLayoutPrivate *priv = ST_BOX_LAYOUT (self)->priv;
+  StThemeNode *theme_node = st_widget_get_theme_node (self);
+  int old_spacing = priv->spacing;
+  double spacing = 0;
+
+  st_theme_node_get_length (theme_node, "spacing", FALSE, &spacing);
+  priv->spacing = (int)(spacing + 0.5);
+  if (priv->spacing != old_spacing)
+    clutter_actor_queue_relayout (CLUTTER_ACTOR (self));
+
+  ST_WIDGET_CLASS (st_box_layout_parent_class)->style_changed (self);
+}
+
+static void
 st_box_layout_class_init (StBoxLayoutClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
   ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
+  StWidgetClass *widget_class = ST_WIDGET_CLASS (klass);
   GParamSpec *pspec;
 
   g_type_class_add_private (klass, sizeof (StBoxLayoutPrivate));
@@ -1093,6 +1101,8 @@ st_box_layout_class_init (StBoxLayoutClass *klass)
   actor_class->paint = st_box_layout_paint;
   actor_class->pick = st_box_layout_pick;
 
+  widget_class->style_changed = st_box_layout_style_changed;
+
   pspec = g_param_spec_boolean ("vertical",
                                 "Vertical",
                                 "Whether the layout should be vertical, rather"
@@ -1108,13 +1118,6 @@ st_box_layout_class_init (StBoxLayoutClass *klass)
                                 ST_PARAM_READWRITE);
   g_object_class_install_property (object_class, PROP_PACK_START, pspec);
 
-  pspec = g_param_spec_uint ("spacing",
-                             "Spacing",
-                             "Spacing between children",
-                             0, G_MAXUINT, 0,
-                             ST_PARAM_READWRITE);
-  g_object_class_install_property (object_class, PROP_SPACING, pspec);
-
   /* StScrollable properties */
   g_object_class_override_property (object_class,
                                     PROP_HADJUST,
@@ -1222,47 +1225,3 @@ st_box_layout_get_pack_start (StBoxLayout *box)
 
   return box->priv->is_pack_start;
 }
-
-/**
- * st_box_layout_set_spacing:
- * @box: A #StBoxLayout
- * @spacing: the spacing value
- *
- * Set the amount of spacing between children in pixels
- *
- */
-void
-st_box_layout_set_spacing (StBoxLayout *box,
-                           guint        spacing)
-{
-  StBoxLayoutPrivate *priv;
-
-  g_return_if_fail (ST_IS_BOX_LAYOUT (box));
-
-  priv = box->priv;
-
-  if (priv->spacing != spacing)
-    {
-      priv->spacing = spacing;
-
-      clutter_actor_queue_relayout (CLUTTER_ACTOR (box));
-
-      g_object_notify (G_OBJECT (box), "spacing");
-    }
-}
-
-/**
- * st_box_layout_get_spacing:
- * @box: A #StBoxLayout
- *
- * Get the spacing between children in pixels
- *
- * Returns: the spacing value
- */
-guint
-st_box_layout_get_spacing (StBoxLayout *box)
-{
-  g_return_val_if_fail (ST_IS_BOX_LAYOUT (box), 0);
-
-  return box->priv->spacing;
-}
diff --git a/src/st/st-box-layout.h b/src/st/st-box-layout.h
index f7ad946..30954a2 100644
--- a/src/st/st-box-layout.h
+++ b/src/st/st-box-layout.h
@@ -89,10 +89,6 @@ void     st_box_layout_set_pack_start (StBoxLayout *box,
                                        gboolean     pack_start);
 gboolean st_box_layout_get_pack_start (StBoxLayout *box);
 
-void     st_box_layout_set_spacing    (StBoxLayout *box,
-                                       guint        spacing);
-guint    st_box_layout_get_spacing    (StBoxLayout *box);
-
 G_END_DECLS
 
 #endif /* _ST_BOX_LAYOUT_H */
diff --git a/tests/interactive/borders.js b/tests/interactive/borders.js
index d685345..774e380 100644
--- a/tests/interactive/borders.js
+++ b/tests/interactive/borders.js
@@ -13,8 +13,9 @@ stage.height = 700;
 let vbox = new St.BoxLayout({ vertical: true,
                               width: stage.width,
                               height: stage.height,
-                              spacing: 20,
-                              style: 'padding: 10px; background: #ffee88;' });
+                              style: 'padding: 10px;'
+                                     + 'spacing: 20px;'
+                                     + 'background: #ffee88;' });
 stage.add_actor(vbox);
 
 vbox.add(new St.Label({ text: "Hello World",
diff --git a/tests/interactive/box-layout.js b/tests/interactive/box-layout.js
index 2b8dda8..4454cd0 100644
--- a/tests/interactive/box-layout.js
+++ b/tests/interactive/box-layout.js
@@ -11,8 +11,8 @@ let stage = Clutter.Stage.get_default();
 let vbox = new St.BoxLayout({ vertical: true,
                               width: stage.width,
                               height: stage.height,
-                              spacing: 10,
-                              style: 'padding: 10px' });
+                              style: 'padding: 10px;'
+                                     + 'spacing: 10px;' });
 stage.add_actor(vbox);
 
 ////////////////////////////////////////////////////////////////////////////////
diff --git a/tests/interactive/inline-style.js b/tests/interactive/inline-style.js
index 3cac25c..fa23b1f 100644
--- a/tests/interactive/inline-style.js
+++ b/tests/interactive/inline-style.js
@@ -13,7 +13,7 @@ let vbox = new St.BoxLayout({ vertical: true,
                               height: stage.height });
 stage.add_actor(vbox);
 
-let hbox = new St.BoxLayout({ spacing: 12 });
+let hbox = new St.BoxLayout({ style: 'spacing: 12px;' });
 vbox.add(hbox);
 
 let text = new St.Label({ text: "Styled Text" });



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]