GNOME Bugzilla – Bug 152483
Improper alignment of icons in GtkIconView
Last modified: 2011-02-04 16:17:18 UTC
The GtkIconView widget has some problem with aligning the icons. The number of icons that are displayed in each row, differs for few rows. For example one row may contain 6 icon-items and other may contain only 5 icons. The number of icons to be displayed in each row, differs based on the length of the "Text" that is to be displayed(below the icon). The columns are not arranged in a straight line. It doesn't look neet. In GnomeIconList we had some provision to set the horizontal space taken by each icon(in terms of pixels), so we didn't have this kind of problem. I have been developing a project(eccvs) which uses GtkIconView widget and I have put up screenshots that explain this improper alignment problem. It can be accessed using the following URLs: http://eccvs.sourceforge.net/images/screenshots/iconview-bug1.png http://eccvs.sourceforge.net/images/screenshots/iconview-bug2.png http://eccvs.sourceforge.net/images/screenshots/iconview-bug3.png The "bug2" and "bug3" are screenshots of "gtk-demo".
It seems that we need to change the present algorithm that we use to layout the icons in the icon-view (to overcome this problem). The present algorithm simply layouts the icons row by row. It tries to arrange icons one by one in a row till we have suffiecient amount of horizontal space. This kind of arrangement doesn't guarantee vertical alignment. ====== If we need to extend this algorithm to support vertical alignment, we have traverse through entire list of icons to find the MAXIMUM_ICON_WIDTH. We can use this width to layout the icons. But this kind of extention is not best possible soln (since it consume more time). [The vertical alignment is importment for GtkIconView (both in GTK_ORIENTATION_HORIZONTAL and GTK_ORIENTATION_VERTICAL configurations).. so we can not simply avoid it...] ====== The alternative soln is to provide a way to user so that they can set the MAXIMUM_ICON_WIDTH that is needed for better alignment. This soln not only addresses the issue but also simplies the "layout" algorithm (This is not more complex than the present algorithm). we need to modify the follg fns for changing the alg. 1. gtk_icon_view_layout_single_row 2. gtk_icon_view_layout 3. gtk_icon_view_calculate_item_size [not sure] Besides this, we also need to provide a way to set the MAXIMUM_ICON_WIDTH.. Or Do we have any other soln to this problem?
Created attachment 34477 [details] [review] a proposal The patch changes the allocation of items to be strictly grid-oriented. The width of the grid can be specified using the ::item-width property. The downside of this approach is that items which are too large overdraw each other. An open question in horizontal mode is if text should be aligned inside each column. I have also added a ::columns property which, if positive, causes the grid to have a fixed number of columns instead of reflowing.
I notice there is some code in the a11y section in gtkiconview.c. Padraig, will you be able to fix that relatively quickly if I commit a patch like the above next week ? CC'ing a11y team
Created attachment 34486 [details] [review] new version A new version which adds a couple of spacing parameters.
What impact does your proposed patch have on the a11y code?
Well, I haven't looked in detail, but it appeared to me that the a11y code duplicates some of the calculations done to position the text. So, if the positioning of the text changes, the calculations will have to be adjusted.
it would probably be preferable to have gtk+ API which allowed the a11y code to get the positional info without duplicate calculation.
Are you referring to the functions gtk_icon_view_item_accessible_get_extents and gtk_icon_view_item_accessible_is_showing? If these are the only functions you are referring to I do not hink there is a problem.
gtk_icon_view_item_accessible_text_get_character_extents gtk_icon_view_item_accessible_text_get_offset_at_point are two more which do calculations with item->layout_x and item->x. I'm not saying that there is a definitive problem, just that you should probably verify that these still work as expected after this bug has been closed...
What makes items to overdrew each other? We probably know the width of the pixbuf that we are going to pack into iconview. So there will be no problem with the pixbuf stuff... The remaining thing is the text? Can't we be able to pack text in any provided width? I think we don't have constraint on the vertical space. So we can limit the horizontal space occupied by the text and increase the number of lines (vertical space).. I don't know about the pango layout.. I am simply guessing.. Finally, what about using Cell renderers? Will the GtkIconView API be changed in future to accomodate cell renderers.. (I have started using GtkIconView for my project http://eccvs.sourceforge.net/)
As long as you specify a fixed grid width, overlarge icons will simply not fit. And if you have horizontal layout, and the icon fills up 95% of the grid width, things probably look bad for the text, no matter how we try to break it. We do have a plan to use cell renderers in the future, see bug 148144. The current api will be kept as a convenience api.
2004-12-14 Matthias Clasen <mclasen@redhat.com> * gtk/gtk.symbols: Add new symbols. * gtk/gtkiconview.[hc]: Make the icon view lay out its items in a grid, allocating multiple grid cells to oversized items. Also convert hardwired spacing constants into properties. (#152483)