Add elementary scrolling support to the view

This commit is contained in:
Přemysl Eric Janouch 2021-11-09 06:55:00 +01:00
parent a135d6f332
commit ed39a9b434
Signed by: p
GPG Key ID: A0420B94F92B9493
2 changed files with 14 additions and 13 deletions

View File

@ -60,21 +60,15 @@ static void
fastiv_view_get_preferred_height(
GtkWidget *widget, gint *minimum, gint *natural)
{
*minimum = 0;
*natural = 0;
FastivView *self = FASTIV_VIEW(widget);
*natural = get_display_height(self);
*minimum = *natural = get_display_height(self);
}
static void
fastiv_view_get_preferred_width(GtkWidget *widget, gint *minimum, gint *natural)
{
*minimum = 0;
*natural = 0;
FastivView *self = FASTIV_VIEW(widget);
*natural = get_display_width(self);
*minimum = *natural = get_display_width(self);
}
static void
@ -207,6 +201,7 @@ fastiv_view_open(FastivView *self, const gchar *path, GError **error)
cairo_surface_destroy(self->surface);
self->surface = surface;
self->scale = 1.0;
gtk_widget_queue_resize(GTK_WIDGET(self));
return TRUE;
}

View File

@ -63,6 +63,7 @@ struct {
GtkWidget *window;
GtkWidget *stack;
GtkWidget *view;
GtkWidget *view_scroller;
GtkWidget *browser;
GtkWidget *browser_scroller;
} g;
@ -149,7 +150,7 @@ open(const gchar *path)
}
gtk_window_set_title(GTK_WINDOW(g.window), path);
gtk_stack_set_visible_child(GTK_STACK(g.stack), g.view);
gtk_stack_set_visible_child(GTK_STACK(g.stack), g.view_scroller);
gchar *basename = g_path_get_basename(path);
g_free(g.basename);
@ -281,9 +282,10 @@ on_key_press(G_GNUC_UNUSED GtkWidget *widget, GdkEvent *event,
case GDK_KEY_Tab:
case GDK_KEY_Return:
gtk_stack_set_visible_child(GTK_STACK(g.stack),
gtk_stack_get_visible_child(GTK_STACK(g.stack)) == g.view
gtk_stack_get_visible_child(GTK_STACK(g.stack)) ==
g.view_scroller
? g.browser_scroller
: g.view);
: g.view_scroller);
return TRUE;
}
}
@ -328,8 +330,12 @@ main(int argc, char *argv[])
gtk_style_context_add_provider_for_screen(gdk_screen_get_default(),
GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
g.view_scroller = gtk_scrolled_window_new(NULL, NULL);
g.view = g_object_new(FASTIV_TYPE_VIEW, NULL);
gtk_widget_show_all(g.view);
gtk_widget_set_vexpand(g.view, TRUE);
gtk_widget_set_hexpand(g.view, TRUE);
gtk_container_add(GTK_CONTAINER(g.view_scroller), g.view);
gtk_widget_show_all(g.view_scroller);
g.browser_scroller = gtk_scrolled_window_new(NULL, NULL);
g.browser = g_object_new(FASTIV_TYPE_BROWSER, NULL);
@ -344,7 +350,7 @@ main(int argc, char *argv[])
g.stack = gtk_stack_new();
gtk_stack_set_transition_type(
GTK_STACK(g.stack), GTK_STACK_TRANSITION_TYPE_NONE);
gtk_container_add(GTK_CONTAINER(g.stack), g.view);
gtk_container_add(GTK_CONTAINER(g.stack), g.view_scroller);
gtk_container_add(GTK_CONTAINER(g.stack), g.browser_scroller);
g.window = gtk_window_new(GTK_WINDOW_TOPLEVEL);