diff options
author | Emmanuele Bassi <ebassi@gnome.org> | 2013-09-19 15:18:42 +0100 |
---|---|---|
committer | Emmanuele Bassi <ebassi@gnome.org> | 2013-09-19 15:29:28 +0100 |
commit | 5319e2622135a32c81b87463cac8fc830ae1ba82 (patch) | |
tree | dd04ef85e5d12bcd13a4527ae2314e6d00303788 | |
parent | c9652a6e61351c4937bd0723fb3983595fff976b (diff) |
Add a test case for the FlexyGrid widget
[endlessm/eos-sdk#1015]
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | test/Makefile.am | 5 | ||||
-rw-r--r-- | test/flexy-grid.c | 104 |
3 files changed, 110 insertions, 0 deletions
@@ -1,6 +1,7 @@ # Build products endless-0.pc test/run-tests +test/flexy-grid test/smoke-tests/hello Endless-0.gir Endless-0.typelib diff --git a/test/Makefile.am b/test/Makefile.am index 4124c52..29748dd 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -2,6 +2,7 @@ noinst_PROGRAMS = \ test/run-tests \ + test/flexy-grid \ test/smoke-tests/hello TEST_FLAGS = @EOS_SDK_CFLAGS@ -I$(top_srcdir) -DCOMPILING_EOS_SDK @@ -25,6 +26,10 @@ test_smoke_tests_hello_SOURCES = test/smoke-tests/hello.c test_smoke_tests_hello_CPPFLAGS = $(TEST_FLAGS) test_smoke_tests_hello_LDADD = $(TEST_LIBS) +test_flexy_grid_SOURCES = test/flexy-grid.c +test_flexy_grid_CPPFLAGS = $(TEST_FLAGS) +test_flexy_grid_LDADD = $(TEST_LIBS) + javascript_tests = \ test/tools/eos-run-test/sanitycheck.js \ test/webhelper/testTranslate.js \ diff --git a/test/flexy-grid.c b/test/flexy-grid.c new file mode 100644 index 0000000..f52f96e --- /dev/null +++ b/test/flexy-grid.c @@ -0,0 +1,104 @@ +#include <endless/endless.h> + +static const char *icons[] = { + "applications-accessories", + "applications-development", + "applications-engineering", + "applications-games", + "applications-graphics", + "applications-internet", + "applications-multimedia", + "applications-office", + "applications-other", + "applications-science", + "applications-system", + "applications-utilities", +}; + +#define CHAR(r,g,b) { r / 255.0, g / 255.0, b / 255.0, 1.0 } + +static GdkRGBA colors[] = { + CHAR (0xff, 0x00, 0x00), + CHAR (0x80, 0x00, 0x00), + CHAR (0x00, 0xff, 0x00), + CHAR (0x00, 0x80, 0x00), + CHAR (0x00, 0x00, 0xff), + CHAR (0x00, 0x00, 0x80), + CHAR (0x00, 0xff, 0xff), + CHAR (0x00, 0x80, 0x80), + CHAR (0xff, 0x00, 0xff), + CHAR (0x80, 0x00, 0x80), + CHAR (0xff, 0xff, 0x00), + CHAR (0x80, 0x80, 0x00), + CHAR (0xa0, 0xa0, 0xa4), + CHAR (0x80, 0x80, 0x80), + CHAR (0xc0, 0xc0, 0xc0), +}; + +static EosFlexyShape shapes[] = { + EOS_FLEXY_SHAPE_MEDIUM_HORIZONTAL, + EOS_FLEXY_SHAPE_MEDIUM_VERTICAL, + EOS_FLEXY_SHAPE_SMALL, + EOS_FLEXY_SHAPE_SMALL, + EOS_FLEXY_SHAPE_SMALL, + EOS_FLEXY_SHAPE_MEDIUM_VERTICAL, + EOS_FLEXY_SHAPE_MEDIUM_HORIZONTAL, + EOS_FLEXY_SHAPE_SMALL, +}; + +static void +on_cell_selected (EosFlexyGrid *grid, EosFlexyGridCell *cell) +{ + g_print ("Cell %p selected\n", cell); +} + +static void +on_cell_activated (EosFlexyGrid *grid, EosFlexyGridCell *cell) +{ + g_print ("Cell %p activated\n", cell); +} + +int +main (int argc, char *argv[]) +{ + gtk_init (NULL, NULL); + + GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); + gtk_widget_show (window); + + GtkWidget *scroll = gtk_scrolled_window_new (NULL, NULL); + gtk_container_add (GTK_CONTAINER (window), scroll); + gtk_widget_show (scroll); + + GtkWidget *grid = eos_flexy_grid_new (); + g_signal_connect (grid, "cell-selected", G_CALLBACK (on_cell_selected), NULL); + g_signal_connect (grid, "cell-activated", G_CALLBACK (on_cell_activated), NULL); + gtk_container_add (GTK_CONTAINER (scroll), grid); + gtk_widget_set_size_request (grid, 800, -1); + gtk_widget_show (grid); + + for (guint i; i < 8; i++) + { + GtkWidget *cell = eos_flexy_grid_cell_new (); + eos_flexy_grid_cell_set_shape (EOS_FLEXY_GRID_CELL (cell), shapes[i]); + gtk_container_add (GTK_CONTAINER (grid), cell); + gtk_widget_show (cell); + + GtkWidget *frame = gtk_event_box_new (); + gtk_widget_override_background_color (frame, GTK_STATE_FLAG_NORMAL, &colors[i]); + gtk_container_add (GTK_CONTAINER (cell), frame); + gtk_widget_show (frame); + + GtkWidget *image = gtk_image_new (); + gtk_image_set_from_icon_name (GTK_IMAGE (image), icons[i], GTK_ICON_SIZE_DIALOG); + gtk_container_add (GTK_CONTAINER (frame), image); + gtk_widget_set_hexpand (image, TRUE); + gtk_widget_set_vexpand (image, TRUE); + gtk_widget_show (image); + } + + gtk_main (); + + return 0; +} |