[cairo-commit] goocanvas/demo demo-clipping.c, 1.1, 1.2 demo-table.c, 1.1, 1.2 demo.c, 1.20, 1.21

Damon Chaplin commit at pdx.freedesktop.org
Tue Mar 6 04:08:22 PST 2007


Committed by: damon

Update of /cvs/cairo/goocanvas/demo
In directory kemper:/tmp/cvs-serv2122/demo

Modified Files:
	demo-clipping.c demo-table.c demo.c 
Log Message:
2007-03-06  Damon Chaplin  <damon at gnome.org>

	* src/goocanvasitem.[hc]: added get_requested_height() method.

	* src/goocanvastable.c: Reworked a lot of code to support
	width-for-height layout. This gets the requested area of all children,
	calculates the column widths, then checks if any children want to
	change their requested height given their allocated width. Text items
	change their requested height based on their width, so this results in
	a better layout.

	* src/goocanvastext.h (struct _GooCanvasText): added layout_width to
	store the width used for the PangoLayout. This initially comes from
	the text's width property, but can be modified when the text item
	is layed out in a container like GooCanvasTable.

	* src/goocanvastext.c (goo_canvas_text_get_requested_height):
	calculates the requested height for the given width, or just returns
	-1 if the text item is rotated or has a clip path, in which case the
	original height is used.
	(goo_canvas_text_init, goo_canvas_text_create_layout) 
	(goo_canvas_text_update): use layout_width.

	* demo/demo-table.c (create_width_for_height_table): added tests for
	width-for-height layout.

	* demo/demo-clipping.c (setup_canvas): added text item to check
	clipping works OK with them.



Index: demo-clipping.c
===================================================================
RCS file: /cvs/cairo/goocanvas/demo/demo-clipping.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- demo-clipping.c	15 Feb 2007 14:18:50 -0000	1.1
+++ demo-clipping.c	6 Mar 2007 12:08:15 -0000	1.2
@@ -46,6 +46,11 @@
   g_signal_connect (item, "button_press_event",
 		    (GtkSignalFunc) on_button_press, "Yellow rectangle (unclipped)");
 
+  item = goo_canvas_text_new (root, "Sample Text", 520, 100, -1, GTK_ANCHOR_NW,
+			      NULL);
+  g_signal_connect (item, "button_press_event",
+		    (GtkSignalFunc) on_button_press, "Text (unclipped)");
+
 
 
   /* Clipped items. */
@@ -73,6 +78,12 @@
   g_signal_connect (item, "button_press_event",
 		    (GtkSignalFunc) on_button_press, "Yellow rectangle");
 
+  item = goo_canvas_text_new (root, "Sample Text", 520, 300, -1, GTK_ANCHOR_NW,
+			      "clip-path", "M535,300 h75 v40 h-75 z",
+			      NULL);
+  g_signal_connect (item, "button_press_event",
+		    (GtkSignalFunc) on_button_press, "Text");
+
 
   /* Table with clipped items. */
   table = goo_canvas_table_new (root, NULL);
@@ -108,6 +119,16 @@
 					NULL);
   g_signal_connect (item, "button_press_event",
 		    (GtkSignalFunc) on_button_press, "Yellow rectangle");
+
+  item = goo_canvas_text_new (table, "Sample Text", 520, 300, -1,
+			      GTK_ANCHOR_NW,
+			      "clip-path", "M535,300 h75 v40 h-75 z",
+			      NULL);
+  goo_canvas_item_set_child_properties (table, item,
+					"column", 3,
+					NULL);
+  g_signal_connect (item, "button_press_event",
+		    (GtkSignalFunc) on_button_press, "Text");
 }
 
 

Index: demo-table.c
===================================================================
RCS file: /cvs/cairo/goocanvas/demo/demo-table.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- demo-table.c	20 Feb 2007 23:53:17 -0000	1.1
+++ demo-table.c	6 Mar 2007 12:08:15 -0000	1.2
@@ -197,6 +197,62 @@
 }
 
 
+static void
+create_width_for_height_table (GooCanvasItem *root,
+			       gdouble        x,
+			       gdouble        y,
+			       gdouble        width,
+			       gdouble        height,
+			       gdouble        rotation)
+{
+  GooCanvasItem *table, *item;
+  gchar *text = "This is a long paragraph that will have to be split over a few lines so we can see if its allocated height changes when its allocated width is changed.";
+
+  table = goo_canvas_table_new (root,
+#if 1
+				"width", width,
+				"height", height,
+#endif
+                                NULL);
+  goo_canvas_item_translate (table, x, y);
+  goo_canvas_item_rotate (table, rotation, 0, 0);
+
+  item = goo_canvas_rect_new (table, 0.0, 0.0, width - 2, 10.0,
+			      "fill-color", "red",
+			      NULL);
+  goo_canvas_item_set_child_properties (table, item,
+					"row", 0,
+					"column", 0,
+					"x-shrink", TRUE,
+					NULL);
+
+#if 1
+  item = goo_canvas_text_new (table, text, 0, 0, -1, GTK_ANCHOR_NW, NULL);
+  goo_canvas_item_set_child_properties (table, item,
+					"row", 1,
+					"column", 0,
+					"x-expand", TRUE,
+					"x-fill", TRUE,
+					"x-shrink", TRUE,
+					"y-expand", TRUE,
+					"y-fill", TRUE,
+					NULL);
+  g_object_set_data (G_OBJECT (item), "id", "Text Item");
+  g_signal_connect (item, "button_press_event",
+		    (GtkSignalFunc) on_button_press, NULL);
+#endif
+
+  item = goo_canvas_rect_new (table, 0.0, 0.0, width - 2, 10.0,
+			      "fill-color", "red",
+			      NULL);
+  goo_canvas_item_set_child_properties (table, item,
+					"row", 2,
+					"column", 0,
+					"x-shrink", TRUE,
+					NULL);
+}
+
+
 GtkWidget *
 create_table_page (void)
 {
@@ -215,7 +271,7 @@
 
   canvas = goo_canvas_new ();
   gtk_widget_set_size_request (canvas, 600, 450);
-  goo_canvas_set_bounds (GOO_CANVAS (canvas), 0, 0, 1000, 1000);
+  goo_canvas_set_bounds (GOO_CANVAS (canvas), 0, 0, 1000, 2000);
   gtk_container_add (GTK_CONTAINER (scrolled_win), canvas);
 
   root = goo_canvas_get_root_item (GOO_CANVAS (canvas));
@@ -246,6 +302,14 @@
   g_object_set (table, "width", 300.0, "height", 200.0, NULL);
 #endif
 
+  create_width_for_height_table (root, 100, 1000, 200, -1, 0);
+#if 1
+  create_width_for_height_table (root, 100, 1200, 300, -1, 0);
+
+  create_width_for_height_table (root, 500, 1000, 200, -1, 30);
+  create_width_for_height_table (root, 500, 1200, 300, -1, 30);
+#endif
+
   gtk_widget_show (canvas);
 
   return vbox;

Index: demo.c
===================================================================
RCS file: /cvs/cairo/goocanvas/demo/demo.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- demo.c	27 Feb 2007 14:45:07 -0000	1.20
+++ demo.c	6 Mar 2007 12:08:15 -0000	1.21
@@ -1251,9 +1251,11 @@
   gtk_widget_show (notebook);
   gtk_container_add (GTK_CONTAINER (window), notebook);
 
+#if 1
   gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
 			    create_canvas_primitives (),
 			    gtk_label_new ("Primitives"));
+#endif
 #if 1
   gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
 			    create_canvas_arrowhead (),



More information about the cairo-commit mailing list