From 238fd52c4b0660ac61b3ae125f3eef8f71b0f6b0 Mon Sep 17 00:00:00 2001 From: Elliot Smith Date: Fri, 28 Jan 2011 17:09:24 +0000 Subject: [PATCH] docs: Change order of functions in example to match docs Moved the functions around in the C code file, to match the order Clutter uses them, and the order they are explained in the recipe. --- doc/cookbook/examples/cb-button.c | 99 +++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 55 deletions(-) diff --git a/doc/cookbook/examples/cb-button.c b/doc/cookbook/examples/cb-button.c index 20ee6e5..49543b6 100644 --- a/doc/cookbook/examples/cb-button.c +++ b/doc/cookbook/examples/cb-button.c @@ -145,57 +145,19 @@ cb_button_get_property (GObject *gobject, /* ClutterActor implementation * - * we only implement allocate(), paint(), get_preferred_height() - * and get_preferred_width(), as this is the minimum - * we can get away with + * we only implement get_preferred_height(), get_preferred_width(), + * allocate(), and paint(), as this is the minimum we can get away with */ -/* use the actor's allocation for the ClutterBox */ -static void -cb_button_allocate (ClutterActor *actor, - const ClutterActorBox *box, - ClutterAllocationFlags flags) -{ - CbButtonPrivate *priv = CB_BUTTON (actor)->priv; - ClutterActorBox child_box = { 0, }; - - /* set the allocation for the whole button */ - CLUTTER_ACTOR_CLASS (cb_button_parent_class)->allocate (actor, box, flags); - - /* make the child (the ClutterBox) fill the parent; - * note that this allocation box is relative to the - * coordinates of the whole button actor, so we can't just - * use the box passed into this function; instead, it - * is adjusted to span the whole of the actor, from its - * top-left corner (0,0) to its bottom-right corner - * (width,height) - */ - child_box.x1 = 0.0; - child_box.y1 = 0.0; - child_box.x2 = clutter_actor_box_get_width (box); - child_box.y2 = clutter_actor_box_get_height (box); - - clutter_actor_allocate (priv->child, &child_box, flags); -} - -/* paint function implementation: just calls paint() on the ClutterBox */ -static void -cb_button_paint (ClutterActor *actor) -{ - CbButtonPrivate *priv = CB_BUTTON (actor)->priv; - - clutter_actor_paint (priv->child); -} - -/* get_preferred_height defers to the internal ClutterBox - * but adds 20px padding around it; - * min_height_p is the minimum height the actor should occupy - * to be useful; natural_height_p is the height the actor +/* get_preferred_height and get_preferred_width defer to the + * internal ClutterBox, adding 20px padding on each axis; + * min_*_p is the minimum height or width the actor should occupy + * to be useful; natural_*_p is the height or width the actor * would occupy if not constrained * * note that if we required explicit sizing for CbButtons * (i.e. a developer must set their height and width), - * we wouldn't need to implement this function + * we wouldn't need to implement these functions */ static void cb_button_get_preferred_height (ClutterActor *self, @@ -214,16 +176,6 @@ cb_button_get_preferred_height (ClutterActor *self, *natural_height_p += 20.0; } -/* get_preferred_width defers to the internal ClutterBox - * but adds 20px padding around it; - * min_width_p is the minimum width the actor should occupy - * to be useful; natural_width_p is the width the actor - * would occupy if not constrained - * - * note that if we required explicit sizing for CbButtons - * (i.e. a developer must set their height and width), - * we wouldn't need to implement this function - */ static void cb_button_get_preferred_width (ClutterActor *self, gfloat for_height, @@ -241,6 +193,43 @@ cb_button_get_preferred_width (ClutterActor *self, *natural_width_p += 20.0; } +/* use the actor's allocation for the ClutterBox */ +static void +cb_button_allocate (ClutterActor *actor, + const ClutterActorBox *box, + ClutterAllocationFlags flags) +{ + CbButtonPrivate *priv = CB_BUTTON (actor)->priv; + ClutterActorBox child_box = { 0, }; + + /* set the allocation for the whole button */ + CLUTTER_ACTOR_CLASS (cb_button_parent_class)->allocate (actor, box, flags); + + /* make the child (the ClutterBox) fill the parent; + * note that this allocation box is relative to the + * coordinates of the whole button actor, so we can't just + * use the box passed into this function; instead, it + * is adjusted to span the whole of the actor, from its + * top-left corner (0,0) to its bottom-right corner + * (width,height) + */ + child_box.x1 = 0.0; + child_box.y1 = 0.0; + child_box.x2 = clutter_actor_box_get_width (box); + child_box.y2 = clutter_actor_box_get_height (box); + + clutter_actor_allocate (priv->child, &child_box, flags); +} + +/* paint function implementation: just calls paint() on the ClutterBox */ +static void +cb_button_paint (ClutterActor *actor) +{ + CbButtonPrivate *priv = CB_BUTTON (actor)->priv; + + clutter_actor_paint (priv->child); +} + /* proxy ClickAction signals so they become signals from the actor */ static void cb_button_clicked (ClutterClickAction *action, -- 2.7.4