Reworking the details view to use the header bar instead of

plain buttons.
This commit is contained in:
sergiotarxz 2021-11-22 23:40:22 +01:00
parent 1630610354
commit f998953f13
5 changed files with 69 additions and 12 deletions

View File

@ -3,5 +3,7 @@
#include <openmg/manga.h>
#include <openmg/view/controls.h>
GtkBox *
create_detail_view (MgManga *manga, AdwLeaflet *views_leaflet);
create_detail_view (MgManga *manga, ControlsAdwaita *controls);

View File

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

View File

@ -13,6 +13,18 @@
#include <openmg/view/detail_manga.h>
#include <openmg/view/list_view_chapter.h>
typedef struct {
GtkWidget *reorder;
GtkWidget *hide_description;
AdwHeaderBar *header;
} HeaderButtons;
static void
hide_controls (GtkWidget *detail_view,
gpointer user_data);
static void
show_controls (GtkWidget *detail_view,
gpointer user_data);
static void
reverse_list (GtkButton *reverse_button,
gpointer user_data) {
@ -48,7 +60,9 @@ toggle_folded (GtkButton *toggle_folded_button,
}
GtkBox *
create_detail_view (MgManga *manga, AdwLeaflet *views_leaflet) {
create_detail_view (MgManga *manga, ControlsAdwaita *controls) {
AdwLeaflet *views_leaflet = controls->views_leaflet;
AdwHeaderBar *header = controls->header;
MgBackendReadmng *readmng = mg_backend_readmng_new ();
GtkWidget *scroll;
GtkBox *detail_view = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 0));
@ -68,6 +82,7 @@ create_detail_view (MgManga *manga, AdwLeaflet *views_leaflet) {
char *title_text = mg_util_xml_get_title_text (
xml_util, manga_title_text);
char *description_text;
HeaderButtons *buttons = g_malloc (sizeof *buttons);
scroll = gtk_scrolled_window_new ();
g_object_set_property_int (G_OBJECT (scroll), "vexpand", 1);
@ -100,11 +115,21 @@ create_detail_view (MgManga *manga, AdwLeaflet *views_leaflet) {
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (scroll), GTK_WIDGET (chapter_list));
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
gtk_box_append (detail_view, GTK_WIDGET (toggle_folded_button));
gtk_box_append (detail_view, scroll);
gtk_box_append (detail_view, GTK_WIDGET (reverse_list_button));
g_clear_object (&readmng);
buttons->header = header;
buttons->hide_description = GTK_WIDGET (toggle_folded_button);
buttons->reorder = GTK_WIDGET (reverse_list_button);
g_object_ref (G_OBJECT (reverse_list_button));
g_object_ref (G_OBJECT (toggle_folded_button));
g_signal_connect (detail_view, "map", G_CALLBACK (show_controls),
buttons);
g_signal_connect (detail_view, "unmap", G_CALLBACK (hide_controls),
buttons);
g_clear_object (&readmng);
g_free (url_image);
g_free (manga_title_text);
g_free (title_text);
@ -112,3 +137,21 @@ create_detail_view (MgManga *manga, AdwLeaflet *views_leaflet) {
g_clear_object (&xml_util);
return detail_view;
}
static void
hide_controls (GtkWidget *detail_view,
gpointer user_data) {
HeaderButtons *buttons = (HeaderButtons *) user_data;
AdwHeaderBar *header = buttons->header;
adw_header_bar_remove (header, GTK_WIDGET (buttons->hide_description));
adw_header_bar_remove (header, GTK_WIDGET (buttons->reorder));
}
static void
show_controls (GtkWidget *detail_view,
gpointer user_data) {
HeaderButtons *buttons = (HeaderButtons *) user_data;
AdwHeaderBar *header = buttons->header;
adw_header_bar_pack_end (header, GTK_WIDGET (buttons->hide_description));
adw_header_bar_pack_end (header, GTK_WIDGET (buttons->reorder));
}

View File

@ -9,6 +9,7 @@
#include <openmg/view/detail_manga.h>
#include <openmg/view/list_view_manga.h>
#include <openmg/view/picture.h>
#include <openmg/view/controls.h>
typedef struct {
GtkListView *list_view;
@ -24,7 +25,8 @@ static void
manga_selected (GtkListView *list_view,
guint position,
gpointer user_data) {
AdwLeaflet *views_leaflet = ADW_LEAFLET (user_data);
ControlsAdwaita *controls = (ControlsAdwaita *) user_data;
AdwLeaflet *views_leaflet = controls->views_leaflet;
GtkSingleSelection *selection = GTK_SINGLE_SELECTION
(gtk_list_view_get_model (list_view));
GListModel *mangas = gtk_single_selection_get_model (selection);
@ -39,7 +41,7 @@ manga_selected (GtkListView *list_view,
ADW_NAVIGATION_DIRECTION_FORWARD);
}
GtkBox *detail_view = create_detail_view (manga, views_leaflet);
GtkBox *detail_view = create_detail_view (manga, controls);
adw_leaflet_append (views_leaflet, GTK_WIDGET (detail_view));
adw_leaflet_navigate (views_leaflet, ADW_NAVIGATION_DIRECTION_FORWARD);
}
@ -66,7 +68,8 @@ setup_list_view_mangas (GtkSignalListItemFactory *factory,
}
GtkListView *
create_list_view_mangas (GListStore *mangas, AdwLeaflet *views_leaflet) {
create_list_view_mangas (GListStore *mangas, ControlsAdwaita *controls) {
AdwLeaflet *views_leaflet = controls->views_leaflet;
GtkSingleSelection *selection = gtk_single_selection_new (G_LIST_MODEL (mangas));
GtkListItemFactory *factory = gtk_signal_list_item_factory_new ();
GtkListView *list_view_manga = NULL;
@ -80,7 +83,8 @@ create_list_view_mangas (GListStore *mangas, AdwLeaflet *views_leaflet) {
g_object_set_property_int (G_OBJECT (list_view_manga),
"single-click-activate", 1);
g_signal_connect (G_OBJECT (list_view_manga), "activate",
G_CALLBACK (manga_selected), views_leaflet);
G_CALLBACK (manga_selected), controls);
return list_view_manga;
}

View File

@ -28,19 +28,25 @@ activate (AdwApplication *app,
GtkListView *list_view;
GtkWidget *scroll;
AdwLeaflet *views_leaflet = ADW_LEAFLET (adw_leaflet_new ());
ControlsAdwaita *controls = g_malloc (sizeof *controls);
typedef void (*swipe_back_t)(AdwLeaflet *, gboolean);
swipe_back_t swipe_back = (swipe_back_t) dlsym
(NULL, "adw_leaflet_set_can_navigate_back");
if (!swipe_back) {
swipe_back = (swipe_back_t) dlsym
(NULL, "adw_leaflet_set_can_swipe_back");
}
swipe_back (views_leaflet, 1);
create_headerbar (box, views_leaflet);
AdwHeaderBar *header_bar = create_headerbar (box, views_leaflet);
controls->header = header_bar;
controls->views_leaflet = views_leaflet;
mangas = mg_backend_readmng_get_featured_manga (readmng);
list_view = create_list_view_mangas (mangas, views_leaflet);
list_view = create_list_view_mangas (mangas, controls);
scroll = gtk_scrolled_window_new ();
gtk_widget_set_valign (scroll, GTK_ALIGN_FILL);