2015-02-12 17:09:13 +00:00
|
|
|
/* Stack Sidebar
|
2014-08-23 16:38:42 +00:00
|
|
|
*
|
2015-02-12 17:09:13 +00:00
|
|
|
* GtkStackSidebar provides an automatic sidebar widget to control
|
|
|
|
* navigation of a GtkStack object. This widget automatically updates it
|
|
|
|
* content based on what is presently available in the GtkStack object,
|
|
|
|
* and using the "title" child property to set the display labels.
|
2014-08-23 16:38:42 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <glib/gi18n.h>
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
do_sidebar (GtkWidget *do_widget)
|
|
|
|
{
|
2015-06-28 13:23:28 +00:00
|
|
|
static GtkWidget *window = NULL;
|
2014-08-23 16:38:42 +00:00
|
|
|
GtkWidget *sidebar;
|
|
|
|
GtkWidget *stack;
|
|
|
|
GtkWidget *box;
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkWidget *header;
|
2020-07-24 18:40:36 +00:00
|
|
|
const char * pages[] = {
|
2019-02-05 09:19:57 +00:00
|
|
|
"Welcome to GTK",
|
2015-02-12 17:09:13 +00:00
|
|
|
"GtkStackSidebar Widget",
|
2014-10-02 21:57:59 +00:00
|
|
|
"Automatic navigation",
|
|
|
|
"Consistent appearance",
|
|
|
|
"Scrolling",
|
|
|
|
"Page 6",
|
|
|
|
"Page 7",
|
|
|
|
"Page 8",
|
|
|
|
"Page 9",
|
|
|
|
NULL
|
|
|
|
};
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *c = NULL;
|
2014-08-23 16:38:42 +00:00
|
|
|
guint i;
|
|
|
|
|
|
|
|
if (!window)
|
|
|
|
{
|
2020-02-14 19:55:36 +00:00
|
|
|
window = gtk_window_new ();
|
2014-08-23 16:38:42 +00:00
|
|
|
gtk_window_set_resizable (GTK_WINDOW (window), TRUE);
|
|
|
|
gtk_widget_set_size_request (window, 500, 350);
|
|
|
|
|
|
|
|
header = gtk_header_bar_new ();
|
|
|
|
gtk_window_set_titlebar (GTK_WINDOW(window), header);
|
2015-06-20 01:59:15 +00:00
|
|
|
gtk_window_set_title (GTK_WINDOW(window), "Stack Sidebar");
|
2020-05-09 16:03:11 +00:00
|
|
|
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
|
2014-08-23 16:38:42 +00:00
|
|
|
|
|
|
|
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
2015-02-12 17:09:13 +00:00
|
|
|
sidebar = gtk_stack_sidebar_new ();
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), sidebar);
|
2014-08-23 16:38:42 +00:00
|
|
|
|
|
|
|
stack = gtk_stack_new ();
|
|
|
|
gtk_stack_set_transition_type (GTK_STACK (stack), GTK_STACK_TRANSITION_TYPE_SLIDE_UP_DOWN);
|
2015-02-12 17:09:13 +00:00
|
|
|
gtk_stack_sidebar_set_stack (GTK_STACK_SIDEBAR (sidebar), GTK_STACK (stack));
|
2019-10-06 11:31:15 +00:00
|
|
|
gtk_widget_set_hexpand (stack, TRUE);
|
2014-08-23 16:38:42 +00:00
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (box), stack);
|
2014-08-23 16:38:42 +00:00
|
|
|
|
|
|
|
for (i=0; (c = *(pages+i)) != NULL; i++ )
|
|
|
|
{
|
|
|
|
if (i == 0)
|
|
|
|
{
|
2019-04-01 22:49:09 +00:00
|
|
|
widget = gtk_image_new_from_icon_name ("org.gtk.Demo4");
|
2020-04-10 16:08:16 +00:00
|
|
|
gtk_widget_add_css_class (widget, "icon-dropshadow");
|
2014-08-23 16:38:42 +00:00
|
|
|
gtk_image_set_pixel_size (GTK_IMAGE (widget), 256);
|
2014-10-02 21:57:59 +00:00
|
|
|
}
|
|
|
|
else
|
2014-08-23 16:38:42 +00:00
|
|
|
{
|
|
|
|
widget = gtk_label_new (c);
|
|
|
|
}
|
|
|
|
gtk_stack_add_named (GTK_STACK (stack), widget, c);
|
2019-02-08 23:27:56 +00:00
|
|
|
g_object_set (gtk_stack_get_page (GTK_STACK (stack), widget), "title", c, NULL);
|
2014-08-23 16:38:42 +00:00
|
|
|
}
|
|
|
|
|
2020-05-02 21:26:54 +00:00
|
|
|
gtk_window_set_child (GTK_WINDOW (window), box);
|
2014-08-23 16:38:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!gtk_widget_get_visible (window))
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (window);
|
2014-08-23 16:38:42 +00:00
|
|
|
else
|
2020-05-09 14:26:22 +00:00
|
|
|
gtk_window_destroy (GTK_WINDOW (window));
|
2014-08-23 16:38:42 +00:00
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|