0

I want to have a goocanvas with a rect item which contains a text.

How to build a group with a rect to add the text as a child is known. But I want to know the size of the text to give the box ( rect ) enough space to display the complete text.

 txt->property_width()

delivers 0! :-(

Glib::RefPtr<Goocanvas::Text> txt = Goocanvas::Text::create( "W123", 0, 0 );
Goocanvas::Bounds b = txt->get_bounds();
cout << b.get_x1() << endl;
cout << b.get_x2() << endl;
cout << b.get_y1() << endl;
cout << b.get_y2() << endl;

All values are zero!

Wow! If I change the code to:

Glib::RefPtr<Goocanvas::Text> txt = Goocanvas::Text::create( "W123", 0, 0 );
Goocanvas::Bounds b = txt->get_bounds();


GooCanvasBounds bounds;
goo_canvas_item_get_bounds (( GooCanvasItem*)txt->gobj(), &bounds);


cout << b.get_x1() << endl;
cout << b.get_x2() << endl;
cout << b.get_y1() << endl;
cout << b.get_y2() << endl;

The output is as expected! Attention: I look not at the bounds var! I still look for 'b'. Looks strange!

[Edit] I wrote a bug report: https://bugzilla.gnome.org/show_bug.cgi?id=721627

Klaus
  • 24,205
  • 7
  • 58
  • 113

1 Answers1

0

If your text is a GooCanvasText item, all you need is (in gtk+)

void  goo_canvas_item_get_bounds (GooCanvasItem *item, GooCanvasBounds *bounds)

This translates to txt->get_bounds() in the gtkmm case. See goocanvas online devhelp for details.

drahnr
  • 6,782
  • 5
  • 48
  • 75
  • I only get 0 values if I use get_bounds().get_xx() – Klaus Jan 06 '14 at 08:37
  • Are all variabts of `the_populated_bounds.get_x1()`/`get_x2()`/`get_y1()`/... equal `0.`? – drahnr Jan 06 '14 at 09:19
  • Yes, all of x1,x2,y1,y2 are zero. – Klaus Jan 06 '14 at 10:10
  • 1
    I just tried the C version `goo_canvas_item_get_bounds(...)` with a TextItem and it does work just fine. [File a bug](https://bugzilla.gnome.org/buglist.cgi?quicksearch=goocanvasmm) and try to get the internal of the C++ class and call the C func directly in the meantime. – drahnr Jan 06 '14 at 11:16
  • Or: Try to set the width parameter to something really big, I *think* it refers to linebreak width. That could be your issue. See https://developer.gnome.org/goocanvasmm/stable/classGoocanvas_1_1Text.html#ad7c06786fbab0113baf622e9110218ec – drahnr Jan 06 '14 at 11:18
  • I inserted a call to the underlaying c interface. After that the c++ code works! See my last edit to my question. Seems to be a bug. Setting width with a large value changes nothing. – Klaus Jan 06 '14 at 11:43
  • What C call did you need to make? – murrayc Jun 15 '16 at 06:44