GooCanvasTable: column widths



I would like to specify the widths of my GooCanvasTable's columns.

At the moment, it looks like I can only specify the width of an item
that is in a cell, like so:
http://developer.gnome.org/goocanvas/stable/GooCanvasRect.html#GooCanvasRect--width

And I can then choose the GooCanvasTable expand and fill child
properties:
http://developer.gnome.org/goocanvas/stable/GooCanvasTable.html#GooCanvasTable--c-x-expand http://developer.gnome.org/goocanvas/stable/GooCanvasTable.html#GooCanvasTable--c-x-fill

- expand=TRUE means that the cell will be given extra space in addition
to the item's own width.
- fill=TRUE seems to affect how the item will be increased in size to
fill that extra space. For a rect this just makes it left aligned,
rather than center-aligned with fill=FALSE. It seems to have no effect
on text.

But I can't seem to control the width for text items. The attached
example shows that I can limit the width to 50 for text that needs more
than that, forcing it to wrap. But I can't force the column width to be
50 if the text doesn't really need that much width. The first two
columns in the example should have the same width.

-- 
murrayc murrayc com
www.murrayc.com
www.openismus.com
// Build with, for instance:
// gcc test_table_text_width.c `pkg-config goocanvas-2.0 --libs --cflags`
#include <gtk/gtk.h>
#include <goocanvas.h>

gdouble drag_x = 0;
gdouble drag_y = 0;
gdouble dragging = FALSE;

static gboolean
on_delete_event (GtkWidget *window,
		 GdkEvent *event,
		 gpointer unused_data)
{
  gtk_main_quit ();
  return FALSE;
}

int
main (int argc, char *argv[])
{
  GtkWidget *window = 0;

  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_default_size (GTK_WINDOW (window), 640, 600);
  gtk_widget_show (window);
  g_signal_connect (window, "delete_event", G_CALLBACK (on_delete_event),
		    NULL);

  GtkWidget *canvas = goo_canvas_new ();
  goo_canvas_set_bounds (GOO_CANVAS (canvas), 0, 0, 10000, 10000);
  gtk_container_add (GTK_CONTAINER(window), canvas);
  gtk_widget_show (canvas);

  GooCanvasItem *root = goo_canvas_get_root_item (GOO_CANVAS (canvas));

  /* Note: "If the "width" and "height" properties are set to positive values then the group is clipped to the given size." */
  GooCanvasItem *table = goo_canvas_table_new (root,
    "x", 10.0f, 
    "y", 10.0f,
    "width", 500.0f,
    "horz-grid-line-width", 1.0f,
    "vert-grid-line-width", 1.0f,
    NULL);

  GooCanvasItem *text = goo_canvas_text_new (table,
    "This should be 50 wide.",
    0.0f, 0.0f,
    50.0f, GOO_CANVAS_ANCHOR_NW,
    NULL);
  goo_canvas_item_set_child_properties(table, text,
                                       "row", 0,
                                       "column", 0,
                                       "x-fill", TRUE, 
                                       "x-expand", TRUE, 
                                       NULL);
                                       
  GooCanvasItem *text2 = goo_canvas_text_new (table,
    "This too.",
    0.0f, 0.0f,
    50.0f, GOO_CANVAS_ANCHOR_NW,
    NULL);
  goo_canvas_item_set_child_properties(table, text2,
                                       "row", 1,
                                       "column", 1,
                                       "x-fill", TRUE, 
                                       "x-expand", TRUE, 
                                       NULL);
                                       

  GooCanvasItem *text3 = goo_canvas_text_new (table,
    "This should be 400 wide. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum",
    0.0f, 0.0f,
    400.0f, GOO_CANVAS_ANCHOR_NW,
    NULL);
  goo_canvas_item_set_child_properties(table, text3,
                                       "row", 2,
                                       "column", 2,
                                       "x-fill", TRUE, 
                                       "x-expand", TRUE, 
                                       NULL);
  g_object_set (text3,
   "wrap", TRUE,
    NULL);

  gtk_main ();
  return 0;
}


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