mirror of
https://github.com/brl/mutter.git
synced 2024-12-23 19:42:05 +00:00
[layout] Add initial implementation of LayoutManager
The LayoutManager class is an abstract proxy for the size requesition and size allocation process in ClutterActor. A ClutterLayoutManager sub-class must implement get_preferred_width(), get_preferred_height() and allocate(); a ClutterContainer using the LayoutManager API will then proxy the corresponding Actor virtual functions to the LayoutManager instance. This allows having a generic "blank" ClutterActor sub-class, implementing the ClutterContainer interface, which leaves only the layout management implementation to the application developers.
This commit is contained in:
parent
4f2bfc003a
commit
d6183e95e5
@ -78,6 +78,7 @@ source_h = \
|
||||
$(srcdir)/clutter-group.h \
|
||||
$(srcdir)/clutter-interval.h \
|
||||
$(srcdir)/clutter-keysyms.h \
|
||||
$(srcdir)/clutter-layout-manager.h \
|
||||
$(srcdir)/clutter-list-model.h \
|
||||
$(srcdir)/clutter-main.h \
|
||||
$(srcdir)/clutter-media.h \
|
||||
@ -142,6 +143,7 @@ source_c = \
|
||||
$(srcdir)/clutter-group.c \
|
||||
$(srcdir)/clutter-id-pool.c \
|
||||
$(srcdir)/clutter-interval.c \
|
||||
$(srcdir)/clutter-layout-manager.c \
|
||||
$(srcdir)/clutter-list-model.c \
|
||||
$(srcdir)/clutter-main.c \
|
||||
clutter-marshal.c \
|
||||
|
180
clutter/clutter-layout-manager.c
Normal file
180
clutter/clutter-layout-manager.c
Normal file
@ -0,0 +1,180 @@
|
||||
/**
|
||||
* SECTION:clutter-layout-manager
|
||||
* @short_description: Layout managers base class
|
||||
*
|
||||
* #ClutterLayoutManager is FIXME
|
||||
*
|
||||
* #ClutterLayoutManager is available since Clutter 1.2
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "clutter-debug.h"
|
||||
#include "clutter-layout-manager.h"
|
||||
#include "clutter-marshal.h"
|
||||
#include "clutter-private.h"
|
||||
|
||||
#define LAYOUT_MANAGER_WARN_NOT_IMPLEMENTED(m,method) G_STMT_START { \
|
||||
GObject *_obj = G_OBJECT (m); \
|
||||
g_warning ("Layout managers of type %s do not implement " \
|
||||
"the ClutterLayoutManager::%s method", \
|
||||
G_OBJECT_TYPE_NAME (_obj), \
|
||||
(method)); } G_STMT_END
|
||||
|
||||
G_DEFINE_ABSTRACT_TYPE (ClutterLayoutManager, clutter_layout_manager, G_TYPE_OBJECT);
|
||||
|
||||
static void
|
||||
layout_manager_real_get_preferred_width (ClutterLayoutManager *manager,
|
||||
ClutterContainer *container,
|
||||
gfloat for_height,
|
||||
gfloat *min_width_p,
|
||||
gfloat *nat_width_p)
|
||||
{
|
||||
LAYOUT_MANAGER_WARN_NOT_IMPLEMENTED (manager, "get_preferred_width");
|
||||
|
||||
if (min_width_p)
|
||||
*min_width_p = 0.0;
|
||||
|
||||
if (nat_width_p)
|
||||
*nat_width_p = 0.0;
|
||||
}
|
||||
|
||||
static void
|
||||
layout_manager_real_get_preferred_height (ClutterLayoutManager *manager,
|
||||
ClutterContainer *container,
|
||||
gfloat for_width,
|
||||
gfloat *min_height_p,
|
||||
gfloat *nat_height_p)
|
||||
{
|
||||
LAYOUT_MANAGER_WARN_NOT_IMPLEMENTED (manager, "get_preferred_height");
|
||||
|
||||
if (min_height_p)
|
||||
*min_height_p = 0.0;
|
||||
|
||||
if (nat_height_p)
|
||||
*nat_height_p = 0.0;
|
||||
}
|
||||
|
||||
static void
|
||||
layout_manager_real_allocate (ClutterLayoutManager *manager,
|
||||
ClutterContainer *container,
|
||||
const ClutterActorBox *allocation,
|
||||
ClutterAllocationFlags flags)
|
||||
{
|
||||
LAYOUT_MANAGER_WARN_NOT_IMPLEMENTED (manager, "allocate");
|
||||
}
|
||||
|
||||
static void
|
||||
clutter_layout_manager_class_init (ClutterLayoutManagerClass *klass)
|
||||
{
|
||||
klass->get_preferred_width = layout_manager_real_get_preferred_width;
|
||||
klass->get_preferred_height = layout_manager_real_get_preferred_height;
|
||||
klass->allocate = layout_manager_real_allocate;
|
||||
}
|
||||
|
||||
static void
|
||||
clutter_layout_manager_init (ClutterLayoutManager *manager)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* clutter_layout_manager_get_preferred_width:
|
||||
* @manager: a #ClutterLayoutManager
|
||||
* @container: the #ClutterContainer using @manager
|
||||
* @for_height: the height for which the width should be computed, or -1
|
||||
* @min_width_p: (out) (allow-none): return location for the minimum width
|
||||
* of the layout, or %NULL
|
||||
* @nat_width_p: (out) (allow-none): return location for the natural width
|
||||
* of the layout, or %NULL
|
||||
*
|
||||
* Computes the minimum and natural widths of the @container according
|
||||
* to @manager.
|
||||
*
|
||||
* See also clutter_actor_get_preferred_width()
|
||||
*
|
||||
* Since: 1.2
|
||||
*/
|
||||
void
|
||||
clutter_layout_manager_get_preferred_width (ClutterLayoutManager *manager,
|
||||
ClutterContainer *container,
|
||||
gfloat for_height,
|
||||
gfloat *min_width_p,
|
||||
gfloat *nat_width_p)
|
||||
{
|
||||
ClutterLayoutManagerClass *klass;
|
||||
|
||||
g_return_if_fail (CLUTTER_IS_LAYOUT_MANAGER (manager));
|
||||
g_return_if_fail (CLUTTER_IS_CONTAINER (container));
|
||||
|
||||
klass = CLUTTER_LAYOUT_MANAGER_GET_CLASS (manager);
|
||||
klass->get_preferred_width (manager, container, for_height,
|
||||
min_width_p,
|
||||
nat_width_p);
|
||||
}
|
||||
|
||||
/**
|
||||
* clutter_layout_manager_get_preferred_height:
|
||||
* @manager: a #ClutterLayoutManager
|
||||
* @container: the #ClutterContainer using @manager
|
||||
* @for_width: the width for which the height should be computed, or -1
|
||||
* @min_height_p: (out) (allow-none): return location for the minimum height
|
||||
* of the layout, or %NULL
|
||||
* @nat_height_p: (out) (allow-none): return location for the natural height
|
||||
* of the layout, or %NULL
|
||||
*
|
||||
* Computes the minimum and natural heights of the @container according
|
||||
* to @manager.
|
||||
*
|
||||
* See also clutter_actor_get_preferred_height()
|
||||
*
|
||||
* Since: 1.2
|
||||
*/
|
||||
void
|
||||
clutter_layout_manager_get_preferred_height (ClutterLayoutManager *manager,
|
||||
ClutterContainer *container,
|
||||
gfloat for_width,
|
||||
gfloat *min_height_p,
|
||||
gfloat *nat_height_p)
|
||||
{
|
||||
ClutterLayoutManagerClass *klass;
|
||||
|
||||
g_return_if_fail (CLUTTER_IS_LAYOUT_MANAGER (manager));
|
||||
g_return_if_fail (CLUTTER_IS_CONTAINER (container));
|
||||
|
||||
klass = CLUTTER_LAYOUT_MANAGER_GET_CLASS (manager);
|
||||
klass->get_preferred_height (manager, container, for_width,
|
||||
min_height_p,
|
||||
nat_height_p);
|
||||
}
|
||||
|
||||
/**
|
||||
* clutter_layout_manager_allocate:
|
||||
* @manager: a #ClutterLayoutManager
|
||||
* @container: the #ClutterContainer using @manager
|
||||
* @allocation: the #ClutterActorBox containing the allocated area
|
||||
* of @container
|
||||
* @flags: the allocation flags
|
||||
*
|
||||
* Allocates the children of @container given an area
|
||||
*
|
||||
* See also clutter_actor_allocate()
|
||||
*
|
||||
* Since: 1.2
|
||||
*/
|
||||
void
|
||||
clutter_layout_manager_allocate (ClutterLayoutManager *manager,
|
||||
ClutterContainer *container,
|
||||
const ClutterActorBox *allocation,
|
||||
ClutterAllocationFlags flags)
|
||||
{
|
||||
ClutterLayoutManagerClass *klass;
|
||||
|
||||
g_return_if_fail (CLUTTER_IS_LAYOUT_MANAGER (manager));
|
||||
g_return_if_fail (CLUTTER_IS_CONTAINER (container));
|
||||
g_return_if_fail (allocation != NULL);
|
||||
|
||||
klass = CLUTTER_LAYOUT_MANAGER_GET_CLASS (manager);
|
||||
klass->allocate (manager, container, allocation, flags);
|
||||
}
|
92
clutter/clutter-layout-manager.h
Normal file
92
clutter/clutter-layout-manager.h
Normal file
@ -0,0 +1,92 @@
|
||||
#if !defined(__CLUTTER_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
|
||||
#error "Only <clutter/clutter.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#ifndef __CLUTTER_LAYOUT_MANAGER_H__
|
||||
#define __CLUTTER_LAYOUT_MANAGER_H__
|
||||
|
||||
#include <clutter/clutter-actor.h>
|
||||
#include <clutter/clutter-container.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define CLUTTER_TYPE_LAYOUT_MANAGER (clutter_layout_manager_get_type ())
|
||||
#define CLUTTER_LAYOUT_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_LAYOUT_MANAGER, ClutterLayoutManager))
|
||||
#define CLUTTER_IS_LAYOUT_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_LAYOUT_MANAGER))
|
||||
#define CLUTTER_LAYOUT_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CLUTTER_TYPE_LAYOUT_MANAGER, ClutterLayoutManagerClass))
|
||||
#define CLUTTER_IS_LAYOUT_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CLUTTER_TYPE_LAYOUT_MANAGER))
|
||||
#define CLUTTER_LAYOUT_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CLUTTER_TYPE_LAYOUT_MANAGER, ClutterLayoutManagerClass))
|
||||
|
||||
typedef struct _ClutterLayoutManager ClutterLayoutManager;
|
||||
typedef struct _ClutterLayoutManagerClass ClutterLayoutManagerClass;
|
||||
|
||||
/**
|
||||
* ClutterLayoutManager:
|
||||
*
|
||||
* The #ClutterLayoutManager structure contains only private data
|
||||
* and should be accessed using the provided API
|
||||
*
|
||||
* Since: 1.2
|
||||
*/
|
||||
struct _ClutterLayoutManager
|
||||
{
|
||||
GObject parent_instance;
|
||||
};
|
||||
|
||||
/**
|
||||
* ClutterLayoutManagerClass:
|
||||
*
|
||||
* The #ClutterLayoutManagerClass structure contains only private
|
||||
* data and should be accessed using the provided API
|
||||
*
|
||||
* Since: 1.2
|
||||
*/
|
||||
struct _ClutterLayoutManagerClass
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
|
||||
void (* get_preferred_width) (ClutterLayoutManager *manager,
|
||||
ClutterContainer *container,
|
||||
gfloat for_height,
|
||||
gfloat *minimum_width_p,
|
||||
gfloat *natural_width_p);
|
||||
void (* get_preferred_height) (ClutterLayoutManager *manager,
|
||||
ClutterContainer *container,
|
||||
gfloat for_width,
|
||||
gfloat *minimum_height_p,
|
||||
gfloat *natural_height_p);
|
||||
void (* allocate) (ClutterLayoutManager *manager,
|
||||
ClutterContainer *container,
|
||||
const ClutterActorBox *allocation,
|
||||
ClutterAllocationFlags flags);
|
||||
|
||||
void (* _clutter_padding_1) (void);
|
||||
void (* _clutter_padding_2) (void);
|
||||
void (* _clutter_padding_3) (void);
|
||||
void (* _clutter_padding_4) (void);
|
||||
void (* _clutter_padding_5) (void);
|
||||
void (* _clutter_padding_6) (void);
|
||||
void (* _clutter_padding_7) (void);
|
||||
void (* _clutter_padding_8) (void);
|
||||
};
|
||||
|
||||
GType clutter_layout_manager_get_type (void) G_GNUC_CONST;
|
||||
|
||||
void clutter_layout_manager_get_preferred_width (ClutterLayoutManager *manager,
|
||||
ClutterContainer *container,
|
||||
gfloat for_height,
|
||||
gfloat *min_width_p,
|
||||
gfloat *nat_width_p);
|
||||
void clutter_layout_manager_get_preferred_height (ClutterLayoutManager *manager,
|
||||
ClutterContainer *container,
|
||||
gfloat for_width,
|
||||
gfloat *min_height_p,
|
||||
gfloat *nat_height_p);
|
||||
void clutter_layout_manager_allocate (ClutterLayoutManager *manager,
|
||||
ClutterContainer *container,
|
||||
const ClutterActorBox *allocation,
|
||||
ClutterAllocationFlags flags);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __CLUTTER_LAYOUT_MANAGER_H__ */
|
@ -54,6 +54,7 @@
|
||||
#include "clutter-group.h"
|
||||
#include "clutter-interval.h"
|
||||
#include "clutter-keysyms.h"
|
||||
#include "clutter-layout-manager.h"
|
||||
#include "clutter-list-model.h"
|
||||
#include "clutter-main.h"
|
||||
#include "clutter-media.h"
|
||||
|
Loading…
Reference in New Issue
Block a user