From 0fca70768ae218e08df33470e57037817b09f024 Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Fri, 8 Jul 2022 16:25:21 -0300 Subject: [PATCH] carousel: Make MctCarouselItem subclass GtkButton And add a setter to its internal child. --- malcontent-control/carousel.c | 21 +++++++++++++-------- malcontent-control/carousel.css | 2 +- malcontent-control/carousel.h | 7 +++++-- malcontent-control/user-selector.c | 2 +- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/malcontent-control/carousel.c b/malcontent-control/carousel.c index c6ac594..21e28b9 100644 --- a/malcontent-control/carousel.c +++ b/malcontent-control/carousel.c @@ -30,12 +30,12 @@ #define ARROW_SIZE 20 struct _MctCarouselItem { - GtkRadioButton parent; + GtkButton parent; gint page; }; -G_DEFINE_TYPE (MctCarouselItem, mct_carousel_item, GTK_TYPE_RADIO_BUTTON) +G_DEFINE_TYPE (MctCarouselItem, mct_carousel_item, GTK_TYPE_BUTTON) GtkWidget * mct_carousel_item_new (void) @@ -43,17 +43,24 @@ mct_carousel_item_new (void) return g_object_new (MCT_TYPE_CAROUSEL_ITEM, NULL); } +void +mct_carousel_item_set_child (MctCarouselItem *self, + GtkWidget *child) +{ + g_return_if_fail (MCT_IS_CAROUSEL_ITEM (self)); + + gtk_button_set_child (GTK_BUTTON (self), child); +} + static void mct_carousel_item_class_init (MctCarouselItemClass *klass) { + gtk_widget_class_set_css_name (GTK_WIDGET_CLASS (klass), "carousel-item"); } static void mct_carousel_item_init (MctCarouselItem *self) { - gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (self), FALSE); - gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (self)), - "carousel-item"); } struct _MctCarousel { @@ -318,9 +325,7 @@ mct_carousel_add (GtkContainer *container, self->children = g_list_append (self->children, widget); MCT_CAROUSEL_ITEM (widget)->page = get_last_page_number (self); - if (self->selected_item != NULL) - gtk_radio_button_join_group (GTK_RADIO_BUTTON (widget), GTK_RADIO_BUTTON (self->selected_item)); - g_signal_connect (widget, "button-press-event", G_CALLBACK (on_item_toggled), self); + g_signal_connect (item, "clicked", G_CALLBACK (on_item_toggled), self); last_box_is_full = ((g_list_length (self->children) - 1) % ITEMS_PER_PAGE == 0); if (last_box_is_full) diff --git a/malcontent-control/carousel.css b/malcontent-control/carousel.css index 738562c..1c414d6 100644 --- a/malcontent-control/carousel.css +++ b/malcontent-control/carousel.css @@ -22,7 +22,7 @@ margin-bottom: -2px; } -.carousel-item { +carousel-item { background: transparent; box-shadow: none; border: none; diff --git a/malcontent-control/carousel.h b/malcontent-control/carousel.h index db18e9e..37529d5 100644 --- a/malcontent-control/carousel.h +++ b/malcontent-control/carousel.h @@ -23,19 +23,22 @@ #pragma once -#include +#include G_BEGIN_DECLS #define MCT_TYPE_CAROUSEL_ITEM (mct_carousel_item_get_type ()) -G_DECLARE_FINAL_TYPE (MctCarouselItem, mct_carousel_item, MCT, CAROUSEL_ITEM, GtkRadioButton) +G_DECLARE_FINAL_TYPE (MctCarouselItem, mct_carousel_item, MCT, CAROUSEL_ITEM, GtkButton) #define MCT_TYPE_CAROUSEL (mct_carousel_get_type ()) G_DECLARE_FINAL_TYPE (MctCarousel, mct_carousel, MCT, CAROUSEL, GtkRevealer) GtkWidget *mct_carousel_item_new (void); +void mct_carousel_item_set_child (MctCarouselItem *self, + GtkWidget *child); + MctCarousel *mct_carousel_new (void); void mct_carousel_purge_items (MctCarousel *self); diff --git a/malcontent-control/user-selector.c b/malcontent-control/user-selector.c index 2f772c9..1575d3c 100644 --- a/malcontent-control/user-selector.c +++ b/malcontent-control/user-selector.c @@ -455,7 +455,7 @@ user_added_cb (ActUserManager *user_manager, widget = create_carousel_entry (self, user); item = mct_carousel_item_new (); - gtk_container_add (GTK_CONTAINER (item), widget); + mct_carousel_item_set_child (MCT_CAROUSEL_ITEM (item), widget); g_object_set_data (G_OBJECT (item), "uid", GINT_TO_POINTER (act_user_get_uid (user))); gtk_container_add (GTK_CONTAINER (self->carousel), item);