<commit_before>/*
 * Clutter.
 *
 * An OpenGL based 'interactive canvas' library.
 *
 * Copyright (C) 2009,2010  Intel Corporation.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * SECTION:clutter-box
 * @short_description: A Generic layout container
 *
 * #ClutterBox is a #ClutterActor sub-class implementing the #ClutterContainer
 * interface. A Box delegates the whole size requisition and size allocation to
 * a #ClutterLayoutManager instance.
 *
 * <example id="example-clutter-box">
 *   <title>Using ClutterBox</title>
 *   <para>The following code shows how to create a #ClutterBox with
 *   a #ClutterLayoutManager sub-class, and how to add children to
 *   it via clutter_box_pack().</para>
 *   <programlisting>
 *  ClutterActor *box;
 *  ClutterLayoutManager *layout;
 *
 *  /&ast; Create the layout manager first &ast;/
 *  layout = clutter_box_layout_new ();
 *  clutter_box_layout_set_homogeneous (CLUTTER_BOX_LAYOUT (layout), TRUE);
 *  clutter_box_layout_set_spacing (CLUTTER_BOX_LAYOUT (layout), 12);
 *
 *  /&ast; Then create the ClutterBox actor. The Box will take
 *   &ast; ownership of the ClutterLayoutManager instance by sinking
 *   &ast; its floating reference
 *   &ast;/
 *  box = clutter_box_new (layout);
 *
 *  /&ast; Now add children to the Box using the variadic arguments
 *   &ast; function clutter_box_pack() to set layout properties
 *   &ast;/
 *  clutter_box_pack (CLUTTER_BOX (box), actor,
 *                    "x-align", CLUTTER_BOX_ALIGNMENT_CENTER,
 *                    "y-align", CLUTTER_BOX_ALIGNMENT_END,
 *                    "expand", TRUE,
 *                    NULL);
 *   </programlisting>
 * </example>
 *
 * #ClutterBox<!-- -->'s clutter_box_pack() wraps the generic
 * clutter_container_add_actor() function, but it also allows setting
 * layout properties while adding the new child to the box.
 *
 * #ClutterBox is available since Clutter 1.2
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <glib-object.h>
#include <gobject/gvaluecollector.h>

#include "clutter-box.h"
#include "clutter-debug.h"
#include "clutter-enum-types.h"
#include "clutter-marshal.h"
#include "clutter-private.h"

#define CLUTTER_BOX_GET_PRIVATE(obj)    (G_TYPE_INSTANCE_GET_PRIVATE ((obj), CLUTTER_TYPE_BOX, ClutterBoxPrivate))

struct _ClutterBoxPrivate
{
  ClutterLayoutManager *manager;

  GList *children;

  guint changed_id;

  ClutterColor color;
  guint color_set : 1;
};

enum
{
  PROP_0,

  PROP_LAYOUT_MANAGER,
  PROP_COLOR,
  PROP_COLOR_SET
};

static const ClutterColor default_box_color = { 255, 255, 255, 255 };

static void clutter_container_iface_init (ClutterContainerIface *iface);

G_DEFINE_TYPE_WITH_CODE (ClutterBox, clutter_box, CLUTTER_TYPE_ACTOR,
                         G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_CONTAINER,
                                                clutter_container_iface_init));

static gint
sort_by_depth (gconstpointer a,
               gconstpointer b)
{
  gfloat depth_a = clutter_actor_get_depth ((ClutterActor *) a);
  gfloat depth_b = clutter_actor_get_depth ((ClutterActor *) b);

  if (depth_a < depth_b)
    return -1;

  if (depth_a > depth_b)
    return 1;

  return 0;
}

static void
clutter_box_real_add (ClutterContainer *container,
                      ClutterActor     *actor)
{
  ClutterBoxPrivate *priv = CLUTTER_BOX (container)->priv;

  g_object_ref (actor);

  priv->children = g_list_insert_sorted (priv->children,
                                         actor,
                                         sort_by_depth);

  clutter_actor_set_parent (actor, CLUTTER_ACTOR (container));

  clutter_actor_queue_relayout (actor);

  g_signal_emit_by_name (container, "actor-added", actor);

  g_object_unref (actor);
}
<commit_msg>box: Tweak the depth sorting function<commit_after>/*
 * Clutter.
 *
 * An OpenGL based 'interactive canvas' library.
 *
 * Copyright (C) 2009,2010  Intel Corporation.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * SECTION:clutter-box
 * @short_description: A Generic layout container
 *
 * #ClutterBox is a #ClutterActor sub-class implementing the #ClutterContainer
 * interface. A Box delegates the whole size requisition and size allocation to
 * a #ClutterLayoutManager instance.
 *
 * <example id="example-clutter-box">
 *   <title>Using ClutterBox</title>
 *   <para>The following code shows how to create a #ClutterBox with
 *   a #ClutterLayoutManager sub-class, and how to add children to
 *   it via clutter_box_pack().</para>
 *   <programlisting>
 *  ClutterActor *box;
 *  ClutterLayoutManager *layout;
 *
 *  /&ast; Create the layout manager first &ast;/
 *  layout = clutter_box_layout_new ();
 *  clutter_box_layout_set_homogeneous (CLUTTER_BOX_LAYOUT (layout), TRUE);
 *  clutter_box_layout_set_spacing (CLUTTER_BOX_LAYOUT (layout), 12);
 *
 *  /&ast; Then create the ClutterBox actor. The Box will take
 *   &ast; ownership of the ClutterLayoutManager instance by sinking
 *   &ast; its floating reference
 *   &ast;/
 *  box = clutter_box_new (layout);
 *
 *  /&ast; Now add children to the Box using the variadic arguments
 *   &ast; function clutter_box_pack() to set layout properties
 *   &ast;/
 *  clutter_box_pack (CLUTTER_BOX (box), actor,
 *                    "x-align", CLUTTER_BOX_ALIGNMENT_CENTER,
 *                    "y-align", CLUTTER_BOX_ALIGNMENT_END,
 *                    "expand", TRUE,
 *                    NULL);
 *   </programlisting>
 * </example>
 *
 * #ClutterBox<!-- -->'s clutter_box_pack() wraps the generic
 * clutter_container_add_actor() function, but it also allows setting
 * layout properties while adding the new child to the box.
 *
 * #ClutterBox is available since Clutter 1.2
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <glib-object.h>
#include <gobject/gvaluecollector.h>

#include "clutter-box.h"
#include "clutter-debug.h"
#include "clutter-enum-types.h"
#include "clutter-marshal.h"
#include "clutter-private.h"

#define CLUTTER_BOX_GET_PRIVATE(obj)    (G_TYPE_INSTANCE_GET_PRIVATE ((obj), CLUTTER_TYPE_BOX, ClutterBoxPrivate))

struct _ClutterBoxPrivate
{
  ClutterLayoutManager *manager;

  GList *children;

  guint changed_id;

  ClutterColor color;
  guint color_set : 1;
};

enum
{
  PROP_0,

  PROP_LAYOUT_MANAGER,
  PROP_COLOR,
  PROP_COLOR_SET
};

static const ClutterColor default_box_color = { 255, 255, 255, 255 };

static void clutter_container_iface_init (ClutterContainerIface *iface);

G_DEFINE_TYPE_WITH_CODE (ClutterBox, clutter_box, CLUTTER_TYPE_ACTOR,
                         G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_CONTAINER,
                                                clutter_container_iface_init));

static gint
sort_by_depth (gconstpointer a,
               gconstpointer b)
{
  gfloat depth_a = clutter_actor_get_depth ((ClutterActor *) a);
  gfloat depth_b = clutter_actor_get_depth ((ClutterActor *) b);

  if (depth_a < depth_b)
    return -1;

  if (depth_a >= depth_b)
    return 1;

  return 0;
}

static void
clutter_box_real_add (ClutterContainer *container,
                      ClutterActor     *actor)
{
  ClutterBoxPrivate *priv = CLUTTER_BOX (container)->priv;

  g_object_ref (actor);

  priv->children = g_list_insert_sorted (priv->children,
                                         actor,
                                         sort_by_depth);

  clutter_actor_set_parent (actor, CLUTTER_ACTOR (container));

  clutter_actor_queue_relayout (actor);

  g_signal_emit_by_name (container, "actor-added", actor);

  g_object_unref (actor);
}

{'fraction_non_alphanumeric': 0.0917890900808564, 'fraction_numerical': 0.006832934745473181, 'mean_word_length': 3.3691542288557215, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3998165', 'n_tokens_mistral': 2821, 'n_tokens_neox': 2713, 'n_words': 807}