summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatt <mattdangerw@gmail.com>2013-05-14 17:22:00 -0700
committerMatt Watson <mattdangerw@gmail.com>2013-05-29 14:38:07 -0700
commit3ea04fe6d3253f1ca698a313e24eb3d5aeac3948 (patch)
tree0532b9072832cbb922643fbb68a0dcbc9e700140
parentc013139ca14f93b420dbc819103367e1596c0c0e (diff)
Added transition type and duration props to page manager.
These just wrap the functionality of GtkStack. Added some dropdowns in the app-window.js to try the different transition options and some simple c tests. [endlessm/eos-sdk#61]
-rw-r--r--endless/eospagemanager.c166
-rw-r--r--endless/eospagemanager.h88
-rw-r--r--test/smoke-tests/app-window.js51
-rw-r--r--test/test-page-manager.c55
4 files changed, 324 insertions, 36 deletions
diff --git a/endless/eospagemanager.c b/endless/eospagemanager.c
index 3919b5b..d44dbb8 100644
--- a/endless/eospagemanager.c
+++ b/endless/eospagemanager.c
@@ -109,11 +109,32 @@ struct _EosPageManagerPrivate
EosPageManagerPageInfo *visible_page_info;
};
+GType
+eos_page_manager_transition_type_get_type (void)
+{
+ static GType etype = 0;
+ if (G_UNLIKELY(etype == 0)) {
+ static const GEnumValue values[] = {
+ { EOS_PAGE_MANAGER_TRANSITION_TYPE_NONE, "EOS_PAGE_MANAGER_TRANSITION_TYPE_NONE", "none" },
+ { EOS_PAGE_MANAGER_TRANSITION_TYPE_CROSSFADE, "EOS_PAGE_MANAGER_TRANSITION_TYPE_CROSSFADE", "crossfade" },
+ { EOS_PAGE_MANAGER_TRANSITION_TYPE_SLIDE_RIGHT, "EOS_PAGE_MANAGER_TRANSITION_TYPE_SLIDE_RIGHT", "slide_right" },
+ { EOS_PAGE_MANAGER_TRANSITION_TYPE_SLIDE_LEFT, "EOS_PAGE_MANAGER_TRANSITION_TYPE_SLIDE_LEFT", "slide_left" },
+ { EOS_PAGE_MANAGER_TRANSITION_TYPE_SLIDE_UP, "EOS_PAGE_MANAGER_TRANSITION_TYPE_SLIDE_UP", "slide_up" },
+ { EOS_PAGE_MANAGER_TRANSITION_TYPE_SLIDE_DOWN, "EOS_PAGE_MANAGER_TRANSITION_TYPE_SLIDE_DOWN", "slide_down" },
+ { 0, NULL, NULL }
+ };
+ etype = g_enum_register_static (g_intern_static_string ("EosPageManagerTransition"), values);
+ }
+ return etype;
+}
+
enum
{
PROP_0,
PROP_VISIBLE_PAGE,
PROP_VISIBLE_PAGE_NAME,
+ PROP_TRANSITION_DURATION,
+ PROP_TRANSITION_TYPE,
NPROPS
};
@@ -244,6 +265,14 @@ eos_page_manager_get_property (GObject *object,
g_value_set_string (value, eos_page_manager_get_visible_page_name (self));
break;
+ case PROP_TRANSITION_DURATION:
+ g_value_set_uint (value, eos_page_manager_get_transition_duration (self));
+ break;
+
+ case PROP_TRANSITION_TYPE:
+ g_value_set_enum (value, eos_page_manager_get_transition_type (self));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
@@ -267,6 +296,14 @@ eos_page_manager_set_property (GObject *object,
eos_page_manager_set_visible_page_name (self, g_value_get_string (value));
break;
+ case PROP_TRANSITION_DURATION:
+ eos_page_manager_set_transition_duration (self, g_value_get_uint (value));
+ break;
+
+ case PROP_TRANSITION_TYPE:
+ eos_page_manager_set_transition_type (self, g_value_get_enum (value));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
@@ -587,6 +624,34 @@ eos_page_manager_class_init (EosPageManagerClass *klass)
"",
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+ /**
+ * EosPageManager:transition-duration:
+ *
+ * The time it will take to animate between pages in the page managers, in
+ * milliseconds.
+ */
+ eos_page_manager_props[PROP_TRANSITION_DURATION] =
+ g_param_spec_uint ("transition-duration", "Transition duration",
+ "The animation duration, in milliseconds",
+ 0, G_MAXUINT,
+ 200,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
+
+
+ /**
+ * EosPageManager:transition-type:
+ *
+ * The type of animation to use when switching between pages in the page
+ * manager. The pages can crossfade from one to the next, or slide in from
+ * any direction.
+ */
+ eos_page_manager_props[PROP_TRANSITION_TYPE] =
+ g_param_spec_enum ("transition-type", "Transition type",
+ "The type of animation used to transition",
+ EOS_TYPE_PAGE_MANAGER_TRANSITION_TYPE,
+ EOS_PAGE_MANAGER_TRANSITION_TYPE_NONE,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
+
g_object_class_install_properties (object_class, NPROPS,
eos_page_manager_props);
@@ -669,8 +734,6 @@ eos_page_manager_init (EosPageManager *self)
/* TODO replace with GtkStack */
self->priv->stack = p_stack_new ();
- p_stack_set_transition_type (P_STACK (self->priv->stack),
- P_STACK_TRANSITION_TYPE_CROSSFADE);
gtk_widget_set_parent (self->priv->stack, self_widget);
}
@@ -1081,3 +1144,102 @@ eos_page_manager_remove_page_by_name (EosPageManager *self,
assert_internal_state (self);
}
+
+/**
+ * eos_page_manager_get_transition_duration:
+ * @self: the page manager
+ *
+ * Gets the animation duration of page transitions, in milliseconds. See
+ * #EosPageManager:transition-duration for more information.
+ *
+ * Returns: the current transition time of the page manager.
+ */
+guint
+eos_page_manager_get_transition_duration (EosPageManager *self)
+{
+ g_return_val_if_fail (EOS_IS_PAGE_MANAGER (self), 0);
+
+ return p_stack_get_transition_duration (P_STACK (self->priv->stack));
+}
+
+/**
+ * eos_page_manager_set_transition_duration:
+ * @self: the page manager
+ * @duration: the duration of page transitions, in milliseconds
+ *
+ * Sets the animation duration of page transitions, in milliseconds. See
+ * #EosPageManager:transition-duration for more information.
+ */
+void
+eos_page_manager_set_transition_duration (EosPageManager *self,
+ guint duration)
+{
+ g_return_if_fail (EOS_IS_PAGE_MANAGER (self));
+
+ p_stack_set_transition_duration (P_STACK (self->priv->stack), duration);
+ g_object_notify (G_OBJECT (self), "transition-duration");
+}
+
+/**
+ * eos_page_manager_get_transition_type:
+ * @self: the page manager
+ *
+ * Gets the animation type of page transitions. See #EosPageManager
+ * :transition-type for more information.
+ *
+ * Returns: the current transition type of the page manager.
+ */
+EosPageManagerTransitionType
+eos_page_manager_get_transition_type (EosPageManager *self)
+{
+ g_return_val_if_fail (EOS_IS_PAGE_MANAGER (self), EOS_PAGE_MANAGER_TRANSITION_TYPE_NONE);
+
+ return p_stack_get_transition_type (P_STACK (self->priv->stack));
+}
+
+
+/**
+ * eos_page_manager_set_transition_type:
+ * @self: the page manager
+ * @transition: the type of page transitions
+ *
+ * Sets the animation type of page transitions. See #EosPageManager
+ * :transition-type for more information.
+ */
+void
+eos_page_manager_set_transition_type (EosPageManager *self,
+ EosPageManagerTransitionType transition)
+{
+ g_return_if_fail (EOS_IS_PAGE_MANAGER (self));
+
+ // WOO useless switch statement! Should I just cast, cause I know they're the
+ // same? This seems more futureproof.
+ PStackTransitionType type;
+ switch (transition)
+ {
+ case EOS_PAGE_MANAGER_TRANSITION_TYPE_NONE:
+ type = P_STACK_TRANSITION_TYPE_NONE;
+ break;
+ case EOS_PAGE_MANAGER_TRANSITION_TYPE_CROSSFADE:
+ type = P_STACK_TRANSITION_TYPE_CROSSFADE;
+ break;
+ case EOS_PAGE_MANAGER_TRANSITION_TYPE_SLIDE_RIGHT:
+ type = P_STACK_TRANSITION_TYPE_SLIDE_RIGHT;
+ break;
+ case EOS_PAGE_MANAGER_TRANSITION_TYPE_SLIDE_LEFT:
+ type = P_STACK_TRANSITION_TYPE_SLIDE_LEFT;
+ break;
+ case EOS_PAGE_MANAGER_TRANSITION_TYPE_SLIDE_UP:
+ type = P_STACK_TRANSITION_TYPE_SLIDE_UP;
+ break;
+ case EOS_PAGE_MANAGER_TRANSITION_TYPE_SLIDE_DOWN:
+ type = P_STACK_TRANSITION_TYPE_SLIDE_DOWN;
+ break;
+ default:
+ type = P_STACK_TRANSITION_TYPE_NONE;
+ break;
+ }
+ p_stack_set_transition_type (P_STACK (self->priv->stack), type);
+
+ g_object_notify (G_OBJECT (self), "transition-type");
+}
diff --git a/endless/eospagemanager.h b/endless/eospagemanager.h
index a05800a..4512988 100644
--- a/endless/eospagemanager.h
+++ b/endless/eospagemanager.h
@@ -39,6 +39,17 @@ typedef struct _EosPageManager EosPageManager;
typedef struct _EosPageManagerClass EosPageManagerClass;
typedef struct _EosPageManagerPrivate EosPageManagerPrivate;
+#define EOS_TYPE_PAGE_MANAGER_TRANSITION_TYPE (eos_page_manager_transition_type_get_type ())
+
+typedef enum {
+ EOS_PAGE_MANAGER_TRANSITION_TYPE_NONE,
+ EOS_PAGE_MANAGER_TRANSITION_TYPE_CROSSFADE,
+ EOS_PAGE_MANAGER_TRANSITION_TYPE_SLIDE_RIGHT,
+ EOS_PAGE_MANAGER_TRANSITION_TYPE_SLIDE_LEFT,
+ EOS_PAGE_MANAGER_TRANSITION_TYPE_SLIDE_UP,
+ EOS_PAGE_MANAGER_TRANSITION_TYPE_SLIDE_DOWN
+} EosPageManagerTransitionType;
+
/**
* EosPageManager:
*
@@ -60,64 +71,81 @@ struct _EosPageManagerClass
};
EOS_SDK_ALL_API_VERSIONS
-GType eos_page_manager_get_type (void) G_GNUC_CONST;
+GType eos_page_manager_get_type (void) G_GNUC_CONST;
+
+EOS_SDK_ALL_API_VERSIONS
+GType eos_page_manager_transition_type_get_type (void) G_GNUC_CONST;
+
+EOS_SDK_ALL_API_VERSIONS
+GtkWidget *eos_page_manager_new (void);
+
+EOS_SDK_ALL_API_VERSIONS
+GtkWidget *eos_page_manager_get_visible_page (EosPageManager *self);
+
+EOS_SDK_ALL_API_VERSIONS
+void eos_page_manager_set_visible_page (EosPageManager *self,
+ GtkWidget *page);
+
+EOS_SDK_ALL_API_VERSIONS
+const gchar *eos_page_manager_get_visible_page_name (EosPageManager *self);
EOS_SDK_ALL_API_VERSIONS
-GtkWidget *eos_page_manager_new (void);
+void eos_page_manager_set_visible_page_name (EosPageManager *self,
+ const gchar *page_name);
EOS_SDK_ALL_API_VERSIONS
-GtkWidget *eos_page_manager_get_visible_page (EosPageManager *self);
+const gchar *eos_page_manager_get_page_name (EosPageManager *self,
+ GtkWidget *page);
EOS_SDK_ALL_API_VERSIONS
-void eos_page_manager_set_visible_page (EosPageManager *self,
- GtkWidget *page);
+void eos_page_manager_set_page_name (EosPageManager *self,
+ GtkWidget *page,
+ const gchar *name);
EOS_SDK_ALL_API_VERSIONS
-const gchar *eos_page_manager_get_visible_page_name (EosPageManager *self);
+gboolean eos_page_manager_get_page_actions (EosPageManager *self,
+ GtkWidget *page);
EOS_SDK_ALL_API_VERSIONS
-void eos_page_manager_set_visible_page_name (EosPageManager *self,
- const gchar *page_name);
+void eos_page_manager_set_page_actions (EosPageManager *self,
+ GtkWidget *page,
+ gboolean actions_visible);
EOS_SDK_ALL_API_VERSIONS
-const gchar *eos_page_manager_get_page_name (EosPageManager *self,
- GtkWidget *page);
+GtkWidget *eos_page_manager_get_page_custom_toolbox_widget (EosPageManager *self,
+ GtkWidget *page);
EOS_SDK_ALL_API_VERSIONS
-void eos_page_manager_set_page_name (EosPageManager *self,
- GtkWidget *page,
- const gchar *name);
+void eos_page_manager_set_page_custom_toolbox_widget (EosPageManager *self,
+ GtkWidget *page,
+ GtkWidget *custom_toolbox_widget);
EOS_SDK_ALL_API_VERSIONS
-gboolean eos_page_manager_get_page_actions (EosPageManager *self,
- GtkWidget *page);
+void eos_page_manager_set_transition_duration (EosPageManager *self,
+ guint duration);
EOS_SDK_ALL_API_VERSIONS
-void eos_page_manager_set_page_actions (EosPageManager *self,
- GtkWidget *page,
- gboolean actions_visible);
+guint eos_page_manager_get_transition_duration (EosPageManager *self);
EOS_SDK_ALL_API_VERSIONS
-GtkWidget *eos_page_manager_get_page_custom_toolbox_widget (EosPageManager *self,
- GtkWidget *page);
+void eos_page_manager_set_transition_type (EosPageManager *self,
+ EosPageManagerTransitionType transition);
EOS_SDK_ALL_API_VERSIONS
-void eos_page_manager_set_page_custom_toolbox_widget (EosPageManager *self,
- GtkWidget *page,
- GtkWidget *custom_toolbox_widget);
+EosPageManagerTransitionType eos_page_manager_get_transition_type (EosPageManager *self);
EOS_SDK_ALL_API_VERSIONS
-const gchar *eos_page_manager_get_page_background_uri (EosPageManager *self,
- GtkWidget *page);
+const gchar *eos_page_manager_get_page_background_uri (EosPageManager *self,
+ GtkWidget *page);
EOS_SDK_ALL_API_VERSIONS
-void eos_page_manager_set_page_background_uri (EosPageManager *self,
- GtkWidget *page,
- const gchar *background);
+void eos_page_manager_set_page_background_uri (EosPageManager *self,
+ GtkWidget *page,
+ const gchar *background);
EOS_SDK_ALL_API_VERSIONS
-void eos_page_manager_remove_page_by_name (EosPageManager *self,
- const gchar *name);
+void eos_page_manager_remove_page_by_name (EosPageManager *self,
+ const gchar *name);
G_END_DECLS
diff --git a/test/smoke-tests/app-window.js b/test/smoke-tests/app-window.js
index 8b5dd15..8f3f301 100644
--- a/test/smoke-tests/app-window.js
+++ b/test/smoke-tests/app-window.js
@@ -3,6 +3,7 @@
const Lang = imports.lang;
const Endless = imports.gi.Endless;
const Gtk = imports.gi.Gtk;
+const GObject = imports.gi.GObject;
const TEST_APPLICATION_ID = 'com.endlessm.example.test';
@@ -11,7 +12,7 @@ const Page0 = new Lang.Class ({
Name: 'Page0',
Extends: Gtk.Grid,
- _init: function(props) {
+ _init: function(pm, props) {
props = props || {};
props.orientation = Gtk.Orientation.VERTICAL;
this.parent(props);
@@ -20,6 +21,47 @@ const Page0 = new Lang.Class ({
this.add(this.button1);
this.button2 = new Gtk.Button({ label: 'Go to page named "page1"' });
this.add(this.button2);
+
+ this._addTransitionOptions(pm);
+ },
+
+ _addTransitionOptions: function(pm) {
+ // Combo box for transition type...
+ let typeMenu = new Gtk.ComboBoxText();
+ let type_options = {
+ "Transition type: None": Endless.PageManagerTransitionType.NONE,
+ "Transition type: Fade": Endless.PageManagerTransitionType.CROSSFADE,
+ "Transition type: Slide Right": Endless.PageManagerTransitionType.SLIDE_RIGHT,
+ "Transition type: Slide Left": Endless.PageManagerTransitionType.SLIDE_LEFT,
+ "Transition type: Slide Down": Endless.PageManagerTransitionType.SLIDE_DOWN,
+ "Transition type: Slide Up": Endless.PageManagerTransitionType.SLIDE_UP
+ }
+ for (let key in type_options) {
+ typeMenu.append_text(key);
+ }
+ typeMenu.set_active (0);
+ this.add(typeMenu);
+ typeMenu.connect('changed', Lang.bind(this, function () {
+ let activeKey = typeMenu.get_active_text();
+ pm.set_transition_type(type_options[activeKey]);
+ }));
+ // Combo box for transition time...
+ let durationMenu = new Gtk.ComboBoxText();
+ let duration_options = {
+ "Transition time: 200": 200,
+ "Transition time: 500": 500,
+ "Transition time: 1000": 1000,
+ "Transition time: 2000": 2000
+ }
+ for (let key in duration_options) {
+ durationMenu.append_text(key);
+ }
+ durationMenu.set_active (0);
+ this.add(durationMenu);
+ durationMenu.connect('changed', Lang.bind(this, function () {
+ let activeKey = durationMenu.get_active_text();
+ pm.set_transition_duration(duration_options[activeKey]);
+ }));
}
});
@@ -69,8 +111,10 @@ const TestApplication = new Lang.Class ({
vfunc_startup: function() {
this.parent();
+ this._pm = new Endless.PageManager();
+
// First page
- this._page0 = new Page0();
+ this._page0 = new Page0(this._pm);
this._page0.button1.connect('clicked', Lang.bind(this, function () {
this._pm.visible_page = this._page1;
}));
@@ -97,7 +141,6 @@ const TestApplication = new Lang.Class ({
this._toolbox.switch2.active);
}));
- this._pm = new Endless.PageManager();
this._pm.add(this._page0, {
name: "page0",
background_uri: "./test/smoke-tests/images/cat_eye.jpg",
@@ -120,7 +163,7 @@ const TestApplication = new Lang.Class ({
_onButtonClicked: function () {
this._window.destroy();
- },
+ }
});
let app = new TestApplication({ application_id: TEST_APPLICATION_ID,
diff --git a/test/test-page-manager.c b/test/test-page-manager.c
index 46ac768..4122d7e 100644
--- a/test/test-page-manager.c
+++ b/test/test-page-manager.c
@@ -23,6 +23,9 @@
#define ADD_EMPTY_PAGE_MANAGER_TEST(path, test_func) \
g_test_add ((path), PageManagerFixture, NULL, \
empty_pm_fixture_setup, (test_func), pm_fixture_teardown);
+#define DURATION_DEFAULT 200
+#define DURATION_1 1
+#define DURATION_2 9999
typedef struct
{
@@ -458,6 +461,50 @@ test_pm_duplicate_page_name (PageManagerFixture *fixture,
}
static void
+test_pm_prop_transition_duration (PageManagerFixture *fixture,
+ gconstpointer unused)
+{
+ guint duration;
+ g_object_get (fixture->pm, "transition-duration", &duration, NULL);
+ g_assert (duration == DURATION_DEFAULT);
+ g_object_set (fixture->pm, "transition-duration", DURATION_2, NULL);
+ g_object_get (fixture->pm, "transition-duration", &duration, NULL);
+ g_assert (duration == DURATION_2);
+}
+
+static void
+test_pm_get_set_transition_duration (PageManagerFixture *fixture,
+ gconstpointer unused)
+{
+ g_assert (DURATION_DEFAULT == eos_page_manager_get_transition_duration (EOS_PAGE_MANAGER (fixture->pm)));
+ eos_page_manager_set_transition_duration (EOS_PAGE_MANAGER (fixture->pm), DURATION_1);
+ g_assert (DURATION_1 == eos_page_manager_get_transition_duration (EOS_PAGE_MANAGER (fixture->pm)));
+ eos_page_manager_set_transition_duration (EOS_PAGE_MANAGER (fixture->pm), DURATION_2);
+ g_assert (DURATION_2 == eos_page_manager_get_transition_duration (EOS_PAGE_MANAGER (fixture->pm)));
+}
+
+static void
+test_pm_prop_transition_type (PageManagerFixture *fixture,
+ gconstpointer unused)
+{
+ EosPageManagerTransitionType type;
+ g_object_get (fixture->pm, "transition-type", &type, NULL);
+ g_assert (type == EOS_PAGE_MANAGER_TRANSITION_TYPE_NONE);
+ g_object_set (fixture->pm, "transition-type", EOS_PAGE_MANAGER_TRANSITION_TYPE_CROSSFADE, NULL);
+ g_object_get (fixture->pm, "transition-type", &type, NULL);
+ g_assert (type == EOS_PAGE_MANAGER_TRANSITION_TYPE_CROSSFADE);
+}
+
+static void
+test_pm_get_set_transition_type (PageManagerFixture *fixture,
+ gconstpointer unused)
+{
+ g_assert (EOS_PAGE_MANAGER_TRANSITION_TYPE_NONE == eos_page_manager_get_transition_type (EOS_PAGE_MANAGER (fixture->pm)));
+ eos_page_manager_set_transition_type (EOS_PAGE_MANAGER (fixture->pm), EOS_PAGE_MANAGER_TRANSITION_TYPE_CROSSFADE);
+ g_assert (EOS_PAGE_MANAGER_TRANSITION_TYPE_CROSSFADE == eos_page_manager_get_transition_type (EOS_PAGE_MANAGER (fixture->pm)));
+}
+
+static void
test_empty_pm_visible_page (PageManagerFixture *fixture,
gconstpointer unused)
{
@@ -531,6 +578,14 @@ add_page_manager_tests (void)
test_pm_remove_page_by_name);
ADD_PAGE_MANAGER_TEST ("/page-manager/duplicate-page-name",
test_pm_duplicate_page_name);
+ ADD_PAGE_MANAGER_TEST ("/page-manager/prop-transition-duration",
+ test_pm_prop_transition_duration);
+ ADD_PAGE_MANAGER_TEST ("/page-manager/get-set-transition-duration",
+ test_pm_get_set_transition_duration);
+ ADD_PAGE_MANAGER_TEST ("/page-manager/prop-transition-type",
+ test_pm_prop_transition_type);
+ ADD_PAGE_MANAGER_TEST ("/page-manager/get-set-transition-type",
+ test_pm_get_set_transition_type);
ADD_EMPTY_PAGE_MANAGER_TEST ("/page-manager/empty-visible-page",
test_empty_pm_visible_page);
ADD_EMPTY_PAGE_MANAGER_TEST ("/page-manager/empty-visible-page-name",