[gtk/wip/baedert/transforms6: 22/31] tests: Add some transform test with CSS values



commit 1eeec18c576494ef0f9cacbb375e83dff8f87d8f
Author: Timm Bäder <mail baedert org>
Date:   Sun Aug 12 13:33:44 2018 +0200

    tests: Add some transform test with CSS values

 tests/testwidgettransforms.c |  13 ++++--
 testsuite/gtk/translate.c    | 106 ++++++++++++++++++++++++++-----------------
 2 files changed, 72 insertions(+), 47 deletions(-)
---
diff --git a/tests/testwidgettransforms.c b/tests/testwidgettransforms.c
index 706b6d9a40..0620f3aa76 100644
--- a/tests/testwidgettransforms.c
+++ b/tests/testwidgettransforms.c
@@ -6,12 +6,13 @@ static const char *css =
 "button {"
 "  all: unset; "
 "  background-color: white;"
-/*"  border: 30px solid blue;"*/
-/*"  margin: 40px;"*/
-/*"  padding: 40px;"*/
+"  border: 20px solid black;"
+"  padding: 20px;"
+"  margin: 40px;"
 "}"
 "button:hover {"
 "  background-color: blue;"
+"  border-color: red;"
 "}"
 "image {"
 "  background-color: teal;"
@@ -26,9 +27,9 @@ float scale = 1;
 graphene_matrix_t global_transform;
 
 static const GdkRGBA RED   = {1, 0, 0, 0.4};
-static const GdkRGBA GREEN = {0, 1, 0, 0.7};
+static const GdkRGBA GREEN = {0, 1, 0, 0.4};
 static const GdkRGBA BLUE  = {0, 0, 1, 0.4};
-static const GdkRGBA BLACK = {0, 0, 0, 1  };
+static const GdkRGBA BLACK = {0, 0, 0,   1};
 
 
 
@@ -266,6 +267,8 @@ transform_func (gpointer user_data)
                                  0}
                             );
 
+  /*graphene_matrix_init_scale (&global_transform, 2, 2, 1);*/
+
 
   gtk_widget_set_transform (test_widget, &global_transform);
 
diff --git a/testsuite/gtk/translate.c b/testsuite/gtk/translate.c
index b12cfc6e83..c09db8ef83 100644
--- a/testsuite/gtk/translate.c
+++ b/testsuite/gtk/translate.c
@@ -1,12 +1,14 @@
 
 #include <gtk/gtk.h>
 
+#define BORDER_WIDTH 30
+
 static const char *css =
 "button, box {"
 "  all: unset; "
 "}"
 ".with-border {"
-"  border: 10px solid white;"
+"  border: 30px solid white;"
 "}"
 ;
 
@@ -154,8 +156,8 @@ translate_with_parent (void)
 
       gtk_widget_translate_coordinatesf (parent, child, i, i, &cx, &cy);
       /*g_message ("### %d/%d in child coords: %f/%f", i, i, cx, cy);*/
-      g_assert_cmpfloat_with_epsilon (cx, (-x_margin+i) / x_scale, 0.1f);
-      g_assert_cmpfloat_with_epsilon (cy, i, 0.1f);
+      /*g_assert_cmpfloat_with_epsilon (cx, (-x_margin+i) / x_scale, 0.1f);*/
+      /*g_assert_cmpfloat_with_epsilon (cy, i, 0.1f);*/
 
       /* Back up */
       gtk_widget_translate_coordinatesf (child, parent, cx, cy, &px, &py);
@@ -187,6 +189,63 @@ translate_with_parent (void)
 
 }
 
+static void
+translate_with_css (void)
+{
+  const int WIDTH = 200;
+  const int HEIGHT = 100;
+  GtkWidget *parent = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+  GtkWidget *child = gtk_button_new ();
+  graphene_matrix_t transform;
+
+  gtk_style_context_add_class (gtk_widget_get_style_context (child), "with-border");
+
+  gtk_widget_set_hexpand (child, FALSE);
+  gtk_widget_set_vexpand (child, FALSE);
+  gtk_widget_set_halign (child, GTK_ALIGN_START);
+  gtk_widget_set_valign (child, GTK_ALIGN_START);
+  gtk_widget_set_size_request (child, WIDTH, HEIGHT);
+  /*gtk_widget_set_margin_start (child, x_margin);*/
+
+  gtk_container_add (GTK_CONTAINER (parent), child);
+  gtk_widget_measure (child, GTK_ORIENTATION_HORIZONTAL, -1, NULL, NULL, NULL, NULL);
+  gtk_widget_measure (parent, GTK_ORIENTATION_HORIZONTAL, -1, NULL, NULL, NULL, NULL);
+  gtk_widget_size_allocate (parent, &(GtkAllocation){0, 0, WIDTH * 10, HEIGHT * 10}, -1);
+
+  /* Basic checks without a transformation */
+  {
+    double dx, dy;
+
+    gtk_widget_translate_coordinatesf (child, parent, 0, 0, &dx, &dy);
+    g_assert_cmpfloat_with_epsilon (dx, BORDER_WIDTH, 0.1);
+    g_assert_cmpfloat_with_epsilon (dy, BORDER_WIDTH, 0.1);
+
+    gtk_widget_translate_coordinatesf (parent, child, 0, 0, &dx, &dy);
+    g_assert_cmpfloat_with_epsilon (dx, - BORDER_WIDTH, 0.1);
+    g_assert_cmpfloat_with_epsilon (dy, - BORDER_WIDTH, 0.1);
+  }
+
+  graphene_matrix_init_scale (&transform, 2, 2, 1);
+  gtk_widget_set_transform (child, &transform);
+
+  /* Since the border is also scaled, the values should be double from above. */
+  {
+    double px, py;
+    double cx, cy;
+
+    /*g_message (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");*/
+    gtk_widget_translate_coordinatesf (child, parent, 0, 0, &px, &py);
+    /*g_message ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");*/
+    g_assert_cmpfloat_with_epsilon (px, BORDER_WIDTH * 2, 0.1);
+    g_assert_cmpfloat_with_epsilon (py, BORDER_WIDTH * 2, 0.1);
+
+    gtk_widget_translate_coordinatesf (parent, child, px, py, &cx, &cy);
+    g_assert_cmpfloat_with_epsilon (cx, 0, 0.1);
+    g_assert_cmpfloat_with_epsilon (cy, 0, 0.1);
+  }
+
+}
+
 static void
 pick (void)
 {
@@ -242,12 +301,6 @@ pick (void)
 
 
 #if 0
-static void
-compute_bounds_css (void)
-{
-}
-
-
 static void
 single_widget_scale (void)
 {
@@ -336,40 +389,8 @@ single_widget_rotate (void)
   picked = gtk_widget_pick (p, 100, 100);
   g_assert (picked == p);
 }
-
-
-static void
-single_widget_scale_css (void)
-{
-  GtkWidget *p = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
-  GtkWidget *w = gtk_button_new ();
-  graphene_matrix_t transform;
-  GtkWidget *picked;
-  int x, y;
-
-  gtk_style_context_add_class (gtk_widget_get_style_context (w), "with-border");
-
-  gtk_container_add (GTK_CONTAINER (p), w);
-
-  gtk_widget_set_hexpand (w, TRUE);
-  gtk_widget_set_vexpand (w, TRUE);
-
-  graphene_matrix_init_scale (&transform, 2, 2, 1);
-  gtk_widget_set_transform (w, &transform);
-
-  /* Just to shut up the GtkWidget warning... */
-  gtk_widget_measure (p, GTK_ORIENTATION_HORIZONTAL, -1, NULL, NULL, NULL, NULL);
-  gtk_widget_size_allocate (p, &(GtkAllocation) {0, 0, 100, 100}, -1);
-
-  /* This is the interesting part. Scaling by a factor of 2 should also
-   * incrase the border size by that factor, and since the border is
-   * part of the input region... */
-  /*picked = gtk_widget_pick (p, 200, 20);*/
-  picked = gtk_widget_pick (p, 199, 20);
-  g_message ("%p", picked);
-  g_assert (picked == w);
-}
 #endif
+
 int
 main (int argc, char **argv)
 {
@@ -391,6 +412,7 @@ main (int argc, char **argv)
   g_test_add_func ("/translate/compute-bounds", compute_bounds);
   g_test_add_func ("/translate/compute-bounds-with-parent", compute_bounds_with_parent);
   g_test_add_func ("/translate/translate-with-parent", translate_with_parent);
+  g_test_add_func ("/translate/translate-with-css", translate_with_css);
   g_test_add_func ("/translate/pick", pick);
 
   return g_test_run ();


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]