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 11, 2025
1 parent 91222ff commit 9865ae4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/exm-comment-tile.blp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ template $ExmCommentTile: Gtk.Widget {
wrap: true;
wrap-mode: word_char;
xalign: 0;
max-width-chars: 30;
}

Gtk.Label date {
Expand Down
17 changes: 8 additions & 9 deletions src/exm-detail-view.blp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Adw.SpinnerPaintable spinner {
}

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

Adw.ToolbarView {
[top]
Adw.HeaderBar header_bar {
Expand All @@ -24,7 +26,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 +298,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;
line-homogeneous: true;
child-spacing: 12;
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
28 changes: 24 additions & 4 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 @@ -243,9 +243,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 = comment_factory (comment, NULL);
adw_wrap_box_append (self->comment_box, tile);
g_object_unref (comment);
}
}

static void
Expand Down Expand Up @@ -626,6 +630,21 @@ screenshot_view_cb (ExmDetailView *self)
adw_navigation_view_push_by_tag (parent, "screenshot-view");
}

static void
remove_comments (ExmDetailView *self,
gpointer user_data G_GNUC_UNUSED)
{
GtkWidget *child;

child = gtk_widget_get_first_child (GTK_WIDGET (self->comment_box));

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

static void
exm_detail_view_class_init (ExmDetailViewClass *klass)
{
Expand Down Expand Up @@ -678,6 +697,7 @@ 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_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 9865ae4

Please sign in to comment.