From 222f59764a39a56666e199de124552be37d08999 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93scar=20Fern=C3=A1ndez=20D=C3=ADaz?= <42654671+oscfdezdz@users.noreply.github.com> Date: Sat, 11 Jan 2025 17:26:39 +0100 Subject: [PATCH] detail-view: Port comments section to AdwWrapBox Fix https://github.com/mjakeman/extension-manager/issues/244 --- src/exm-comment-tile.blp | 9 ++++++- src/exm-comment-tile.c | 6 +++-- src/exm-detail-view.blp | 15 +++++------- src/exm-detail-view.c | 53 ++++++++++++++++++++-------------------- 4 files changed, 44 insertions(+), 39 deletions(-) diff --git a/src/exm-comment-tile.blp b/src/exm-comment-tile.blp index bce9fce7..cf444d50 100644 --- a/src/exm-comment-tile.blp +++ b/src/exm-comment-tile.blp @@ -5,6 +5,8 @@ template $ExmCommentTile: Gtk.Widget { "comment-tile" ] + focusable: true; + Gtk.Box { orientation: vertical; @@ -16,8 +18,11 @@ template $ExmCommentTile: Gtk.Widget { "heading" ] - xalign: 0; label: bind template.comment as <$ExmComment>.author; + max-width-chars: 20; + wrap: true; + wrap-mode: word; + xalign: 0; } Gtk.Label author_badge { @@ -26,6 +31,7 @@ template $ExmCommentTile: Gtk.Widget { ] label: _("Author"); + valign: center; visible: bind template.comment as <$ExmComment>.is_extension_creator; } @@ -48,6 +54,7 @@ template $ExmCommentTile: Gtk.Widget { wrap: true; wrap-mode: word_char; xalign: 0; + max-width-chars: 30; } Gtk.Label date { diff --git a/src/exm-comment-tile.c b/src/exm-comment-tile.c index b90f5d00..7cc3b6b4 100644 --- a/src/exm-comment-tile.c +++ b/src/exm-comment-tile.c @@ -1,6 +1,7 @@ -/* exm-comment-tile.c +/* + * exm-comment-tile.c * - * Copyright 2022-2024 Matthew Jakeman + * Copyright 2022-2025 Matthew Jakeman * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -157,6 +158,7 @@ exm_comment_tile_class_init (ExmCommentTileClass *klass) gtk_widget_class_bind_template_child (widget_class, ExmCommentTile, date); gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT); + gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_COMMENT); } static void diff --git a/src/exm-detail-view.blp b/src/exm-detail-view.blp index 1ca9eddf..91864818 100644 --- a/src/exm-detail-view.blp +++ b/src/exm-detail-view.blp @@ -24,7 +24,6 @@ template $ExmDetailView: Adw.NavigationPage { header_suffix.orientation: vertical; header_suffix.spacing: 12; ext_install.halign: start; - comment_box.min-children-per-line: 1; } apply => $breakpoint_apply_cb() swapped; @@ -297,19 +296,17 @@ template $ExmDetailView: Adw.NavigationPage { child: Gtk.Box { orientation: vertical; - Gtk.FlowBox comment_box { - min-children-per-line: 2; - max-children-per-line: 2; - homogeneous: true; - selection-mode: none; - row-spacing: 12; - column-spacing: 12; + Adw.WrapBox comment_box { + orientation: vertical; + child-spacing: 12; + line-homogeneous: true; + line-spacing: 12; } Gtk.Button show_more_btn { label: _("_Show All Reviews"); halign: center; - margin-top: 10; + margin-top: 12; use-underline: true; } }; diff --git a/src/exm-detail-view.c b/src/exm-detail-view.c index 6988d4ef..5776b49c 100644 --- a/src/exm-detail-view.c +++ b/src/exm-detail-view.c @@ -71,7 +71,7 @@ struct _ExmDetailView ExmInfoBar *ext_info_bar; GtkScrolledWindow *scroll_area; GtkStack *comment_stack; - GtkFlowBox *comment_box; + AdwWrapBox *comment_box; GtkButton *show_more_btn; AdwActionRow *link_homepage; @@ -209,17 +209,13 @@ queue_resolve_image (ExmDetailView *self, g_object_ref (self)); } -static GtkWidget * -comment_factory (ExmComment *comment, - gpointer user_data G_GNUC_UNUSED) +static void +delete_comment_tiles (ExmDetailView *self) { - GtkWidget *tile; - - tile = gtk_flow_box_child_new (); - gtk_widget_add_css_class (tile, "card"); - gtk_flow_box_child_set_child (GTK_FLOW_BOX_CHILD (tile), GTK_WIDGET (exm_comment_tile_new (comment))); + GtkWidget *child; - return tile; + while ((child = gtk_widget_get_first_child (GTK_WIDGET (self->comment_box))) != NULL) + adw_wrap_box_remove (self->comment_box, child); } static void @@ -243,9 +239,16 @@ on_get_comments (GObject *source, else gtk_stack_set_visible_child_name (self->comment_stack, "page_comments"); - gtk_flow_box_bind_model (self->comment_box, model, - (GtkFlowBoxCreateWidgetFunc) comment_factory, - g_object_ref (self), g_object_unref); + delete_comment_tiles (self); + + for (guint i = 0; i < g_list_model_get_n_items (model); i++) + { + ExmComment *comment = g_list_model_get_item (model, i); + GtkWidget *tile = GTK_WIDGET (exm_comment_tile_new (comment)); + gtk_widget_add_css_class (tile, "card"); + adw_wrap_box_append (self->comment_box, tile); + g_object_unref (comment); + } } static void @@ -287,20 +290,6 @@ install_remote (GtkButton *button, "(sb)", self->uuid, warn); } -static void -delete_donation_rows (ExmDetailView *self) -{ - GtkWidget *row; - - for (GList *iter = self->donation_rows_list; iter != NULL; iter = g_list_next (iter)) { - row = GTK_WIDGET (iter->data); - adw_expander_row_remove (self->links_donations, row); - } - - g_list_free (self->donation_rows_list); - self->donation_rows_list = NULL; -} - static void new_donation_row (ExmDetailView *self, int num_donation) @@ -325,6 +314,16 @@ new_donation_row (ExmDetailView *self, self->donation_rows_list = g_list_append (self->donation_rows_list, row); } +static void +delete_donation_rows (ExmDetailView *self) +{ + for (GList *iter = self->donation_rows_list; iter != NULL; iter = g_list_next (iter)) + adw_expander_row_remove (self->links_donations, GTK_WIDGET (iter->data)); + + g_list_free (self->donation_rows_list); + self->donation_rows_list = NULL; +} + static void update_donation_rows (ExmDetailView *self, gchar **donation_urls)