File: test-table.c

package info (click to toggle)
nbtk 1.2.3-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 2,044 kB
  • ctags: 2,334
  • sloc: ansic: 20,971; makefile: 435; sh: 147
file content (197 lines) | stat: -rw-r--r-- 7,268 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/*
 * Copyright 2009 Intel Corporation.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU Lesser General Public License,
 * version 2.1, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope 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.
 * Boston, MA 02111-1307, USA.
 *
 */
#include <stdlib.h>
#include <stdio.h>

#include <glib.h>

#include <clutter/clutter.h>
#include <nbtk/nbtk.h>

static void
toggle_expand (NbtkButton *button, ClutterContainer *table)
{
  gboolean x_expand;
  gchar *label;


  clutter_container_child_get (table, CLUTTER_ACTOR (button),
                               "x-expand", &x_expand,
                               NULL);

  x_expand = !x_expand;

  clutter_container_child_set (table, CLUTTER_ACTOR (button),
                               "x-expand", x_expand,
                               "y-expand", x_expand,
                               NULL);

  label = g_strdup_printf ("Expand = %d", x_expand);
  nbtk_button_set_label (button, label);

  g_free (label);
}

static void
randomise_align (NbtkButton *button, ClutterContainer *table)
{
  gdouble x_align, y_align;
  gchar *label;
  
  x_align = g_random_double ();
  y_align = g_random_double ();
  
  clutter_container_child_set (table, CLUTTER_ACTOR (button),
                               "x-align", x_align,
                               "y-align", y_align,
                               NULL);

  label = g_strdup_printf ("Align (%.2lf, %.2lf)", x_align, y_align);
  nbtk_button_set_label (button, label);
  g_free (label);
}

static void
stage_size_notify_cb (ClutterActor *stage,
                      GParamSpec *pspec,
                      ClutterActor *table)
{
  gfloat width, height;

  clutter_actor_get_size (stage, &width, &height);
  clutter_actor_set_size (table, width - 10, height - 10);
}

static void
toggle_visible (NbtkButton *button)
{
  clutter_actor_hide (CLUTTER_ACTOR (button));
}

int
main (int argc, char *argv[])
{
  ClutterActor *stage, *button2;
  NbtkWidget *table;
  NbtkWidget *button1, *button3, *button4, *button5,
             *button6, *button7, *button8, *button9,
             *button10;

  clutter_init (&argc, &argv);

  /* load the style sheet */
  nbtk_style_load_from_file (nbtk_style_get_default (),
                             "style/default.css", NULL);

  stage = clutter_stage_get_default ();
  clutter_stage_set_user_resizable (CLUTTER_STAGE (stage), TRUE);

  table = nbtk_table_new ();
  nbtk_table_set_col_spacing (NBTK_TABLE (table), 10);
  nbtk_table_set_row_spacing (NBTK_TABLE (table), 10);


  g_signal_connect (stage, "notify::width",
                    G_CALLBACK (stage_size_notify_cb), table);
  g_signal_connect (stage, "notify::height",
                    G_CALLBACK (stage_size_notify_cb), table);

  button1 = nbtk_button_new_with_label ("button1");
  button2 = clutter_texture_new_from_file ("redhand.png", NULL);
  button3 = nbtk_button_new_with_label ("button3");
  button4 = nbtk_button_new_with_label ("Expand = 1");
  button5 = nbtk_button_new_with_label ("button5");
  button6 = nbtk_button_new_with_label ("button6");
  button7 = nbtk_button_new_with_label ("Align (0.50, 0.50)");
  button8 = nbtk_button_new_with_label ("button8");
  button9 = nbtk_button_new_with_label ("button9");
  button10 = nbtk_button_new_with_label ("button10");

  nbtk_table_add_actor (NBTK_TABLE (table), CLUTTER_ACTOR (button1), 0, 0);
  nbtk_table_add_actor (NBTK_TABLE (table), button2, 0, 1);
  nbtk_table_add_actor (NBTK_TABLE (table), CLUTTER_ACTOR (button3), 1, 1);
  nbtk_table_add_actor (NBTK_TABLE (table), CLUTTER_ACTOR (button4), 2, 0);
  nbtk_table_add_actor (NBTK_TABLE (table), CLUTTER_ACTOR (button5), 3, 0);
  nbtk_table_add_actor (NBTK_TABLE (table), CLUTTER_ACTOR (button6), 3, 1);
  nbtk_table_add_actor (NBTK_TABLE (table), CLUTTER_ACTOR (button7), 4, 1);
  nbtk_table_add_actor (NBTK_TABLE (table), CLUTTER_ACTOR (button8), 4, 0);
  nbtk_table_add_actor (NBTK_TABLE (table), CLUTTER_ACTOR (button9), 5, 0);
  nbtk_table_add_actor (NBTK_TABLE (table), CLUTTER_ACTOR (button10), -1, 0);
  nbtk_table_child_set_row_span (NBTK_TABLE (table), CLUTTER_ACTOR (button1), 2);
  nbtk_table_child_set_row_span (NBTK_TABLE (table), CLUTTER_ACTOR (button7), 2);
  nbtk_table_child_set_col_span (NBTK_TABLE (table), CLUTTER_ACTOR (button4), 2);


  clutter_actor_set_size (CLUTTER_ACTOR (button1), 100, 100);

  clutter_container_child_set (CLUTTER_CONTAINER (table),
                               CLUTTER_ACTOR (button1),
                               "x-expand", FALSE, "y-expand", FALSE,
                               "allocate-hidden", FALSE,
                               NULL);

  clutter_container_child_set (CLUTTER_CONTAINER (table),
                               CLUTTER_ACTOR (button5),
                               "x-expand", FALSE, "y-expand", FALSE,
                               NULL);
  clutter_container_child_set (CLUTTER_CONTAINER (table),
                               CLUTTER_ACTOR (button7),
                               "x-expand", TRUE, "y-expand", TRUE,
                               "x-fill", FALSE, "y-fill", FALSE,
                               NULL);
  clutter_container_child_set (CLUTTER_CONTAINER (table),
                               CLUTTER_ACTOR (button8),
                               "x-expand", FALSE, "y-expand", FALSE,
                               NULL);
  clutter_container_child_set (CLUTTER_CONTAINER (table),
                               CLUTTER_ACTOR (button9),
                               "x-expand", FALSE, "y-expand", FALSE,
                               NULL);

  g_object_set (G_OBJECT (button2), "keep-aspect-ratio", TRUE, NULL);
  clutter_container_child_set (CLUTTER_CONTAINER (table),
                               CLUTTER_ACTOR (button2),
                               "y-fill", FALSE,
                               "x-fill", FALSE,
                               NULL);

  clutter_container_child_set (CLUTTER_CONTAINER (table),
                               CLUTTER_ACTOR (button10),
                               "allocate-hidden", FALSE,
                               NULL);

  clutter_container_add_actor (CLUTTER_CONTAINER (stage), CLUTTER_ACTOR (table));

  clutter_actor_set_position (CLUTTER_ACTOR (table), 5, 5);

  g_signal_connect (button4, "clicked", G_CALLBACK (toggle_expand), table);
  g_signal_connect (button7, "clicked", G_CALLBACK (randomise_align), table);
  g_signal_connect (button10, "clicked", G_CALLBACK (toggle_visible), NULL);

  clutter_actor_show (stage);

  g_debug ("table row count = %d",
           nbtk_table_get_row_count (NBTK_TABLE (table)));
  g_debug ("table column count = %d",
           nbtk_table_get_column_count (NBTK_TABLE (table)));

  clutter_main ();

  return EXIT_SUCCESS;
}