Esempio n. 1
0
static void
startup_cb (MxApplication *application)
{
  MxWindow *window;
  ClutterActor *scroll, *child;
  gint i;

  window = mx_application_create_window (application, "Test Widgets");

  /* Create scroll view */
  scroll = mx_kinetic_scroll_view_new ();
  mx_kinetic_scroll_view_set_use_grab (MX_KINETIC_SCROLL_VIEW (scroll), TRUE);
  mx_kinetic_scroll_view_set_mouse_button (MX_KINETIC_SCROLL_VIEW (scroll), 3);
  clutter_actor_set_clip_to_allocation (scroll, TRUE);

  child = mx_box_layout_new_with_orientation (MX_ORIENTATION_VERTICAL);

  for (i = 0; i < 10000; i++) {
    ClutterActor *layout, *label, *icon;
    gchar *s = g_strdup_printf ("Row %d", i);

    layout = mx_box_layout_new_with_orientation (MX_ORIENTATION_HORIZONTAL);
    label = mx_label_new_with_text (s);
    clutter_actor_add_child (layout, label);
    g_free (s);

    icon = mx_icon_new ();
    mx_icon_set_icon_name (MX_ICON (icon), "object-rotate-left");
    mx_icon_set_icon_size (MX_ICON (icon), 32);
    clutter_actor_add_child (layout, icon);

    clutter_actor_add_child (child, layout);
  }

  clutter_actor_add_child (scroll, child);

  mx_window_set_child (window, scroll);

  /* show the window */
  mx_window_set_has_toolbar (window, FALSE);
  mx_window_show (window);
}
Esempio n. 2
0
void
scroll_view_main (ClutterContainer *stage)
{
  gint width, height;
  MxAdjustment *hadjust, *vadjust;
  ClutterActor *label, *elastic, *overshoot, *scroll, *kinetic, *view, *texture;

  scroll = mx_scroll_view_new ();

  /* Make sure something underneath the kinetic scroll view swallows events
   * so that we don't end up moving the window.
   */
  g_signal_connect (scroll, "button-press-event", G_CALLBACK (true_cb), NULL);

  kinetic = mx_kinetic_scroll_view_new ();

  clutter_container_add_actor (stage, scroll);
  clutter_actor_set_position (scroll, 10, 10);
  clutter_actor_set_size (scroll, 300, 300);

  view = mx_viewport_new ();
  mx_viewport_set_sync_adjustments (MX_VIEWPORT (view), FALSE);
  clutter_container_add_actor (CLUTTER_CONTAINER (kinetic), view);
  clutter_container_add_actor (CLUTTER_CONTAINER (scroll), kinetic);


  texture = clutter_texture_new_from_file ("redhand.png", NULL);
  clutter_container_add_actor (CLUTTER_CONTAINER (view), texture);
  g_object_set (texture, "repeat-x", TRUE, "repeat-y", TRUE, NULL);
  clutter_actor_set_size (texture, 1280, 1280);

  clutter_texture_get_base_size (CLUTTER_TEXTURE (texture),
                                 &width, &height);
  mx_scrollable_get_adjustments (MX_SCROLLABLE (view),
                                 &hadjust, &vadjust);
  mx_adjustment_set_values (hadjust,
                            0,
                            0,
                            1280,
                            width,
                            width * 3,
                            300);
  mx_adjustment_set_values (vadjust,
                            0,
                            0,
                            1280,
                            height,
                            height * 3,
                            300);

  label = mx_label_new_with_text ("Toggle over-shooting:");
  overshoot = mx_toggle_new ();
  clutter_actor_set_position (label, 320, 10);
  clutter_actor_set_position (overshoot, 330 + clutter_actor_get_width (label),
                              10);
  clutter_container_add (stage, label, overshoot, NULL);

  g_signal_connect (overshoot, "notify::active",
                    G_CALLBACK (notify_overshoot_cb), kinetic);

  label = mx_label_new_with_text ("Toggle elasticity:");
  elastic = mx_toggle_new ();
  clutter_actor_set_position (label, 320,
                              20 + clutter_actor_get_height (overshoot));
  clutter_actor_set_position (elastic, clutter_actor_get_x (overshoot),
                              clutter_actor_get_y (label));
  clutter_container_add (stage, label, elastic, NULL);

  g_signal_connect (elastic, "notify::active",
                    G_CALLBACK (notify_elastic_cb), kinetic);
}