1 /* testscale.c - scale mark demo
2 * Copyright (C) 2009 Red Hat, Inc.
3 * Author: Matthias Clasen
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
26 GtkWidget *extra_scale;
29 invert (GtkButton *button)
33 for (l = scales; l; l = l->next)
35 GtkRange *range = l->data;
36 gtk_range_set_inverted (range, !gtk_range_get_inverted (range));
41 flip (GtkButton *button)
45 gtk_orientable_set_orientation (GTK_ORIENTABLE (flipbox), 1 - gtk_orientable_get_orientation (GTK_ORIENTABLE (flipbox)));
47 for (l = scales; l; l = l->next)
49 GtkOrientable *o = l->data;
50 gtk_orientable_set_orientation (o, 1 - gtk_orientable_get_orientation (o));
55 trough (GtkToggleButton *button)
60 value = gtk_toggle_button_get_active (button);
62 for (l = scales; l; l = l->next)
64 GtkRange *range = l->data;
65 gtk_range_set_range (range, 0., value ? 100.0 : 0.);
69 gdouble marks[3] = { 0.0, 50.0, 100.0 };
70 gdouble extra_marks[2] = { 20.0, 40.0 };
73 extra (GtkToggleButton *button)
77 value = gtk_toggle_button_get_active (button);
81 gtk_scale_add_mark (GTK_SCALE (extra_scale), extra_marks[0], GTK_POS_TOP, NULL);
82 gtk_scale_add_mark (GTK_SCALE (extra_scale), extra_marks[1], GTK_POS_TOP, NULL);
86 gtk_scale_clear_marks (GTK_SCALE (extra_scale));
87 gtk_scale_add_mark (GTK_SCALE (extra_scale), marks[0], GTK_POS_BOTTOM, NULL);
88 gtk_scale_add_mark (GTK_SCALE (extra_scale), marks[1], GTK_POS_BOTTOM, NULL);
89 gtk_scale_add_mark (GTK_SCALE (extra_scale), marks[2], GTK_POS_BOTTOM, NULL);
93 int main (int argc, char *argv[])
102 const gchar *labels[3] = {
103 "<small>Left</small>",
104 "<small>Middle</small>",
105 "<small>Right</small>"
108 gdouble bath_marks[4] = { 0.0, 33.3, 66.6, 100.0 };
109 const gchar *bath_labels[4] = {
110 "<span color='blue' size='small'>Cold</span>",
111 "<span size='small'>Baby bath</span>",
112 "<span size='small'>Hot tub</span>",
113 "<span color='Red' size='small'>Hot</span>"
116 gdouble pos_marks[4] = { 0.0, 33.3, 66.6, 100.0 };
117 const gchar *pos_labels[4] = { "Left", "Right", "Top", "Bottom" };
119 gtk_init (&argc, &argv);
121 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
122 gtk_window_set_title (GTK_WINDOW (window), "Ranges with marks");
123 box1 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
124 flipbox = box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
125 gtk_widget_set_hexpand (flipbox, TRUE);
126 gtk_widget_set_vexpand (flipbox, TRUE);
127 gtk_container_add (GTK_CONTAINER (box1), box);
128 gtk_container_add (GTK_CONTAINER (window), box1);
130 frame = gtk_frame_new ("No marks");
131 scale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL, 0, 100, 1);
132 scales = g_slist_prepend (scales, scale);
133 gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
134 gtk_container_add (GTK_CONTAINER (frame), scale);
135 gtk_box_pack_start (GTK_BOX (box), frame, FALSE, FALSE, 0);
137 frame = gtk_frame_new ("Simple marks");
138 extra_scale = scale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL, 0, 100, 1);
139 scales = g_slist_prepend (scales, scale);
140 gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
141 gtk_scale_add_mark (GTK_SCALE (scale), marks[0], GTK_POS_BOTTOM, NULL);
142 gtk_scale_add_mark (GTK_SCALE (scale), marks[1], GTK_POS_BOTTOM, NULL);
143 gtk_scale_add_mark (GTK_SCALE (scale), marks[2], GTK_POS_BOTTOM, NULL);
144 gtk_container_add (GTK_CONTAINER (frame), scale);
145 gtk_box_pack_start (GTK_BOX (box), frame, FALSE, FALSE, 0);
147 frame = gtk_frame_new ("Labeled marks");
148 box2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
150 scale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL, 0, 100, 1);
151 scales = g_slist_prepend (scales, scale);
152 gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
153 gtk_scale_add_mark (GTK_SCALE (scale), marks[0], GTK_POS_BOTTOM, labels[0]);
154 gtk_scale_add_mark (GTK_SCALE (scale), marks[1], GTK_POS_BOTTOM, labels[1]);
155 gtk_scale_add_mark (GTK_SCALE (scale), marks[2], GTK_POS_BOTTOM, labels[2]);
156 gtk_container_add (GTK_CONTAINER (frame), scale);
157 gtk_box_pack_start (GTK_BOX (box), frame, FALSE, FALSE, 0);
159 frame = gtk_frame_new ("Some labels");
160 scale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL, 0, 100, 1);
161 scales = g_slist_prepend (scales, scale);
162 gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
163 gtk_scale_add_mark (GTK_SCALE (scale), marks[0], GTK_POS_BOTTOM, labels[0]);
164 gtk_scale_add_mark (GTK_SCALE (scale), marks[1], GTK_POS_BOTTOM, NULL);
165 gtk_scale_add_mark (GTK_SCALE (scale), marks[2], GTK_POS_BOTTOM, labels[2]);
166 gtk_container_add (GTK_CONTAINER (frame), scale);
167 gtk_box_pack_start (GTK_BOX (box), frame, FALSE, FALSE, 0);
169 frame = gtk_frame_new ("Above and below");
170 scale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL, 0, 100, 1);
171 scales = g_slist_prepend (scales, scale);
172 gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
173 gtk_scale_add_mark (GTK_SCALE (scale), bath_marks[0], GTK_POS_TOP, bath_labels[0]);
174 gtk_scale_add_mark (GTK_SCALE (scale), bath_marks[1], GTK_POS_BOTTOM, bath_labels[1]);
175 gtk_scale_add_mark (GTK_SCALE (scale), bath_marks[2], GTK_POS_BOTTOM, bath_labels[2]);
176 gtk_scale_add_mark (GTK_SCALE (scale), bath_marks[3], GTK_POS_TOP, bath_labels[3]);
177 gtk_container_add (GTK_CONTAINER (frame), scale);
178 gtk_box_pack_start (GTK_BOX (box), frame, FALSE, FALSE, 0);
180 frame = gtk_frame_new ("Positions");
181 scale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL, 0, 100, 1);
182 scales = g_slist_prepend (scales, scale);
183 gtk_scale_set_draw_value (GTK_SCALE (scale), FALSE);
184 gtk_scale_add_mark (GTK_SCALE (scale), pos_marks[0], GTK_POS_LEFT, pos_labels[0]);
185 gtk_scale_add_mark (GTK_SCALE (scale), pos_marks[1], GTK_POS_RIGHT, pos_labels[1]);
186 gtk_scale_add_mark (GTK_SCALE (scale), pos_marks[2], GTK_POS_TOP, pos_labels[2]);
187 gtk_scale_add_mark (GTK_SCALE (scale), pos_marks[3], GTK_POS_BOTTOM, pos_labels[3]);
188 gtk_container_add (GTK_CONTAINER (frame), scale);
189 gtk_box_pack_start (GTK_BOX (box), frame, FALSE, FALSE, 0);
191 box2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
192 gtk_container_add (GTK_CONTAINER (box1), box2);
193 button = gtk_button_new_with_label ("Flip");
194 g_signal_connect (button, "clicked", G_CALLBACK (flip), NULL);
195 gtk_container_add (GTK_CONTAINER (box2), button);
197 button = gtk_button_new_with_label ("Invert");
198 g_signal_connect (button, "clicked", G_CALLBACK (invert), NULL);
199 gtk_container_add (GTK_CONTAINER (box2), button);
201 button = gtk_toggle_button_new_with_label ("Trough");
202 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
203 g_signal_connect (button, "toggled", G_CALLBACK (trough), NULL);
204 gtk_container_add (GTK_CONTAINER (box2), button);
205 gtk_widget_show_all (window);
207 button = gtk_toggle_button_new_with_label ("Extra");
208 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), FALSE);
209 g_signal_connect (button, "toggled", G_CALLBACK (extra), NULL);
210 gtk_container_add (GTK_CONTAINER (box2), button);
211 gtk_widget_show_all (window);