summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorGustavo Noronha Silva <gustavo.noronha@collabora.com>2013-09-11 12:33:57 -0300
committerGustavo Noronha Silva <gustavo.noronha@collabora.co.uk>2015-06-11 15:47:48 -0300
commit0c75e178145c3296f05deefed34be3691b1ffb3b (patch)
treef156fccb446cf532830faef20bf812afc27435ba /examples
parent2105055a347c8a35d091cabe118983f621f26965 (diff)
downloadclutter-0c75e178145c3296f05deefed34be3691b1ffb3b.tar.gz
Add PanAxis mode that automatically pins scroll based on initial movement
This code is inspired by the implementation of the same feature for the Mx toolkit's MxKineticScrollView. See commit 4d08771. https://bugzilla.gnome.org/show_bug.cgi?id=707982
Diffstat (limited to 'examples')
-rw-r--r--examples/pan-action.c58
1 files changed, 54 insertions, 4 deletions
diff --git a/examples/pan-action.c b/examples/pan-action.c
index e8733056b..4e3f73f25 100644
--- a/examples/pan-action.c
+++ b/examples/pan-action.c
@@ -83,7 +83,7 @@ create_scroll_actor (ClutterActor *stage)
pan_action = clutter_pan_action_new ();
clutter_pan_action_set_interpolate (CLUTTER_PAN_ACTION (pan_action), TRUE);
g_signal_connect (pan_action, "pan", G_CALLBACK (on_pan), NULL);
- clutter_actor_add_action (scroll, pan_action);
+ clutter_actor_add_action_with_name (scroll, "pan", pan_action);
clutter_actor_set_reactive (scroll, TRUE);
@@ -113,10 +113,45 @@ on_key_press (ClutterActor *stage,
return CLUTTER_EVENT_STOP;
}
+static gboolean
+label_clicked_cb (ClutterText *label, ClutterEvent *event, ClutterActor *scroll)
+{
+ ClutterPanAction *action = CLUTTER_PAN_ACTION (clutter_actor_get_action (scroll, "pan"));
+ const gchar *label_text = clutter_text_get_text (label);
+
+ if (g_str_equal (label_text, "X AXIS"))
+ clutter_pan_action_set_pan_axis (action, CLUTTER_PAN_X_AXIS);
+ else if (g_str_equal (label_text, "Y AXIS"))
+ clutter_pan_action_set_pan_axis (action, CLUTTER_PAN_Y_AXIS);
+ else if (g_str_equal (label_text, "AUTO"))
+ clutter_pan_action_set_pan_axis (action, CLUTTER_PAN_AXIS_AUTO);
+ else
+ clutter_pan_action_set_pan_axis (action, CLUTTER_PAN_AXIS_NONE);
+
+ return TRUE;
+}
+
+static void
+add_label (const gchar *text, ClutterActor *box, ClutterActor *scroll)
+{
+ ClutterActor *label;
+
+ label = clutter_text_new_with_text (NULL, text);
+ clutter_actor_set_reactive (label, TRUE);
+ clutter_actor_set_x_align (label, CLUTTER_ACTOR_ALIGN_START);
+ clutter_actor_set_x_expand (label, TRUE);
+
+ clutter_actor_add_child (box, label);
+
+ g_signal_connect (label, "button-release-event",
+ G_CALLBACK (label_clicked_cb), scroll);
+}
+
int
main (int argc, char *argv[])
{
- ClutterActor *stage, *scroll, *info;
+ ClutterActor *stage, *scroll, *box, *info;
+ ClutterLayoutManager *layout;
if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
return EXIT_FAILURE;
@@ -129,9 +164,24 @@ main (int argc, char *argv[])
scroll = create_scroll_actor (stage);
clutter_actor_add_child (stage, scroll);
+ box = clutter_actor_new ();
+ clutter_actor_add_child (stage, box);
+ clutter_actor_set_position (box, 12, 12);
+
+ layout = clutter_box_layout_new ();
+ clutter_box_layout_set_orientation (CLUTTER_BOX_LAYOUT (layout), CLUTTER_ORIENTATION_VERTICAL);
+ clutter_actor_set_layout_manager (box, layout);
+
info = clutter_text_new_with_text (NULL, "Press <space> to reset the image position.");
- clutter_actor_add_child (stage, info);
- clutter_actor_set_position (info, 12, 12);
+ clutter_actor_add_child (box, info);
+
+ info = clutter_text_new_with_text (NULL, "Click labels below to change AXIS pinning.");
+ clutter_actor_add_child (box, info);
+
+ add_label ("NONE", box, scroll);
+ add_label ("X AXIS", box, scroll);
+ add_label ("Y AXIS", box, scroll);
+ add_label ("AUTO", box, scroll);
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL);
g_signal_connect (stage, "key-press-event", G_CALLBACK (on_key_press), scroll);