Making listviewitems on clicked to send us to a new screen.

This commit is contained in:
sergiotarxz 2021-10-31 20:42:58 +01:00
parent b9e7a2952c
commit 4c492a5791
3 changed files with 43 additions and 11 deletions

View File

@ -1,4 +1,5 @@
#include <gtk/gtk.h>
#include <adwaita.h>
GtkListView *
create_list_view_mangas (GListStore *mangas);
create_list_view_mangas (GListStore *mangas, AdwLeaflet *views_leaflet);

View File

@ -1,4 +1,6 @@
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <adwaita.h>
#include <openmg/manga.h>
#include <openmg/util/soup.h>
@ -12,12 +14,30 @@ setup_list_view_mangas (GtkSignalListItemFactory *factory,
GtkListItem *list_item,
gpointer user_data);
typedef struct {
GListStore *mangas;
AdwLeaflet *views_leaflet;
} MangaPressedValues;
static void
manga_selected (GtkListView *list_view,
guint position,
gpointer user_data) {
MangaPressedValues *manga_pressed_values = (MangaPressedValues *) user_data;
AdwLeaflet *views_leaflet = manga_pressed_values->views_leaflet;
GtkBox *box = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 0));
printf ("hello world\n");
adw_leaflet_append (views_leaflet, GTK_WIDGET (box));
adw_leaflet_navigate (views_leaflet, ADW_NAVIGATION_DIRECTION_FORWARD);
}
static void
setup_list_view_mangas (GtkSignalListItemFactory *factory,
GtkListItem *list_item,
gpointer user_data) {
MgManga *manga = gtk_list_item_get_item (list_item);
GtkBox *box = GTK_BOX (gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0));
GtkWidget *label = gtk_label_new (mg_manga_get_title (manga));
GtkWidget *picture;
@ -54,14 +74,26 @@ setup_list_view_mangas (GtkSignalListItemFactory *factory,
}
GtkListView *
create_list_view_mangas (GListStore *mangas) {
create_list_view_mangas (GListStore *mangas, AdwLeaflet *views_leaflet) {
GtkSingleSelection *selection = gtk_single_selection_new (G_LIST_MODEL (mangas));
GtkListItemFactory *factory = gtk_signal_list_item_factory_new ();
MangaPressedValues *manga_pressed_values = NULL;
GtkListView *list_view_manga = NULL;
manga_pressed_values = g_malloc (sizeof *manga_pressed_values);
manga_pressed_values->mangas = mangas;
manga_pressed_values->views_leaflet = views_leaflet;
g_signal_connect (G_OBJECT (factory), "bind",
G_CALLBACK (setup_list_view_mangas),
NULL);
return GTK_LIST_VIEW (gtk_list_view_new (GTK_SELECTION_MODEL (selection),
views_leaflet);
list_view_manga = GTK_LIST_VIEW (gtk_list_view_new (GTK_SELECTION_MODEL (selection),
factory));
g_signal_connect (G_OBJECT (list_view_manga), "activate",
G_CALLBACK (manga_selected), manga_pressed_values);
return list_view_manga;
}
static void

View File

@ -28,7 +28,7 @@ activate (AdwApplication *app,
create_headerbar (box);
mangas = mg_backend_readmng_get_featured_manga (readmng);
list_view = create_list_view_mangas (mangas);
list_view = create_list_view_mangas (mangas, views_leaflet);
scroll = gtk_scrolled_window_new ();
gtk_widget_set_valign (scroll, GTK_ALIGN_FILL);
@ -37,7 +37,6 @@ activate (AdwApplication *app,
adw_leaflet_append (views_leaflet, scroll);
adw_leaflet_set_can_unfold (views_leaflet, false);
// adw_leaflet_set_visible_child (views_leaflet, scroll);
gtk_box_append (box, GTK_WIDGET (views_leaflet));