Add default padding to ClutterBox

To avoid using a ClutterPadding each time you add an actor to a ClutterBox
when you want the same padding around each child, you can now set the
default padding. The API is pixel-based, since it's a commodity function,
and will affect only clutter_box_pack_defaults().
This commit is contained in:
Emmanuele Bassi 2007-08-06 19:37:15 +00:00
parent a67be7e88f
commit 5c8d18e619
2 changed files with 98 additions and 25 deletions

View File

@ -369,12 +369,12 @@ void
clutter_box_pack_defaults (ClutterBox *box,
ClutterActor *actor)
{
ClutterPadding padding = { 0, };
g_return_if_fail (CLUTTER_IS_BOX (box));
g_return_if_fail (CLUTTER_IS_ACTOR (actor));
clutter_box_pack (box, actor, CLUTTER_PACK_START, &padding);
clutter_box_pack (box, actor,
CLUTTER_PACK_START,
&box->default_padding);
}
/**
@ -609,6 +609,66 @@ clutter_box_remove_all (ClutterBox *box)
}
}
/**
* clutter_box_set_default_padding:
* @box: a #ClutterBox
* @padding_top: top padding, in pixels
* @padding_right: right padding, in pixels
* @padding_bottom: bottom padding, in pixels
* @padding_left: left padding, in pixels
*
* Sets the default padding for children, which will be used when
* packing actors with clutter_box_pack_defaults(). The padding is
* given in pixels.
*
* Since: 0.4
*/
void
clutter_box_set_default_padding (ClutterBox *box,
gint padding_top,
gint padding_right,
gint padding_bottom,
gint padding_left)
{
g_return_if_fail (CLUTTER_IS_BOX (box));
box->default_padding.top = CLUTTER_UNITS_FROM_INT (padding_top);
box->default_padding.right = CLUTTER_UNITS_FROM_INT (padding_right);
box->default_padding.bottom = CLUTTER_UNITS_FROM_INT (padding_bottom);
box->default_padding.left = CLUTTER_UNITS_FROM_INT (padding_left);
}
/**
* clutter_box_get_default_padding:
* @box: a #ClutterBox
* @padding_top: return location for the top padding, or %NULL
* @padding_right: return location for the right padding, or %NULL
* @padding_bottom: return location for the bottom padding, or %NULL
* @padding_left: return location for the left padding, or %NULL
*
* Gets the default padding set with clutter_box_set_default_padding().
*
* Since: 0.4
*/
void
clutter_box_get_default_padding (ClutterBox *box,
gint *padding_top,
gint *padding_right,
gint *padding_bottom,
gint *padding_left)
{
g_return_if_fail (CLUTTER_IS_BOX (box));
if (padding_top)
*padding_top = CLUTTER_UNITS_TO_INT (box->default_padding.top);
if (padding_right)
*padding_right = CLUTTER_UNITS_TO_INT (box->default_padding.right);
if (padding_bottom)
*padding_bottom = CLUTTER_UNITS_TO_INT (box->default_padding.bottom);
if (padding_left)
*padding_left = CLUTTER_UNITS_TO_INT (box->default_padding.left);
}
/*
* Boxed types
*/

View File

@ -53,6 +53,9 @@ struct _ClutterBox
/* Margin between the inner border of the box and the children */
ClutterMargin margin;
/* Default padding for the children */
ClutterPadding default_padding;
};
struct _ClutterBoxClass
@ -95,28 +98,38 @@ struct _ClutterBoxChild
ClutterPadding padding;
};
GType clutter_box_get_type (void) G_GNUC_CONST;
void clutter_box_set_color (ClutterBox *box,
const ClutterColor *color);
void clutter_box_get_color (ClutterBox *box,
ClutterColor *color);
void clutter_box_set_margin (ClutterBox *box,
const ClutterMargin *margin);
void clutter_box_get_margin (ClutterBox *box,
ClutterMargin *margin);
void clutter_box_pack (ClutterBox *box,
ClutterActor *actor,
ClutterPackType pack_type,
const ClutterPadding *padding);
void clutter_box_pack_defaults (ClutterBox *box,
ClutterActor *actor);
void clutter_box_remove_all (ClutterBox *box);
gboolean clutter_box_query_child (ClutterBox *box,
ClutterActor *actor,
ClutterBoxChild *child);
gboolean clutter_box_query_nth_child (ClutterBox *box,
gint index_,
ClutterBoxChild *child);
GType clutter_box_get_type (void) G_GNUC_CONST;
void clutter_box_set_color (ClutterBox *box,
const ClutterColor *color);
void clutter_box_get_color (ClutterBox *box,
ClutterColor *color);
void clutter_box_set_margin (ClutterBox *box,
const ClutterMargin *margin);
void clutter_box_get_margin (ClutterBox *box,
ClutterMargin *margin);
void clutter_box_set_default_padding (ClutterBox *box,
gint padding_top,
gint padding_right,
gint padding_bottom,
gint padding_left);
void clutter_box_get_default_padding (ClutterBox *box,
gint *padding_top,
gint *padding_right,
gint *padding_bottom,
gint *padding_left);
void clutter_box_pack (ClutterBox *box,
ClutterActor *actor,
ClutterPackType pack_type,
const ClutterPadding *padding);
void clutter_box_pack_defaults (ClutterBox *box,
ClutterActor *actor);
void clutter_box_remove_all (ClutterBox *box);
gboolean clutter_box_query_child (ClutterBox *box,
ClutterActor *actor,
ClutterBoxChild *child);
gboolean clutter_box_query_nth_child (ClutterBox *box,
gint index_,
ClutterBoxChild *child);
G_END_DECLS