1#include <gtk/gtk.h>
2
3const int KEEP_HEIGHT = 1 << 0;
4const int KEEP_WIDTH = 1 << 1;
5
6static void
7keep_size (int direction,
8 guint transition_type,
9 gboolean animations)
10{
11 gboolean animations_before;
12 int min_height, min_width;
13 int min_child_width, min_child_height;
14 GtkRevealer *revealer = GTK_REVEALER (gtk_revealer_new ());
15 GtkWidget *child = gtk_button_new_with_label (label: "Some Text!");
16 GtkSettings *settings = gtk_settings_get_default ();
17
18 g_object_get (object: settings, first_property_name: "gtk-enable-animations", &animations_before, NULL);
19 g_object_set (object: settings, first_property_name: "gtk-enable-animations", animations, NULL);
20
21 gtk_revealer_set_child (GTK_REVEALER (revealer), child);
22
23 gtk_revealer_set_transition_type (revealer, transition: transition_type);
24
25 gtk_revealer_set_reveal_child (revealer, TRUE);
26
27 gtk_widget_measure (widget: child, orientation: GTK_ORIENTATION_HORIZONTAL, for_size: -1,
28 minimum: &min_child_width, NULL, NULL, NULL);
29 gtk_widget_measure (widget: child, orientation: GTK_ORIENTATION_VERTICAL, for_size: -1,
30 minimum: &min_child_height, NULL, NULL, NULL);
31
32 gtk_widget_measure (GTK_WIDGET (revealer), orientation: GTK_ORIENTATION_HORIZONTAL, for_size: -1,
33 minimum: &min_width, NULL, NULL, NULL);
34 gtk_widget_measure (GTK_WIDGET (revealer), orientation: GTK_ORIENTATION_VERTICAL, for_size: -1,
35 minimum: &min_height, NULL, NULL, NULL);
36
37 g_assert_cmpint (min_width, ==, min_child_width);
38 g_assert_cmpint (min_height, ==, min_child_height);
39
40
41 gtk_revealer_set_reveal_child (revealer, FALSE);
42 gtk_widget_measure (GTK_WIDGET (revealer), orientation: GTK_ORIENTATION_HORIZONTAL, for_size: -1,
43 minimum: &min_width, NULL, NULL, NULL);
44 gtk_widget_measure (GTK_WIDGET (revealer), orientation: GTK_ORIENTATION_VERTICAL, for_size: -1,
45 minimum: &min_height, NULL, NULL, NULL);
46
47 if (direction & KEEP_WIDTH)
48 g_assert_cmpint (min_width, ==, min_child_width);
49 else
50 g_assert_cmpint (min_width, ==, 0);
51
52 if (direction & KEEP_HEIGHT)
53 g_assert_cmpint (min_height, ==, min_child_height);
54 else
55 g_assert_cmpint (min_height, ==, 0);
56
57 g_object_set (object: settings, first_property_name: "gtk-enable-animations", animations_before, NULL);
58}
59
60
61static void
62slide_right_animations (void)
63{
64 keep_size (direction: KEEP_HEIGHT, transition_type: GTK_REVEALER_TRANSITION_TYPE_SLIDE_RIGHT, TRUE);
65}
66
67static void
68slide_right_no_animations (void)
69{
70 keep_size (direction: KEEP_HEIGHT, transition_type: GTK_REVEALER_TRANSITION_TYPE_SLIDE_RIGHT, FALSE);
71}
72
73static void
74slide_left_animations (void)
75{
76 keep_size (direction: KEEP_HEIGHT, transition_type: GTK_REVEALER_TRANSITION_TYPE_SLIDE_LEFT, TRUE);
77}
78
79static void
80slide_left_no_animations (void)
81{
82 keep_size (direction: KEEP_HEIGHT, transition_type: GTK_REVEALER_TRANSITION_TYPE_SLIDE_LEFT, FALSE);
83}
84
85static void
86none_animations (void)
87{
88 keep_size (direction: KEEP_WIDTH | KEEP_HEIGHT, transition_type: GTK_REVEALER_TRANSITION_TYPE_NONE, TRUE);
89}
90
91static void
92none_no_animations (void)
93{
94 keep_size (direction: KEEP_WIDTH | KEEP_HEIGHT, transition_type: GTK_REVEALER_TRANSITION_TYPE_NONE, FALSE);
95}
96
97static void
98crossfade_animations (void)
99{
100 keep_size (direction: KEEP_WIDTH | KEEP_HEIGHT, transition_type: GTK_REVEALER_TRANSITION_TYPE_CROSSFADE, TRUE);
101}
102
103static void
104crossfade_no_animations (void)
105{
106 keep_size (direction: KEEP_WIDTH | KEEP_HEIGHT, transition_type: GTK_REVEALER_TRANSITION_TYPE_CROSSFADE, FALSE);
107}
108
109static void
110slide_down_animations (void)
111{
112 keep_size (direction: KEEP_WIDTH, transition_type: GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN, TRUE);
113}
114
115static void
116slide_down_no_animations (void)
117{
118 keep_size (direction: KEEP_WIDTH, transition_type: GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN, FALSE);
119}
120
121static void
122slide_up_animations (void)
123{
124 keep_size (direction: KEEP_WIDTH, transition_type: GTK_REVEALER_TRANSITION_TYPE_SLIDE_UP, TRUE);
125}
126
127static void
128slide_up_no_animations (void)
129{
130 keep_size (direction: KEEP_WIDTH, transition_type: GTK_REVEALER_TRANSITION_TYPE_SLIDE_UP, FALSE);
131}
132
133int
134main (int argc, char **argv)
135{
136 gtk_init ();
137 (g_test_init) (argc: &argc, argv: &argv, NULL);
138
139 g_test_add_func (testpath: "/sizing/revealer/slide_right_animations", test_func: slide_right_animations);
140 g_test_add_func (testpath: "/sizing/revealer/slide_right_no_animations", test_func: slide_right_no_animations);
141
142 g_test_add_func (testpath: "/sizing/revealer/slide_left_animations", test_func: slide_left_animations);
143 g_test_add_func (testpath: "/sizing/revealer/slide_left_no_animations", test_func: slide_left_no_animations);
144
145 g_test_add_func (testpath: "/sizing/revealer/none_animations", test_func: none_animations);
146 g_test_add_func (testpath: "/sizing/revealer/none_no_animations", test_func: none_no_animations);
147
148 g_test_add_func (testpath: "/sizing/revealer/crossfade_animations", test_func: crossfade_animations);
149 g_test_add_func (testpath: "/sizing/revealer/crossfade_no_animations", test_func: crossfade_no_animations);
150
151 g_test_add_func (testpath: "/sizing/revealer/slide_down_animations", test_func: slide_down_animations);
152 g_test_add_func (testpath: "/sizing/revealer/slide_down_no_animations", test_func: slide_down_no_animations);
153
154 g_test_add_func (testpath: "/sizing/revealer/slide_up_animations", test_func: slide_up_animations);
155 g_test_add_func (testpath: "/sizing/revealer/slide_up_no_animations", test_func: slide_up_no_animations);
156
157 return g_test_run ();
158}
159

source code of gtk/testsuite/gtk/revealer-size.c