forked from sergiotarxz/mangareader
Reworking the details view to use the header bar instead of
plain buttons.
This commit is contained in:
parent
1630610354
commit
f998953f13
@ -3,5 +3,7 @@
|
|||||||
|
|
||||||
#include <openmg/manga.h>
|
#include <openmg/manga.h>
|
||||||
|
|
||||||
|
#include <openmg/view/controls.h>
|
||||||
|
|
||||||
GtkBox *
|
GtkBox *
|
||||||
create_detail_view (MgManga *manga, AdwLeaflet *views_leaflet);
|
create_detail_view (MgManga *manga, ControlsAdwaita *controls);
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
#include <adwaita.h>
|
#include <adwaita.h>
|
||||||
|
|
||||||
|
#include <openmg/view/controls.h>
|
||||||
|
|
||||||
GtkListView *
|
GtkListView *
|
||||||
create_list_view_mangas (GListStore *mangas, AdwLeaflet *views_leaflet);
|
create_list_view_mangas (GListStore *mangas, ControlsAdwaita *controls);
|
||||||
|
@ -13,6 +13,18 @@
|
|||||||
#include <openmg/view/detail_manga.h>
|
#include <openmg/view/detail_manga.h>
|
||||||
#include <openmg/view/list_view_chapter.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
|
static void
|
||||||
reverse_list (GtkButton *reverse_button,
|
reverse_list (GtkButton *reverse_button,
|
||||||
gpointer user_data) {
|
gpointer user_data) {
|
||||||
@ -48,7 +60,9 @@ toggle_folded (GtkButton *toggle_folded_button,
|
|||||||
}
|
}
|
||||||
|
|
||||||
GtkBox *
|
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 ();
|
MgBackendReadmng *readmng = mg_backend_readmng_new ();
|
||||||
GtkWidget *scroll;
|
GtkWidget *scroll;
|
||||||
GtkBox *detail_view = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 0));
|
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 (
|
char *title_text = mg_util_xml_get_title_text (
|
||||||
xml_util, manga_title_text);
|
xml_util, manga_title_text);
|
||||||
char *description_text;
|
char *description_text;
|
||||||
|
HeaderButtons *buttons = g_malloc (sizeof *buttons);
|
||||||
|
|
||||||
scroll = gtk_scrolled_window_new ();
|
scroll = gtk_scrolled_window_new ();
|
||||||
g_object_set_property_int (G_OBJECT (scroll), "vexpand", 1);
|
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_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_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, 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 (url_image);
|
||||||
g_free (manga_title_text);
|
g_free (manga_title_text);
|
||||||
g_free (title_text);
|
g_free (title_text);
|
||||||
@ -112,3 +137,21 @@ create_detail_view (MgManga *manga, AdwLeaflet *views_leaflet) {
|
|||||||
g_clear_object (&xml_util);
|
g_clear_object (&xml_util);
|
||||||
return detail_view;
|
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));
|
||||||
|
}
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include <openmg/view/detail_manga.h>
|
#include <openmg/view/detail_manga.h>
|
||||||
#include <openmg/view/list_view_manga.h>
|
#include <openmg/view/list_view_manga.h>
|
||||||
#include <openmg/view/picture.h>
|
#include <openmg/view/picture.h>
|
||||||
|
#include <openmg/view/controls.h>
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
GtkListView *list_view;
|
GtkListView *list_view;
|
||||||
@ -24,7 +25,8 @@ static void
|
|||||||
manga_selected (GtkListView *list_view,
|
manga_selected (GtkListView *list_view,
|
||||||
guint position,
|
guint position,
|
||||||
gpointer user_data) {
|
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
|
GtkSingleSelection *selection = GTK_SINGLE_SELECTION
|
||||||
(gtk_list_view_get_model (list_view));
|
(gtk_list_view_get_model (list_view));
|
||||||
GListModel *mangas = gtk_single_selection_get_model (selection);
|
GListModel *mangas = gtk_single_selection_get_model (selection);
|
||||||
@ -39,7 +41,7 @@ manga_selected (GtkListView *list_view,
|
|||||||
ADW_NAVIGATION_DIRECTION_FORWARD);
|
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_append (views_leaflet, GTK_WIDGET (detail_view));
|
||||||
adw_leaflet_navigate (views_leaflet, ADW_NAVIGATION_DIRECTION_FORWARD);
|
adw_leaflet_navigate (views_leaflet, ADW_NAVIGATION_DIRECTION_FORWARD);
|
||||||
}
|
}
|
||||||
@ -66,7 +68,8 @@ setup_list_view_mangas (GtkSignalListItemFactory *factory,
|
|||||||
}
|
}
|
||||||
|
|
||||||
GtkListView *
|
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));
|
GtkSingleSelection *selection = gtk_single_selection_new (G_LIST_MODEL (mangas));
|
||||||
GtkListItemFactory *factory = gtk_signal_list_item_factory_new ();
|
GtkListItemFactory *factory = gtk_signal_list_item_factory_new ();
|
||||||
GtkListView *list_view_manga = NULL;
|
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),
|
g_object_set_property_int (G_OBJECT (list_view_manga),
|
||||||
"single-click-activate", 1);
|
"single-click-activate", 1);
|
||||||
|
|
||||||
|
|
||||||
g_signal_connect (G_OBJECT (list_view_manga), "activate",
|
g_signal_connect (G_OBJECT (list_view_manga), "activate",
|
||||||
G_CALLBACK (manga_selected), views_leaflet);
|
G_CALLBACK (manga_selected), controls);
|
||||||
return list_view_manga;
|
return list_view_manga;
|
||||||
}
|
}
|
||||||
|
@ -28,19 +28,25 @@ activate (AdwApplication *app,
|
|||||||
GtkListView *list_view;
|
GtkListView *list_view;
|
||||||
GtkWidget *scroll;
|
GtkWidget *scroll;
|
||||||
AdwLeaflet *views_leaflet = ADW_LEAFLET (adw_leaflet_new ());
|
AdwLeaflet *views_leaflet = ADW_LEAFLET (adw_leaflet_new ());
|
||||||
|
ControlsAdwaita *controls = g_malloc (sizeof *controls);
|
||||||
|
|
||||||
typedef void (*swipe_back_t)(AdwLeaflet *, gboolean);
|
typedef void (*swipe_back_t)(AdwLeaflet *, gboolean);
|
||||||
swipe_back_t swipe_back = (swipe_back_t) dlsym
|
swipe_back_t swipe_back = (swipe_back_t) dlsym
|
||||||
(NULL, "adw_leaflet_set_can_navigate_back");
|
(NULL, "adw_leaflet_set_can_navigate_back");
|
||||||
|
|
||||||
|
|
||||||
if (!swipe_back) {
|
if (!swipe_back) {
|
||||||
swipe_back = (swipe_back_t) dlsym
|
swipe_back = (swipe_back_t) dlsym
|
||||||
(NULL, "adw_leaflet_set_can_swipe_back");
|
(NULL, "adw_leaflet_set_can_swipe_back");
|
||||||
}
|
}
|
||||||
swipe_back (views_leaflet, 1);
|
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);
|
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 ();
|
scroll = gtk_scrolled_window_new ();
|
||||||
|
|
||||||
gtk_widget_set_valign (scroll, GTK_ALIGN_FILL);
|
gtk_widget_set_valign (scroll, GTK_ALIGN_FILL);
|
||||||
|
Loading…
Reference in New Issue
Block a user