After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 787158 - gtk_widget_get_preferred_width on GtkToolbar gives wrong minimum width
gtk_widget_get_preferred_width on GtkToolbar gives wrong minimum width
Status: RESOLVED NOTABUG
Product: gtk+
Classification: Platform
Component: Widget: GtkToolbar
3.22.x
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2017-09-01 22:20 UTC by alexxcons
Modified: 2017-09-02 20:40 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
very small example (20.00 KB, application/x-tar)
2017-09-01 22:20 UTC, alexxcons
Details
extracted test case (1.52 KB, text/plain)
2017-09-02 05:34 UTC, Daniel Boles
Details

Description alexxcons 2017-09-01 22:20:02 UTC
Created attachment 358961 [details]
very small example

The returned width only seems to be some offset introduced by the Toolbar. In order to get the full min-width of the container and it's items, currently it is required to sum the min-width of all Tool-items and add the min-width of the Toolbar itself.

Attached a very small example in C
I printed the container min-width .. however if you pull the window to have minimum size, you directly can see that the label will vanish.

Same problem seems to exist for the min-height of GtkToolbar.
Comment 1 Daniel Boles 2017-09-02 05:34:57 UTC
Created attachment 358968 [details]
extracted test case

There's no reason for this to be an archive; making people download and extract those is an unnecessary inconvenience.
Comment 2 Daniel Boles 2017-09-02 12:11:26 UTC
(In reply to alexxcons from comment #0)
> Attached a very small example in C
> I printed the container min-width .. however if you pull the window to have
> minimum size, you directly can see that the label will vanish.
> 
> Same problem seems to exist for the min-height of GtkToolbar.

Yes, horizontally shrinking below the min-width of the label makes it disappear.


However, as a quick glance at the code shows, this is perfectly intentional:

The idea is that the toolbar can become too small to show all its items, upon which it'll show an arrow instead.

Just set :show-arrow to FALSE, to disable this, and your problem goes away: the minimal and natural allocations become exactly equal.

https://developer.gnome.org/gtk3/stable/GtkToolbar.html#gtk-toolbar-set-show-arrow


Confirmed by adding this to your test case:

> gtk_toolbar_set_show_arrow (GTK_TOOLBAR (toolbar), FALSE);

and now the Toolbar can't be shrunk below what the Label needs.


The arrow doesn't show, after that... but I think that should be another bug. The size-request code currently assumes that an arrow will show once the toolbar gets too little size, so that's correct, in contrast to the title here.


By the way, you should compile with warnings on: your test case reports this:

> test-tbs.c: In function ‘activate’:
> test-tbs.c:22:26: warning: initialization from incompatible pointer type
> [-Wincompatible-pointer-types]
>    GtkWidget *tool_item = gtk_tool_item_new ();
>                           ^~~~~~~~~~~~~~~~~
> test-tbs.c:23:29: warning: passing argument 1 of ‘gtk_tool_item_set_expand’ from
> incompatible pointer type [-Wincompatible-pointer-types]
>    gtk_tool_item_set_expand (tool_item, TRUE);

The new() function returns a GtkToolItem*, so that needs to be this:

>   GtkToolItem *tool_item = gtk_tool_item_new ();
Comment 3 Daniel Boles 2017-09-02 12:16:16 UTC
(In reply to Daniel Boles from comment #2)
> The arrow doesn't show, after that... but I think that should be another
> bug. The size-request code currently assumes that an arrow will show once
> the toolbar gets too little size, so that's correct, in contrast to the
> title here.

I guess the arrow only shows if there's at least one other item for it to reveal.

So I'm not sure there is any problem here, but please do open another bug if you find a valid use case where GtkToolbar, correctly set up, doesn't work properly.
Comment 4 alexxcons 2017-09-02 20:40:05 UTC
Thanks for the fast reply!

> gtk_toolbar_set_show_arrow (GTK_TOOLBAR (toolbar), FALSE);
In my opinion the default should be "dont show arrow", in order to have the same behavior than other containers.
If you dont know the feature, it is really hard to figure out why a widget disappears on window-shrink when all other containers behave fine ... but maybe that's just because no arrow shows up for me.

It seems like there is a problem with that arrow. For my test it does not show at all (neither for the project I work on) no matter how many tool-items I put inside:
https://bugzilla.gnome.org/show_bug.cgi?id=787195