Skip to content

Commit

Permalink
detail-view: Port comments section to AdwWrapBox
Browse files Browse the repository at this point in the history
Fix #244
  • Loading branch information
oscfdezdz committed Jan 15, 2025
1 parent 3d0580c commit 16d93b9
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 44 deletions.
10 changes: 9 additions & 1 deletion src/exm-comment-tile.blp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ using Gtk 4.0;

template $ExmCommentTile: Gtk.Widget {
styles [
"card",
"comment-tile"
]

focusable: true;

Gtk.Box {
orientation: vertical;

Expand All @@ -16,8 +19,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 {
Expand All @@ -26,6 +32,7 @@ template $ExmCommentTile: Gtk.Widget {
]

label: _("Author");
valign: center;
visible: bind template.comment as <$ExmComment>.is_extension_creator;
}

Expand All @@ -48,6 +55,7 @@ template $ExmCommentTile: Gtk.Widget {
wrap: true;
wrap-mode: word_char;
xalign: 0;
max-width-chars: 30;
}

Gtk.Label date {
Expand Down
6 changes: 4 additions & 2 deletions src/exm-comment-tile.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* exm-comment-tile.c
/*
* exm-comment-tile.c
*
* Copyright 2022-2024 Matthew Jakeman <[email protected]>
* Copyright 2022-2025 Matthew Jakeman <[email protected]>
*
* 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
Expand Down Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions src/exm-detail-view.blp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Adw.SpinnerPaintable spinner {
}

template $ExmDetailView: Adw.NavigationPage {
hidden => $remove_donations();
hidden => $remove_comments();

Adw.ToolbarView {
[top]
Adw.HeaderBar header_bar {
Expand All @@ -24,7 +27,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;
Expand Down Expand Up @@ -297,19 +299,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;
}
};
Expand Down
63 changes: 31 additions & 32 deletions src/exm-detail-view.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -209,19 +209,6 @@ queue_resolve_image (ExmDetailView *self,
g_object_ref (self));
}

static GtkWidget *
comment_factory (ExmComment *comment,
gpointer user_data G_GNUC_UNUSED)
{
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)));

return tile;
}

static void
on_get_comments (GObject *source,
GAsyncResult *res,
Expand All @@ -243,9 +230,13 @@ 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);
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));
adw_wrap_box_append (self->comment_box, tile);
g_object_unref (comment);
}
}

static void
Expand Down Expand Up @@ -287,20 +278,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)
Expand Down Expand Up @@ -330,7 +307,6 @@ update_donation_rows (ExmDetailView *self,
gchar **donation_urls)
{
gtk_widget_set_visible (GTK_WIDGET (self->links_donations), FALSE);
delete_donation_rows (self);

if (donation_urls == NULL || donation_urls[0] == NULL)
return;
Expand Down Expand Up @@ -626,6 +602,27 @@ screenshot_view_cb (ExmDetailView *self)
adw_navigation_view_push_by_tag (parent, "screenshot-view");
}

static void
remove_donations (ExmDetailView *self,
gpointer user_data G_GNUC_UNUSED)
{
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
remove_comments (ExmDetailView *self,
gpointer user_data G_GNUC_UNUSED)
{
GtkWidget *child;

while ((child = gtk_widget_get_first_child (GTK_WIDGET (self->comment_box))) != NULL)
adw_wrap_box_remove (self->comment_box, child);
}

static void
exm_detail_view_class_init (ExmDetailViewClass *klass)
{
Expand Down Expand Up @@ -678,6 +675,8 @@ exm_detail_view_class_init (ExmDetailViewClass *klass)
gtk_widget_class_bind_template_callback (widget_class, breakpoint_apply_cb);
gtk_widget_class_bind_template_callback (widget_class, breakpoint_unapply_cb);
gtk_widget_class_bind_template_callback (widget_class, screenshot_view_cb);
gtk_widget_class_bind_template_callback (widget_class, remove_donations);
gtk_widget_class_bind_template_callback (widget_class, remove_comments);

gtk_widget_class_install_action (widget_class, "detail.open-extensions", NULL, (GtkWidgetActionActivateFunc) open_link);
gtk_widget_class_install_action (widget_class, "detail.open-homepage", NULL, (GtkWidgetActionActivateFunc) open_link);
Expand Down

0 comments on commit 16d93b9

Please sign in to comment.