static void update_playing (MxButton *button, gboolean playing) { ClutterActor *child; child = mx_bin_get_child (MX_BIN (button)); if (playing) { mx_stylable_set_style_class (MX_STYLABLE (button), "PauseButton"); mx_icon_set_icon_name (MX_ICON (child), "media-playback-pause"); } else { mx_stylable_set_style_class (MX_STYLABLE (button), "PlayButton"); mx_icon_set_icon_name (MX_ICON (child), "media-playback-start"); } /* stop button? meh */ }
static ClutterActor * _make_notification_actor (MexNotification *notification) { ClutterActor *box; ClutterActor *label, *icon; box = mx_box_layout_new (); mx_box_layout_set_orientation (MX_BOX_LAYOUT (box), MX_ORIENTATION_HORIZONTAL); if (notification->icon) { icon = mx_icon_new (); clutter_actor_set_size (icon, 26, 26); mx_icon_set_icon_name (MX_ICON (icon), notification->icon); clutter_container_add_actor (CLUTTER_CONTAINER (box), icon); mx_box_layout_child_set_y_align (MX_BOX_LAYOUT (box), icon, MX_ALIGN_MIDDLE); } label = mx_label_new_with_text (notification->message); mx_label_set_y_align (MX_LABEL (label), MX_ALIGN_MIDDLE); clutter_container_add_actor (CLUTTER_CONTAINER (box), label); return box; }
static ClutterActor * create_button (const char *button_style, const char *icon_style, const char *icon_name) { ClutterActor *widget; ClutterActor *icon; icon = mx_icon_new (); mx_stylable_set_style_class (MX_STYLABLE (icon), icon_style); mx_stylable_set_style (MX_STYLABLE (icon), style); mx_icon_set_icon_name (MX_ICON (icon), icon_name); mx_icon_set_icon_size (MX_ICON (icon), 64); widget = mx_button_new (); mx_stylable_set_style_class (MX_STYLABLE (widget), button_style); mx_stylable_set_style (MX_STYLABLE (widget), style); mx_bin_set_child (MX_BIN (widget), icon); return widget; }
/** * mx_combo_box_set_active_icon_name: * @box: A #MxComboBox * @icon_name: (allow-none): Icon name to use for displayed icon * * Set the icon displayed in the combo box. * */ void mx_combo_box_set_active_icon_name (MxComboBox *box, const gchar *icon_name) { MxComboBoxPrivate *priv; g_return_if_fail (MX_IS_COMBO_BOX (box)); priv = box->priv; if (!priv->icon) { if (icon_name) { MxIconTheme *icon_theme; icon_theme = mx_icon_theme_get_default (); if (mx_icon_theme_has_icon (icon_theme, icon_name)) { priv->icon = mx_icon_new (); mx_icon_set_icon_name (MX_ICON (priv->icon), icon_name); clutter_actor_add_child (CLUTTER_ACTOR (box), priv->icon); } } } else { if (icon_name) mx_icon_set_icon_name (MX_ICON (priv->icon), icon_name); else { clutter_actor_destroy (priv->icon); priv->icon = NULL; clutter_actor_queue_relayout (CLUTTER_ACTOR (box)); } } priv->index = -1; g_object_notify (G_OBJECT (box), "index"); g_object_notify (G_OBJECT (box), "active-icon-name"); }
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); }
/** * mx_combo_box_get_active_icon_name: * @box: A #MxComboBox * * Get the name of the icon displayed in the combo box * * Returns: the text string of the name of the displayed icon, owned by * the combo box, or %NULL if there is no active icon. */ const gchar * mx_combo_box_get_active_icon_name (MxComboBox *box) { MxComboBoxPrivate *priv; g_return_val_if_fail (MX_IS_COMBO_BOX (box), NULL); priv = box->priv; if (priv->icon) return mx_icon_get_icon_name (MX_ICON (priv->icon)); else return NULL; }
/** * mx_combo_box_set_index: * @box: A #MxComboBox * @index: the index of the list item to set * * Set the current combo box text from the item at @index in the list. * */ void mx_combo_box_set_index (MxComboBox *box, gint index) { MxComboBoxPrivate *priv; GSList *item; MxAction *action; const gchar *icon_name; g_return_if_fail (MX_IS_COMBO_BOX (box)); priv = box->priv; item = g_slist_nth (box->priv->actions, index); if (!item) { box->priv->index = -1; clutter_text_set_text ((ClutterText*) box->priv->label, NULL); return; } box->priv->index = index; action = (MxAction *)item->data; clutter_text_set_text ((ClutterText*) box->priv->label, mx_action_get_display_name (action)); if (priv->icon) { clutter_actor_remove_child (CLUTTER_ACTOR (box), priv->icon); priv->icon = NULL; } icon_name = mx_action_get_icon (item->data); if (icon_name) { MxIconTheme *icon_theme; icon_theme = mx_icon_theme_get_default (); if (mx_icon_theme_has_icon (icon_theme, icon_name)) { priv->icon = mx_icon_new (); mx_icon_set_icon_name (MX_ICON (priv->icon), icon_name); clutter_actor_add_child (CLUTTER_ACTOR (box), priv->icon); } } g_object_notify (G_OBJECT (box), "index"); g_object_notify (G_OBJECT (box), "active-text"); g_object_notify (G_OBJECT (box), "active-icon-name"); }
/** * mx_button_set_icon_name: * @button: a #MxButton * @icon_name: (allow-none): icon-name to use on the button * * Sets the icon-name used to display an icon on the button. Setting %NULL * will remove the icon name, or resort to the icon-name set in the current * style. Setting an icon name overrides any icon set in the style. * * Since: 1.2 */ void mx_button_set_icon_name (MxButton *button, const gchar *icon_name) { MxButtonPrivate *priv; g_return_if_fail (MX_IS_BUTTON (button)); priv = button->priv; g_free (priv->icon_name); priv->icon_name = g_strdup (icon_name); mx_icon_set_icon_name (MX_ICON (priv->icon), icon_name ? icon_name : priv->style_icon_name); mx_button_update_contents (button); g_object_notify (G_OBJECT (button), "icon-name"); }
/** * mx_button_set_icon_size: * @button: a #MxButton * * Sets the icon-size to use for the icon displayed inside the button. This will * override the icon-size set in the style. Setting a value of %0 resets to the * size from the style. * * Since: 1.2 */ void mx_button_set_icon_size (MxButton *button, guint icon_size) { MxButtonPrivate *priv; g_return_if_fail (MX_IS_BUTTON (button)); priv = button->priv; if (priv->icon_size != icon_size) { priv->icon_size = icon_size; mx_icon_set_icon_size (MX_ICON (priv->icon), icon_size ? icon_size : priv->style_icon_size); g_object_notify (G_OBJECT (button), "icon-size"); } }
/** * mx_button_set_action: * @button: A #MxButton * @action: A #MxAction * * Sets @action as the action for @button. @Button will take its label and * icon from @action. * * Since: 1.2 */ void mx_button_set_action (MxButton *button, MxAction *action) { MxButtonPrivate *priv; const gchar *display_name; g_return_if_fail (MX_IS_BUTTON (button)); g_return_if_fail (MX_IS_ACTION (action)); priv = button->priv; if (priv->action) g_object_unref (priv->action); if (priv->action_label_binding) g_object_unref (priv->action_label_binding); if (priv->action_icon_binding) g_object_unref (priv->action_icon_binding); priv->action = g_object_ref_sink (action); display_name = mx_action_get_display_name (action); mx_icon_set_icon_name (MX_ICON (priv->icon), mx_action_get_icon (action)); clutter_text_set_text (CLUTTER_TEXT (priv->label), (display_name) ? display_name : ""); /* bind action properties to button properties */ priv->action_label_binding = g_object_bind_property (action, "display-name", priv->label, "text", 0); priv->action_icon_binding = g_object_bind_property (action, "icon", priv->icon, "icon-name", 0); mx_button_update_contents (button); }
MxIcon * mex_clock_bin_get_icon (MexClockBin *bin) { g_return_val_if_fail (MEX_IS_CLOCK_BIN (bin), NULL); return MX_ICON (bin->priv->icon); }
void mex_column_set_icon_name (MexColumn *column, const gchar *name) { g_return_if_fail (MEX_IS_COLUMN (column)); mx_icon_set_icon_name (MX_ICON (column->priv->icon), name); }
static void add_pictures (ClutterActor *box) { GList *files = get_pictures (); while (files) { gint w, h, i; ClutterActor *drawer, *drawer2, *tile, *texture, *menu, *description; gchar *file = files->data; /* Create texture */ texture = clutter_texture_new_from_file (file, NULL); clutter_texture_get_base_size (CLUTTER_TEXTURE (texture), &w, &h); clutter_actor_set_size (texture, 300, 300.0/w * h); /* Create menu */ menu = mx_box_layout_new (); mx_box_layout_set_orientation (MX_BOX_LAYOUT (menu), MX_ORIENTATION_VERTICAL); for (i = 0; i < 4; i++) { ClutterActor *button, *layout, *icon, *label; button = mx_button_new (); layout = mx_box_layout_new (); icon = mx_icon_new (); label = mx_label_new (); mx_box_layout_set_spacing (MX_BOX_LAYOUT (layout), 8); mx_icon_set_icon_size (MX_ICON (icon), 16); clutter_actor_set_size (icon, 16, 16); clutter_container_add (CLUTTER_CONTAINER (layout), icon, label, NULL); mx_bin_set_child (MX_BIN (button), layout); mx_bin_set_alignment (MX_BIN (button), MX_ALIGN_START, MX_ALIGN_MIDDLE); clutter_container_add_actor (CLUTTER_CONTAINER (menu), button); mx_box_layout_child_set_x_fill (MX_BOX_LAYOUT (menu), button, TRUE); switch (i) { case 0: mx_icon_set_icon_name (MX_ICON (icon), "dialog-information"); mx_label_set_text (MX_LABEL (label), "This"); break; case 1: mx_icon_set_icon_name (MX_ICON (icon), "dialog-question"); mx_label_set_text (MX_LABEL (label), "is"); break; case 2: mx_icon_set_icon_name (MX_ICON (icon), "dialog-warning"); mx_label_set_text (MX_LABEL (label), "a"); break; case 3: mx_icon_set_icon_name (MX_ICON (icon), "dialog-error"); mx_label_set_text (MX_LABEL (label), "menu"); break; } } /* Create description */ description = mx_label_new_with_text ("Here you could put a very " "long description of whatever " "is above it. Or you could put " "another focusable widget here " "and it'd be navigable, like " "the menu on the right. Whoo!"); clutter_text_set_line_wrap ((ClutterText *)mx_label_get_clutter_text ( MX_LABEL (description)), TRUE); drawer = mex_expander_box_new (); mex_expander_box_set_important_on_focus (MEX_EXPANDER_BOX (drawer), TRUE); drawer2 = mex_expander_box_new (); mex_expander_box_set_grow_direction (MEX_EXPANDER_BOX (drawer2), MEX_EXPANDER_BOX_RIGHT); mex_expander_box_set_important (MEX_EXPANDER_BOX (drawer2), TRUE); tile = mex_tile_new_with_label (file); mex_tile_set_important (MEX_TILE (tile), TRUE); mx_bin_set_child (MX_BIN (tile), texture); clutter_container_add (CLUTTER_CONTAINER (drawer2), tile, menu, NULL); clutter_container_add (CLUTTER_CONTAINER (drawer), drawer2, description, NULL); g_signal_connect (drawer, "notify::open", G_CALLBACK (sync_drawer2_cb), drawer2); clutter_container_add_actor (CLUTTER_CONTAINER (box), drawer); clutter_actor_set_reactive (texture, TRUE); g_signal_connect (texture, "enter-event", G_CALLBACK (texture_enter_cb), drawer); g_signal_connect (texture, "leave-event", G_CALLBACK (texture_leave_cb), drawer); g_signal_connect (texture, "button-press-event", G_CALLBACK (texture_clicked_cb), drawer); g_free (file); files = g_list_delete_link (files, files); } }
static void startup_cb (MxApplication *app) { MxWindow *window; ClutterActor *stage, *toggle, *label, *table, *button, *icon; window = mx_application_create_window (app, "Test Window"); stage = (ClutterActor *)mx_window_get_clutter_stage (window); mx_window_set_icon_name (window, "window-new"); clutter_actor_set_size (stage, 480, 320); table = mx_table_new (); mx_table_set_column_spacing (MX_TABLE (table), 8); mx_table_set_row_spacing (MX_TABLE (table), 12); mx_window_set_child (window, table); toggle = mx_toggle_new (); label = mx_label_new_with_text ("Toggle small-screen mode"); g_signal_connect (toggle, "notify::active", G_CALLBACK (small_screen_cb), window); mx_table_insert_actor_with_properties (MX_TABLE (table), toggle, 0, 0, "x-expand", TRUE, "x-align", MX_ALIGN_END, "x-fill", FALSE, NULL); mx_table_insert_actor_with_properties (MX_TABLE (table), label, 0, 1, "x-expand", TRUE, "x-align", MX_ALIGN_START, "y-fill", FALSE, "x-fill", FALSE, NULL); toggle = mx_toggle_new (); label = mx_label_new_with_text ("Toggle full-screen mode"); g_signal_connect (toggle, "notify::active", G_CALLBACK (fullscreen_cb), stage); mx_table_insert_actor_with_properties (MX_TABLE (table), toggle, 1, 0, "x-expand", TRUE, "x-align", MX_ALIGN_END, "x-fill", FALSE, NULL); mx_table_insert_actor_with_properties (MX_TABLE (table), label, 1, 1, "x-expand", TRUE, "x-align", MX_ALIGN_START, "y-fill", FALSE, "x-fill", FALSE, NULL); toggle = mx_toggle_new (); label = mx_label_new_with_text ("Toggle custom window icon"); g_signal_connect (toggle, "notify::active", G_CALLBACK (icon_cb), window); mx_table_insert_actor_with_properties (MX_TABLE (table), toggle, 2, 0, "x-expand", TRUE, "x-align", MX_ALIGN_END, "x-fill", FALSE, NULL); mx_table_insert_actor_with_properties (MX_TABLE (table), label, 2, 1, "x-expand", TRUE, "x-align", MX_ALIGN_START, "y-fill", FALSE, "x-fill", FALSE, NULL); toggle = mx_toggle_new (); mx_toggle_set_active (MX_TOGGLE (toggle), TRUE); label = mx_label_new_with_text ("Toggle user-resizable"); g_signal_connect (toggle, "notify::active", G_CALLBACK (resizable_cb), stage); mx_table_insert_actor_with_properties (MX_TABLE (table), toggle, 3, 0, "x-expand", TRUE, "x-align", MX_ALIGN_END, "x-fill", FALSE, NULL); mx_table_insert_actor_with_properties (MX_TABLE (table), label, 3, 1, "x-expand", TRUE, "x-align", MX_ALIGN_START, "y-fill", FALSE, "x-fill", FALSE, NULL); toggle = mx_toggle_new (); mx_toggle_set_active (MX_TOGGLE (toggle), TRUE); label = mx_label_new_with_text ("Toggle toolbar"); g_signal_connect (toggle, "notify::active", G_CALLBACK (toolbar_cb), window); mx_table_insert_actor_with_properties (MX_TABLE (table), toggle, 4, 0, "x-expand", TRUE, "x-align", MX_ALIGN_END, "x-fill", FALSE, NULL); mx_table_insert_actor_with_properties (MX_TABLE (table), label, 4, 1, "x-expand", TRUE, "x-align", MX_ALIGN_START, "y-fill", FALSE, "x-fill", FALSE, NULL); icon = mx_icon_new (); mx_icon_set_icon_name (MX_ICON (icon), "object-rotate-right"); mx_icon_set_icon_size (MX_ICON (icon), 16); button = mx_button_new (); mx_bin_set_child (MX_BIN (button), icon); g_signal_connect (button, "clicked", G_CALLBACK (rotate_clicked_cb), window); clutter_container_add_actor ( CLUTTER_CONTAINER (mx_window_get_toolbar (window)), button); mx_bin_set_alignment (MX_BIN (mx_window_get_toolbar (window)), MX_ALIGN_END, MX_ALIGN_MIDDLE); clutter_actor_show (stage); }
static void mx_button_style_changed (MxWidget *widget) { MxButton *button = MX_BUTTON (widget); MxButtonPrivate *priv = button->priv; MxBorderImage *content_image = NULL; /* update the label styling */ mx_button_update_label_style (button); g_free (priv->style_icon_name); mx_stylable_get (MX_STYLABLE (widget), "x-mx-content-image", &content_image, "x-mx-icon-name", &priv->style_icon_name, "x-mx-icon-size", &priv->style_icon_size, NULL); if (content_image && content_image->uri) { if (priv->content_image) { clutter_actor_remove_child (CLUTTER_ACTOR (widget), priv->content_image); } priv->content_image = (ClutterActor*) mx_texture_cache_get_texture (mx_texture_cache_get_default (), content_image->uri); if (priv->content_image) clutter_actor_add_child (CLUTTER_ACTOR (widget), priv->content_image); else g_warning ("Could not load content image \"%s\"", content_image->uri); g_boxed_free (MX_TYPE_BORDER_IMAGE, content_image); return; } else { /* remove any previous content image */ if (priv->content_image) { clutter_actor_remove_child (CLUTTER_ACTOR (widget), priv->content_image); priv->content_image = NULL; } if (content_image) g_boxed_free (MX_TYPE_BORDER_IMAGE, content_image); } if (priv->icon_size == 0) mx_icon_set_icon_size (MX_ICON (priv->icon), priv->style_icon_size); if (priv->style_icon_name && !priv->icon_name) { mx_icon_set_icon_name (MX_ICON (priv->icon), priv->style_icon_name); mx_button_update_contents (button); } }
static void mx_button_update_contents (MxButton *self) { MxButtonPrivate *priv = self->priv; ClutterActor *child; gboolean icon_visible, label_visible; const gchar *text; /* If the icon doesn't have a name set, treat it as * not-visible. */ if (priv->icon_visible && mx_icon_get_icon_name (MX_ICON (priv->icon))) icon_visible = TRUE; else icon_visible = FALSE; text = clutter_text_get_text (CLUTTER_TEXT (priv->label)); if (priv->label_visible && text && (strcmp (text, "") != 0)) label_visible = TRUE; else label_visible = FALSE; /* replace any custom content */ child = mx_bin_get_child (MX_BIN (self)); if (child != priv->hbox) mx_bin_set_child (MX_BIN (self), priv->hbox); /* Handle the simple cases first */ if (!icon_visible && !label_visible) { clutter_actor_hide (priv->hbox); return; } /* ensure the hbox is visible */ clutter_actor_show (priv->hbox); if (icon_visible && !label_visible) { clutter_actor_show (priv->icon); clutter_actor_hide (priv->label); clutter_actor_set_child_below_sibling (priv->hbox, priv->icon, NULL); return; } if (!icon_visible && label_visible) { clutter_actor_hide (priv->icon); clutter_actor_show (priv->label); clutter_actor_set_child_below_sibling (priv->hbox, priv->label, NULL); return; } /* Both the icon and text are visible, handle this case */ clutter_actor_show (priv->icon); clutter_actor_show (priv->label); switch (priv->icon_position) { case MX_POSITION_TOP: mx_box_layout_set_orientation (MX_BOX_LAYOUT (priv->hbox), MX_ORIENTATION_VERTICAL); clutter_actor_set_child_below_sibling (priv->hbox, priv->icon, NULL); clutter_container_child_set (CLUTTER_CONTAINER (priv->hbox), priv->label, "x-align", MX_ALIGN_MIDDLE, "y-align", MX_ALIGN_END, NULL); clutter_container_child_set (CLUTTER_CONTAINER (priv->hbox), priv->icon, "x-align", MX_ALIGN_MIDDLE, "y-align", MX_ALIGN_START, NULL); break; case MX_POSITION_RIGHT: mx_box_layout_set_orientation (MX_BOX_LAYOUT (priv->hbox), MX_ORIENTATION_HORIZONTAL); clutter_actor_set_child_above_sibling (priv->hbox, priv->icon, NULL); clutter_container_child_set (CLUTTER_CONTAINER (priv->hbox), priv->label, "x-align", MX_ALIGN_START, "y-align", MX_ALIGN_MIDDLE, NULL); clutter_container_child_set (CLUTTER_CONTAINER (priv->hbox), priv->icon, "x-align", MX_ALIGN_END, "y-align", MX_ALIGN_MIDDLE, NULL); break; case MX_POSITION_BOTTOM: mx_box_layout_set_orientation (MX_BOX_LAYOUT (priv->hbox), MX_ORIENTATION_VERTICAL); clutter_actor_set_child_above_sibling (priv->hbox, priv->icon, NULL); mx_box_layout_child_set_x_align (MX_BOX_LAYOUT (priv->hbox), priv->label, MX_ALIGN_MIDDLE); clutter_container_child_set (CLUTTER_CONTAINER (priv->hbox), priv->label, "x-align", MX_ALIGN_MIDDLE, "y-align", MX_ALIGN_START, NULL); clutter_container_child_set (CLUTTER_CONTAINER (priv->hbox), priv->icon, "x-align", MX_ALIGN_MIDDLE, "y-align", MX_ALIGN_END, NULL); break; case MX_POSITION_LEFT: mx_box_layout_set_orientation (MX_BOX_LAYOUT (priv->hbox), MX_ORIENTATION_HORIZONTAL); clutter_actor_set_child_below_sibling (priv->hbox, priv->icon, NULL); clutter_container_child_set (CLUTTER_CONTAINER (priv->hbox), priv->label, "x-align", MX_ALIGN_END, "y-align", MX_ALIGN_MIDDLE, NULL); clutter_container_child_set (CLUTTER_CONTAINER (priv->hbox), priv->icon, "x-align", MX_ALIGN_START, "y-align", MX_ALIGN_MIDDLE, NULL); break; } }
const gchar * mex_column_get_icon_name (MexColumn *column) { g_return_val_if_fail (MEX_IS_COLUMN (column), NULL); return mx_icon_get_icon_name (MX_ICON (column->priv->icon)); }