Re: GooCanvasTable: column widths



On Mon, 2011-08-22 at 16:07 +0100, Damon Chaplin wrote:
> On Mon, 2011-08-22 at 15:29 +0200, Murray Cumming wrote:
> > 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.
> 
> I'm not sure if that should be considered a bug or not.

Well, I guess we need to document it. I'll try to do that.

> As a workaround you should be able to add an invisible rect to the
> table:
> 
>   GooCanvasItem *rect = goo_canvas_rect_new (table,
>     0.0f, 0.0f,
>     50.0f, 1.0f,
>     "stroke-pattern", NULL,
>     NULL);
>   goo_canvas_item_set_child_properties(table, rect,
>                                        "row", 1,
>                                        "column", 1,
>                                        NULL);
> 

Thanks. That does help a lot.

However, the GooCanvasText does not seem to use all the space that it
then has. This is a problem when aligning the text right, as you can see
in the attached test. The second column has the text aligned right, but
not against the right side of the column.

-- 
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>

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 *size_rect = goo_canvas_rect_new (table,
    0.0f, 0.0f,
    50.0f, 1.0f,
    "stroke-pattern", NULL,
    NULL);
  goo_canvas_item_set_child_properties(table, size_rect,
   "row", 0,
   "column", 0,
   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);
  g_object_set (text2,
   "alignment",  PANGO_ALIGN_RIGHT,
    NULL);
                                       
  size_rect = goo_canvas_rect_new (table,
    0.0f, 0.0f,
    50.0f, 1.0f,
    "stroke-pattern", NULL,
    NULL);
  goo_canvas_item_set_child_properties(table, size_rect,
   "row", 1,
   "column", 1,
   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);
    
  size_rect = goo_canvas_rect_new (table,
    0.0f, 0.0f,
    50.0f, 1.0f,
    "stroke-pattern", NULL,
    NULL);
  goo_canvas_item_set_child_properties(table, size_rect,
   "row", 2,
   "column", 2,
   NULL);

  gtk_main ();
  return 0;
}


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