[libadwaita/wip/exalm/tests: 2/2] tests: Add a button states test
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libadwaita/wip/exalm/tests: 2/2] tests: Add a button states test
- Date: Thu, 20 Oct 2022 17:06:18 +0000 (UTC)
commit ed77bb38f375da647a5fa11b77ddde5369e74da1
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Wed Oct 27 12:23:07 2021 +0500
tests: Add a button states test
This was one of the demos written before 1.0 that was never properly
included.
meson.build | 1 +
tests/meson.build | 19 ++++++++++
tests/test-button-states.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 114 insertions(+)
---
diff --git a/meson.build b/meson.build
index dc0015de..8061ffeb 100644
--- a/meson.build
+++ b/meson.build
@@ -134,6 +134,7 @@ subdir('src')
subdir('po')
subdir('demo')
subdir('examples')
+subdir('tests')
subdir('testsuite')
subdir('doc')
diff --git a/tests/meson.build b/tests/meson.build
new file mode 100644
index 00000000..dbf954dc
--- /dev/null
+++ b/tests/meson.build
@@ -0,0 +1,19 @@
+if get_option('tests')
+
+test_cflags = [
+ '-DADW_LOG_DOMAIN="Adwaita"',
+ '-DTEST_DATA_DIR="@0@/data"'.format(meson.current_source_dir()),
+]
+
+test_names = [
+ 'test-button-states',
+]
+
+foreach test_name : test_names
+ executable(test_name,
+ [test_name + '.c'] + libadwaita_generated_headers,
+ c_args: test_cflags,
+ dependencies: libadwaita_deps + [libadwaita_dep])
+endforeach
+
+endif
diff --git a/tests/test-button-states.c b/tests/test-button-states.c
new file mode 100644
index 00000000..d2b3b93b
--- /dev/null
+++ b/tests/test-button-states.c
@@ -0,0 +1,94 @@
+#include <adwaita.h>
+
+static inline void
+add_button (GtkGrid *grid,
+ int column,
+ int row,
+ GtkStateFlags flags,
+ const char *style_class)
+{
+ GtkWidget *button;
+ button = gtk_button_new_with_label ("button");
+ gtk_widget_set_state_flags (button, flags, FALSE);
+ if (style_class)
+ gtk_widget_add_css_class (button, style_class);
+ gtk_grid_attach (grid, button, column, row, 1, 1);
+}
+
+static void
+create_column (GtkGrid *grid,
+ int column,
+ const char *name,
+ GtkStateFlags flags)
+{
+ int row = 0;
+
+ GtkWidget *label = gtk_label_new (name);
+ gtk_grid_attach (grid, label, column, row++, 1, 1);
+
+ add_button (grid, column, row++, flags, NULL);
+ add_button (grid, column, row++, flags, "flat");
+ add_button (grid, column, row++, flags, "suggested-action");
+ add_button (grid, column, row++, flags, "destructive-action");
+ add_button (grid, column, row++, flags, "osd");
+ add_button (grid, column, row++, flags, "card");
+}
+
+static void
+create_buttons (GtkGrid *grid)
+{
+ int column = 0;
+
+ create_column (grid, column++, NULL, GTK_STATE_FLAG_NORMAL);
+ create_column (grid, column++, "hover", GTK_STATE_FLAG_PRELIGHT);
+ create_column (grid, column++, "h:active", GTK_STATE_FLAG_PRELIGHT | GTK_STATE_FLAG_ACTIVE);
+ create_column (grid, column++, "focus", GTK_STATE_FLAG_FOCUSED | GTK_STATE_FLAG_FOCUS_VISIBLE);
+ create_column (grid, column++, "checked", GTK_STATE_FLAG_CHECKED);
+ create_column (grid, column++, "c:hover", GTK_STATE_FLAG_CHECKED | GTK_STATE_FLAG_PRELIGHT);
+ create_column (grid, column++, "c:h:active", GTK_STATE_FLAG_CHECKED | GTK_STATE_FLAG_PRELIGHT |
GTK_STATE_FLAG_ACTIVE);
+ create_column (grid, column++, "c:focus", GTK_STATE_FLAG_CHECKED | GTK_STATE_FLAG_FOCUSED |
GTK_STATE_FLAG_FOCUS_VISIBLE);
+ create_column (grid, column++, "disabled", GTK_STATE_FLAG_INSENSITIVE);
+ create_column (grid, column++, "d:checked", GTK_STATE_FLAG_INSENSITIVE | GTK_STATE_FLAG_CHECKED);
+ create_column (grid, column++, "drop", GTK_STATE_FLAG_DROP_ACTIVE);
+}
+
+static void
+close_cb (gboolean *done)
+{
+ *done = TRUE;
+}
+
+int
+main (int argc,
+ char *argv[])
+{
+ GtkWidget *window, *grid;
+ gboolean done = FALSE;
+
+ adw_init ();
+
+ grid = gtk_grid_new ();
+ gtk_widget_set_can_target (grid, FALSE);
+ gtk_widget_set_can_focus (grid, FALSE);
+ gtk_widget_set_halign (grid, GTK_ALIGN_CENTER);
+ gtk_widget_set_valign (grid, GTK_ALIGN_CENTER);
+ gtk_widget_set_margin_top (grid, 6);
+ gtk_widget_set_margin_bottom (grid, 6);
+ gtk_widget_set_margin_start (grid, 6);
+ gtk_widget_set_margin_end (grid, 6);
+ gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
+ gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
+
+ create_buttons(GTK_GRID (grid));
+
+ window = gtk_window_new ();
+ g_signal_connect_swapped (window, "destroy", G_CALLBACK (close_cb), &done);
+ gtk_window_set_title (GTK_WINDOW (window), "Button States");
+ gtk_window_set_child (GTK_WINDOW (window), grid);
+ gtk_window_present (GTK_WINDOW (window));
+
+ while (!done)
+ g_main_context_iteration (NULL, TRUE);
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]