Commit 443459b5 authored by Matthias Clasen's avatar Matthias Clasen

Add GtkRevealer

This is a widget that can hide or show (ie reveal) its child
in an animated fashion.

This widget was initially developed in libgd.
parent d82257e1
......@@ -314,6 +314,7 @@ gtk_public_h_sources = \
gtkrecentchooserwidget.h \
gtkrecentfilter.h \
gtkrecentmanager.h \
gtkrevealer.h \
gtkscale.h \
gtkscalebutton.h \
gtkscrollable.h \
......@@ -815,6 +816,7 @@ gtk_base_c_sources = \
gtkrecentfilter.c \
gtkrecentmanager.c \
gtkresources.c \
gtkrevealer.c \
gtkroundedbox.c \
gtkscale.c \
gtkscalebutton.c \
......
......@@ -163,6 +163,7 @@
#include <gtk/gtkrecentchooserwidget.h>
#include <gtk/gtkrecentfilter.h>
#include <gtk/gtkrecentmanager.h>
#include <gtk/gtkrevealer.h>
#include <gtk/gtkscale.h>
#include <gtk/gtkscalebutton.h>
#include <gtk/gtkscrollable.h>
......
This diff is collapsed.
/*
* Copyright (c) 2013 Red Hat, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Author: Alexander Larsson <alexl@redhat.com>
*
*/
#ifndef __GTK_REVEALER_H__
#define __GTK_REVEALER_H__
#include <gtk/gtkbin.h>
G_BEGIN_DECLS
#define GTK_TYPE_REVEALER (gtk_revealer_get_type ())
#define GTK_REVEALER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_REVEALER, GtkRevealer))
#define GTK_REVEALER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_REVEALER, GtkRevealerClass))
#define GTK_IS_REVEALER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_REVEALER))
#define GTK_IS_REVEALER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_REVEALER))
#define GTK_REVEALER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_REVEALER, GtkRevealerClass))
typedef struct _GtkRevealer GtkRevealer;
typedef struct _GtkRevealerClass GtkRevealerClass;
typedef struct _GtkRevealerPrivate GtkRevealerPrivate;
typedef enum {
GTK_REVEALER_TRANSITION_TYPE_NONE,
GTK_REVEALER_TRANSITION_TYPE_SLIDE_RIGHT,
GTK_REVEALER_TRANSITION_TYPE_SLIDE_LEFT,
GTK_REVEALER_TRANSITION_TYPE_SLIDE_UP,
GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN
} GtkRevealerTransitionType;
struct _GtkRevealer {
GtkBin parent_instance;
GtkRevealerPrivate * priv;
};
struct _GtkRevealerClass {
GtkBinClass parent_class;
};
GType gtk_revealer_get_type (void) G_GNUC_CONST;
GtkWidget* gtk_revealer_new (void);
gboolean gtk_revealer_get_reveal_child (GtkRevealer *revealer);
void gtk_revealer_set_reveal_child (GtkRevealer *revealer,
gboolean reveal_child);
gboolean gtk_revealer_get_child_revealed (GtkRevealer *revealer);
guint gtk_revealer_get_transition_duration (GtkRevealer *revealer);
void gtk_revealer_set_transition_duration (GtkRevealer *revealer,
guint duration);
void gtk_revealer_set_transition_type (GtkRevealer *revealer,
GtkRevealerTransitionType transition);
GtkRevealerTransitionType gtk_revealer_get_transition_type (GtkRevealer *revealer);
G_END_DECLS
#endif
#include <gtk/gtk.h>
gint
main (gint argc,
gchar ** argv)
{
GtkWidget *window, *revealer, *box, *widget, *entry;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_set_size_request (window, 300, 300);
box = gtk_grid_new ();
gtk_container_add (GTK_CONTAINER (window), box);
widget = gtk_label_new ("Some filler text to avoid\nresizing of the window");
gtk_widget_set_margin_top (widget, 10);
gtk_widget_set_margin_bottom (widget, 10);
gtk_widget_set_margin_left (widget, 10);
gtk_widget_set_margin_right (widget, 10);
gtk_grid_attach (GTK_GRID (box), widget, 1, 1, 1, 1);
widget = gtk_label_new ("Some filler text to avoid\nresizing of the window");
gtk_widget_set_margin_top (widget, 10);
gtk_widget_set_margin_bottom (widget, 10);
gtk_widget_set_margin_left (widget, 10);
gtk_widget_set_margin_right (widget, 10);
gtk_grid_attach (GTK_GRID (box), widget, 3, 3, 1, 1);
widget = gtk_toggle_button_new_with_label ("None");
gtk_grid_attach (GTK_GRID (box), widget, 0, 0, 1, 1);
revealer = gtk_revealer_new ();
gtk_widget_set_halign (revealer, GTK_ALIGN_START);
gtk_widget_set_valign (revealer, GTK_ALIGN_START);
entry = gtk_entry_new ();
gtk_entry_set_text (GTK_ENTRY (entry), "00000");
gtk_container_add (GTK_CONTAINER (revealer), entry);
g_object_bind_property (widget, "active", revealer, "reveal-child", 0);
gtk_revealer_set_transition_type (GTK_REVEALER (revealer), GTK_REVEALER_TRANSITION_TYPE_NONE);
gtk_revealer_set_transition_duration (GTK_REVEALER (revealer), 2000);
gtk_grid_attach (GTK_GRID (box), revealer, 1, 0, 1, 1);
widget = gtk_toggle_button_new_with_label ("None");
gtk_grid_attach (GTK_GRID (box), widget, 4, 4, 1, 1);
revealer = gtk_revealer_new ();
gtk_widget_set_halign (revealer, GTK_ALIGN_END);
gtk_widget_set_valign (revealer, GTK_ALIGN_END);
entry = gtk_entry_new ();
gtk_entry_set_text (GTK_ENTRY (entry), "00000");
gtk_container_add (GTK_CONTAINER (revealer), entry);
g_object_bind_property (widget, "active", revealer, "reveal-child", 0);
gtk_revealer_set_transition_type (GTK_REVEALER (revealer), GTK_REVEALER_TRANSITION_TYPE_NONE);
gtk_revealer_set_transition_duration (GTK_REVEALER (revealer), 2000);
gtk_grid_attach (GTK_GRID (box), revealer, 3, 4, 1, 1);
widget = gtk_toggle_button_new_with_label ("Right");
gtk_grid_attach (GTK_GRID (box), widget, 0, 2, 1, 1);
revealer = gtk_revealer_new ();
gtk_widget_set_hexpand (revealer, TRUE);
gtk_widget_set_halign (revealer, GTK_ALIGN_START);
entry = gtk_entry_new ();
gtk_entry_set_text (GTK_ENTRY (entry), "12345");
gtk_container_add (GTK_CONTAINER (revealer), entry);
g_object_bind_property (widget, "active", revealer, "reveal-child", 0);
gtk_revealer_set_transition_type (GTK_REVEALER (revealer), GTK_REVEALER_TRANSITION_TYPE_SLIDE_RIGHT);
gtk_revealer_set_transition_duration (GTK_REVEALER (revealer), 2000);
gtk_grid_attach (GTK_GRID (box), revealer, 1, 2, 1, 1);
widget = gtk_toggle_button_new_with_label ("Down");
gtk_grid_attach (GTK_GRID (box), widget, 2, 0, 1, 1);
revealer = gtk_revealer_new ();
gtk_widget_set_vexpand (revealer, TRUE);
gtk_widget_set_valign (revealer, GTK_ALIGN_START);
entry = gtk_entry_new ();
gtk_entry_set_text (GTK_ENTRY (entry), "23456");
gtk_container_add (GTK_CONTAINER (revealer), entry);
g_object_bind_property (widget, "active", revealer, "reveal-child", 0);
gtk_revealer_set_transition_type (GTK_REVEALER (revealer), GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN);
gtk_revealer_set_transition_duration (GTK_REVEALER (revealer), 2000);
gtk_grid_attach (GTK_GRID (box), revealer, 2, 1, 1, 1);
widget = gtk_toggle_button_new_with_label ("Left");
gtk_grid_attach (GTK_GRID (box), widget, 4, 2, 1, 1);
revealer = gtk_revealer_new ();
gtk_widget_set_hexpand (revealer, TRUE);
gtk_widget_set_halign (revealer, GTK_ALIGN_END);
entry = gtk_entry_new ();
gtk_entry_set_text (GTK_ENTRY (entry), "34567");
gtk_container_add (GTK_CONTAINER (revealer), entry);
g_object_bind_property (widget, "active", revealer, "reveal-child", 0);
gtk_revealer_set_transition_type (GTK_REVEALER (revealer), GTK_REVEALER_TRANSITION_TYPE_SLIDE_LEFT);
gtk_revealer_set_transition_duration (GTK_REVEALER (revealer), 2000);
gtk_grid_attach (GTK_GRID (box), revealer, 3, 2, 1, 1);
widget = gtk_toggle_button_new_with_label ("Up");
gtk_grid_attach (GTK_GRID (box), widget, 2, 4, 1, 1);
revealer = gtk_revealer_new ();
gtk_widget_set_vexpand (revealer, TRUE);
gtk_widget_set_valign (revealer, GTK_ALIGN_END);
entry = gtk_entry_new ();
gtk_entry_set_text (GTK_ENTRY (entry), "45678");
gtk_container_add (GTK_CONTAINER (revealer), entry);
g_object_bind_property (widget, "active", revealer, "reveal-child", 0);
gtk_revealer_set_transition_type (GTK_REVEALER (revealer), GTK_REVEALER_TRANSITION_TYPE_SLIDE_UP);
gtk_revealer_set_transition_duration (GTK_REVEALER (revealer), 2000);
gtk_grid_attach (GTK_GRID (box), revealer, 2, 3, 1, 1);
gtk_widget_show_all (window);
gtk_main ();
gtk_widget_destroy (window);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment