Making the previous button to hide while we are on the main view.

This commit is contained in:
sergiotarxz 2021-11-30 22:04:44 +01:00
parent 95f805f92f
commit ca63ee7449
2 changed files with 38 additions and 5 deletions

View File

@ -3,4 +3,5 @@
typedef struct { typedef struct {
AdwHeaderBar *header; AdwHeaderBar *header;
AdwLeaflet *views_leaflet; AdwLeaflet *views_leaflet;
GtkButton *previous;
} ControlsAdwaita; } ControlsAdwaita;

View File

@ -5,14 +5,21 @@
#include <openmg/backend/readmng.h> #include <openmg/backend/readmng.h>
#include <openmg/manga.h> #include <openmg/manga.h>
#include <openmg/view/controls.h>
#include <openmg/view/list_view_manga.h> #include <openmg/view/list_view_manga.h>
static AdwHeaderBar * static AdwHeaderBar *
create_headerbar (GtkBox *box, AdwLeaflet *views_leaflet); create_headerbar (GtkBox *box, AdwLeaflet *views_leaflet, GtkButton **out_previous);
static GtkBox * static GtkBox *
create_main_box (AdwApplicationWindow *window); create_main_box (AdwApplicationWindow *window);
static void static void
go_back_view (GtkButton *previous, gpointer user_data); go_back_view (GtkButton *previous, gpointer user_data);
static void
hide_main_view (GtkWidget *main_view,
gpointer user_data);
static void
show_main_view (GtkWidget *main_view,
gpointer user_data);
static void static void
activate (AdwApplication *app, activate (AdwApplication *app,
@ -29,6 +36,8 @@ activate (AdwApplication *app,
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); ControlsAdwaita *controls = g_malloc (sizeof *controls);
GtkButton *previous = NULL;
AdwHeaderBar *header_bar = create_headerbar (box, views_leaflet, &previous);
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
@ -41,13 +50,15 @@ activate (AdwApplication *app,
} }
swipe_back (views_leaflet, 1); swipe_back (views_leaflet, 1);
AdwHeaderBar *header_bar = create_headerbar (box, views_leaflet);
controls->header = header_bar; controls->header = header_bar;
controls->views_leaflet = views_leaflet; controls->views_leaflet = views_leaflet;
controls->previous = previous;
mangas = mg_backend_readmng_get_featured_manga (readmng); mangas = mg_backend_readmng_get_featured_manga (readmng);
list_view = create_list_view_mangas (mangas, controls); list_view = create_list_view_mangas (mangas, controls);
scroll = gtk_scrolled_window_new (); scroll = gtk_scrolled_window_new ();
g_signal_connect (scroll, "map", G_CALLBACK (show_main_view), controls);
g_signal_connect (scroll, "unmap", G_CALLBACK (hide_main_view), controls);
gtk_widget_set_valign (scroll, GTK_ALIGN_FILL); gtk_widget_set_valign (scroll, GTK_ALIGN_FILL);
gtk_widget_set_vexpand (scroll, 1); gtk_widget_set_vexpand (scroll, 1);
@ -73,8 +84,26 @@ create_main_box (AdwApplicationWindow *window) {
return GTK_BOX (box); return GTK_BOX (box);
} }
static void
show_main_view (GtkWidget *main_view,
gpointer user_data) {
ControlsAdwaita *controls = (ControlsAdwaita *) user_data;
GtkWidget *previous = GTK_WIDGET (controls->previous);
AdwHeaderBar *header = controls->header;
adw_header_bar_remove (header, previous);
}
static void
hide_main_view (GtkWidget *main_view,
gpointer user_data) {
ControlsAdwaita *controls = (ControlsAdwaita *) user_data;
GtkWidget *previous = GTK_WIDGET (controls->previous);
AdwHeaderBar *header = controls->header;
adw_header_bar_pack_start (header, previous);
}
static AdwHeaderBar * static AdwHeaderBar *
create_headerbar (GtkBox *box, AdwLeaflet *views_leaflet) { create_headerbar (GtkBox *box, AdwLeaflet *views_leaflet, GtkButton **out_previous) {
GtkWidget *title = GtkWidget *title =
adw_window_title_new ("Window", NULL); adw_window_title_new ("Window", NULL);
GtkWidget *header = GtkWidget *header =
@ -87,7 +116,10 @@ create_headerbar (GtkBox *box, AdwLeaflet *views_leaflet) {
g_signal_connect (G_OBJECT (previous), "clicked", G_CALLBACK (go_back_view), g_signal_connect (G_OBJECT (previous), "clicked", G_CALLBACK (go_back_view),
views_leaflet); views_leaflet);
adw_header_bar_pack_start (ADW_HEADER_BAR (header), previous); if (out_previous) {
*out_previous = GTK_BUTTON (previous);
g_object_ref (*out_previous);
}
return ADW_HEADER_BAR (header); return ADW_HEADER_BAR (header);
@ -98,7 +130,7 @@ go_back_view (GtkButton *previous, gpointer user_data) {
AdwLeaflet *views_leaflet = ADW_LEAFLET (user_data); AdwLeaflet *views_leaflet = ADW_LEAFLET (user_data);
adw_leaflet_navigate (views_leaflet, ADW_NAVIGATION_DIRECTION_BACK); adw_leaflet_navigate (views_leaflet, ADW_NAVIGATION_DIRECTION_BACK);
} }
int int
main_view_run (int argc, main_view_run (int argc,
char **argv) char **argv)
{ {