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
This commit is contained in:
Owen W. Taylor 2009-09-29 23:03:41 -04:00
parent 3bbdc1e1e1
commit 1283f0b160
5 changed files with 25 additions and 69 deletions

View File

@ -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),
@ -1072,11 +1063,28 @@ st_box_layout_pick (ClutterActor *actor,
cogl_clip_pop ();
}
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;
}

View File

@ -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 */

View File

@ -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",

View File

@ -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);
////////////////////////////////////////////////////////////////////////////////

View File

@ -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" });