|
40 | 40 |
|
41 | 41 | #include "st-button.h" |
42 | 42 |
|
| 43 | +#include "st-icon.h" |
43 | 44 | #include "st-enum-types.h" |
44 | 45 | #include "st-texture-cache.h" |
45 | 46 | #include "st-private.h" |
|
51 | 52 | PROP_0, |
52 | 53 |
|
53 | 54 | PROP_LABEL, |
| 55 | + PROP_ICON_NAME, |
54 | 56 | PROP_BUTTON_MASK, |
55 | 57 | PROP_TOGGLE_MODE, |
56 | 58 | PROP_CHECKED, |
@@ -316,6 +318,9 @@ st_button_set_property (GObject *gobject, |
316 | 318 | case PROP_LABEL: |
317 | 319 | st_button_set_label (button, g_value_get_string (value)); |
318 | 320 | break; |
| 321 | + case PROP_ICON_NAME: |
| 322 | + st_button_set_icon_name (button, g_value_get_string (value)); |
| 323 | + break; |
319 | 324 | case PROP_BUTTON_MASK: |
320 | 325 | st_button_set_button_mask (button, g_value_get_flags (value)); |
321 | 326 | break; |
@@ -346,6 +351,9 @@ st_button_get_property (GObject *gobject, |
346 | 351 | case PROP_LABEL: |
347 | 352 | g_value_set_string (value, priv->text); |
348 | 353 | break; |
| 354 | + case PROP_ICON_NAME: |
| 355 | + g_value_set_string (value, st_button_get_icon_name (ST_BUTTON (gobject))); |
| 356 | + break; |
349 | 357 | case PROP_BUTTON_MASK: |
350 | 358 | g_value_set_flags (value, priv->button_mask); |
351 | 359 | break; |
@@ -405,6 +413,12 @@ st_button_class_init (StButtonClass *klass) |
405 | 413 | NULL, G_PARAM_READWRITE); |
406 | 414 | g_object_class_install_property (gobject_class, PROP_LABEL, pspec); |
407 | 415 |
|
| 416 | + pspec = g_param_spec_string ("icon-name", |
| 417 | + "Icon name", |
| 418 | + "Icon name of the button", |
| 419 | + NULL, G_PARAM_READWRITE); |
| 420 | + g_object_class_install_property (gobject_class, PROP_ICON_NAME, pspec); |
| 421 | + |
408 | 422 | pspec = g_param_spec_flags ("button-mask", |
409 | 423 | "Button mask", |
410 | 424 | "Which buttons trigger the 'clicked' signal", |
@@ -553,6 +567,66 @@ st_button_set_label (StButton *button, |
553 | 567 | g_object_notify (G_OBJECT (button), "label"); |
554 | 568 | } |
555 | 569 |
|
| 570 | +/** |
| 571 | + * st_button_get_icon_name: |
| 572 | + * @button: a #StButton |
| 573 | + * |
| 574 | + * Get the icon name of the button. If the button isn't showing an icon, |
| 575 | + * the return value will be %NULL. |
| 576 | + * |
| 577 | + * Returns: (transfer none) (nullable): the icon name of the button |
| 578 | + */ |
| 579 | +const char * |
| 580 | +st_button_get_icon_name (StButton *button) |
| 581 | +{ |
| 582 | + ClutterActor *icon; |
| 583 | + |
| 584 | + g_return_val_if_fail (ST_IS_BUTTON (button), NULL); |
| 585 | + |
| 586 | + icon = st_bin_get_child (ST_BIN (button)); |
| 587 | + if (ST_IS_ICON (icon)) |
| 588 | + return st_icon_get_icon_name (ST_ICON (icon)); |
| 589 | + return NULL; |
| 590 | +} |
| 591 | + |
| 592 | +/** |
| 593 | + * st_button_set_icon_name: |
| 594 | + * @button: a #Stbutton |
| 595 | + * @icon_name: an icon name |
| 596 | + * |
| 597 | + * Adds an `StIcon` with the given icon name as a child. |
| 598 | + * |
| 599 | + * If @button already contains a child actor, that child will |
| 600 | + * be removed and replaced with the icon. |
| 601 | + */ |
| 602 | +void |
| 603 | +st_button_set_icon_name (StButton *button, |
| 604 | + const char *icon_name) |
| 605 | +{ |
| 606 | + ClutterActor *icon; |
| 607 | + |
| 608 | + g_return_if_fail (ST_IS_BUTTON (button)); |
| 609 | + g_return_if_fail (icon_name != NULL); |
| 610 | + |
| 611 | + icon = st_bin_get_child (ST_BIN (button)); |
| 612 | + |
| 613 | + if (ST_IS_ICON (icon)) |
| 614 | + { |
| 615 | + st_icon_set_icon_name (ST_ICON (icon), icon_name); |
| 616 | + } |
| 617 | + else |
| 618 | + { |
| 619 | + icon = g_object_new (ST_TYPE_ICON, |
| 620 | + "icon-name", icon_name, |
| 621 | + "x-align", CLUTTER_ACTOR_ALIGN_CENTER, |
| 622 | + "y-align", CLUTTER_ACTOR_ALIGN_CENTER, |
| 623 | + NULL); |
| 624 | + st_bin_set_child (ST_BIN (button), icon); |
| 625 | + } |
| 626 | + |
| 627 | + g_object_notify (G_OBJECT (button), "icon-name"); |
| 628 | +} |
| 629 | + |
556 | 630 | /** |
557 | 631 | * st_button_get_button_mask: |
558 | 632 | * @button: a #StButton |
|
0 commit comments