Add elementary scrolling support to the view
This commit is contained in:
parent
a135d6f332
commit
ed39a9b434
|
@ -60,21 +60,15 @@ static void
|
||||||
fastiv_view_get_preferred_height(
|
fastiv_view_get_preferred_height(
|
||||||
GtkWidget *widget, gint *minimum, gint *natural)
|
GtkWidget *widget, gint *minimum, gint *natural)
|
||||||
{
|
{
|
||||||
*minimum = 0;
|
|
||||||
*natural = 0;
|
|
||||||
|
|
||||||
FastivView *self = FASTIV_VIEW(widget);
|
FastivView *self = FASTIV_VIEW(widget);
|
||||||
*natural = get_display_height(self);
|
*minimum = *natural = get_display_height(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
fastiv_view_get_preferred_width(GtkWidget *widget, gint *minimum, gint *natural)
|
fastiv_view_get_preferred_width(GtkWidget *widget, gint *minimum, gint *natural)
|
||||||
{
|
{
|
||||||
*minimum = 0;
|
|
||||||
*natural = 0;
|
|
||||||
|
|
||||||
FastivView *self = FASTIV_VIEW(widget);
|
FastivView *self = FASTIV_VIEW(widget);
|
||||||
*natural = get_display_width(self);
|
*minimum = *natural = get_display_width(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -207,6 +201,7 @@ fastiv_view_open(FastivView *self, const gchar *path, GError **error)
|
||||||
cairo_surface_destroy(self->surface);
|
cairo_surface_destroy(self->surface);
|
||||||
|
|
||||||
self->surface = surface;
|
self->surface = surface;
|
||||||
|
self->scale = 1.0;
|
||||||
gtk_widget_queue_resize(GTK_WIDGET(self));
|
gtk_widget_queue_resize(GTK_WIDGET(self));
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
16
fastiv.c
16
fastiv.c
|
@ -63,6 +63,7 @@ struct {
|
||||||
GtkWidget *window;
|
GtkWidget *window;
|
||||||
GtkWidget *stack;
|
GtkWidget *stack;
|
||||||
GtkWidget *view;
|
GtkWidget *view;
|
||||||
|
GtkWidget *view_scroller;
|
||||||
GtkWidget *browser;
|
GtkWidget *browser;
|
||||||
GtkWidget *browser_scroller;
|
GtkWidget *browser_scroller;
|
||||||
} g;
|
} g;
|
||||||
|
@ -149,7 +150,7 @@ open(const gchar *path)
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_window_set_title(GTK_WINDOW(g.window), 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);
|
gchar *basename = g_path_get_basename(path);
|
||||||
g_free(g.basename);
|
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_Tab:
|
||||||
case GDK_KEY_Return:
|
case GDK_KEY_Return:
|
||||||
gtk_stack_set_visible_child(GTK_STACK(g.stack),
|
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.browser_scroller
|
||||||
: g.view);
|
: g.view_scroller);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -328,8 +330,12 @@ main(int argc, char *argv[])
|
||||||
gtk_style_context_add_provider_for_screen(gdk_screen_get_default(),
|
gtk_style_context_add_provider_for_screen(gdk_screen_get_default(),
|
||||||
GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
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);
|
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_scroller = gtk_scrolled_window_new(NULL, NULL);
|
||||||
g.browser = g_object_new(FASTIV_TYPE_BROWSER, NULL);
|
g.browser = g_object_new(FASTIV_TYPE_BROWSER, NULL);
|
||||||
|
@ -344,7 +350,7 @@ main(int argc, char *argv[])
|
||||||
g.stack = gtk_stack_new();
|
g.stack = gtk_stack_new();
|
||||||
gtk_stack_set_transition_type(
|
gtk_stack_set_transition_type(
|
||||||
GTK_STACK(g.stack), GTK_STACK_TRANSITION_TYPE_NONE);
|
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);
|
gtk_container_add(GTK_CONTAINER(g.stack), g.browser_scroller);
|
||||||
|
|
||||||
g.window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
g.window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||||
|
|
Loading…
Reference in New Issue