GNOME Bugzilla – Bug 787158
gtk_widget_get_preferred_width on GtkToolbar gives wrong minimum width
Last modified: 2017-09-02 20:40:05 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.
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.
(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 ();
(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.
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