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 757495 - GtkTreeView odd/even row styling no longer works
GtkTreeView odd/even row styling no longer works
Status: RESOLVED OBSOLETE
Product: gtk+
Classification: Platform
Component: Widget: GtkTreeView
3.19.x
Other Linux
: Normal normal
: ---
Assigned To: gtktreeview-bugs
gtktreeview-bugs
Depends on:
Blocks:
 
 
Reported: 2015-11-02 20:02 UTC by Sam P.
Modified: 2018-05-02 16:50 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch to add "row.even" and "row.odd" css nodes (4.66 KB, patch)
2016-05-01 08:12 UTC, Sam P.
none Details | Review
Try 2 (4.62 KB, patch)
2016-05-01 08:21 UTC, Sam P.
none Details | Review
Try 3 Patch (5.52 KB, patch)
2016-06-03 11:02 UTC, Sam P.
needs-work Details | Review

Description Sam P. 2015-11-02 20:02:52 UTC
As of Gtk 3.18, rows could be styled to be different colours if the were odd or even using something along the lines of:

    GtkTreeView row:even {                                                                     
        background-color: @row_even;                                                
    }                                                                               
                                                                                
    GtkTreeView row:odd {                                                                     
        background-color: @row_odd;                                                 
    }

However, this seems to have been removed in 3.19.1, as the rows are not effected by these colors.

Adding the other css does not effect it either:

    -GtkTreeView-odd-row-color: @row_odd;
    -GtkTreeView-even-row-color: @row_even;

Downstrea:  https://bugs.sugarlabs.org/ticket/4908
Comment 1 Benjamin Otte (Company) 2015-11-09 20:59:18 UTC
This is part of the removal of regions. GtkTreeView cells no longer support the "row" or "column" elements.

I didn't much time thinking about the removal at the time because none of the themes seemed to use it...
Comment 2 Sam P. 2015-11-18 20:56:01 UTC
Yeah.  Is there a way that this could be implemented without using the regions?  Even if it's only changing the colours that would be 100% ok.
Comment 3 Matthias Clasen 2015-11-23 16:52:08 UTC
The way to bring this back would be to make two css nodes for rendering cells, and make them match cell:row-even and cell:row-odd, or something like that. Or maybe you can get away making cell:nth-child(event) cell:nth-child(odd) work, by using a setup like

cells
 +- cell    <- use this node for odd rows
 +- cell    <- use this node for even rows
Comment 4 Sam P. 2016-05-01 08:12:31 UTC
Created attachment 327103 [details] [review]
Patch to add "row.even" and "row.odd" css nodes

This is my first patch for Gtk+, so I'm pretty hyped.  Please inform me of the noob mistakes that I have made.
Comment 5 Sam P. 2016-05-01 08:21:47 UTC
Created attachment 327104 [details] [review]
Try 2

This patch fixes an unintended added line in the previous patch.

To test, open the gtk3-widget-factory, go to the 3rd page (with the tree view), open gtk+ inspetor and add the following css:

    row.odd { background: blue; }

When you go back to the window, the odd rows will have a blue bg.
Comment 6 Sam P. 2016-05-11 03:13:00 UTC
Hello, are there any updates on reviewing this patch?
Comment 7 Matthias Clasen 2016-05-11 12:46:45 UTC
sorry, I tried it last week and forgot to comment here:

It is a nice start, thanks for doing this patch. There are a few issues though. 

One is that I noticed you don't treat separator rows specially when calculating the row color, which looks wrong (you can see that in the treeview on page 3 of widget-factory.

Another one is problems with selection color - maybe that just needs the theme to be expanded to cover even/odd rows.

And sometimes, the drawing seems to go entirely wrong, mainly when scrolling around. Haven't investigated that further yet.
Comment 8 Benjamin Otte (Company) 2016-05-19 14:52:53 UTC
You can do the same thing as the removed code in commit b65f400d565a3d30a9cd8b686296176f00abefee to get the even/odd thing right.

The parity boolean is still present in the current code even.
Comment 9 Sam P. 2016-06-03 11:02:19 UTC
Created attachment 329033 [details] [review]
Try 3 Patch

Thanks for the review.  Sorry for taking my time on this one.

I think I fixed the separator issue, I now use the same logic as the previous implementation did.

I also bound it to the styled-changed signal, so that hopefully fixes some of the visual glitches that you are seeing.
Comment 10 Sam P. 2016-07-03 01:57:46 UTC
Hello, Do I need to update a tag to indicate that there is a new patch for review?

Thanks,
Sam
Comment 11 Emmanuele Bassi (:ebassi) 2016-08-02 10:17:48 UTC
Review of attachment 329033 [details] [review]:

Is it necessary to have two additional CSS nodes? Wouldn't it be enough to have a single row node to which you can apply different classes when drawing?

::: gtk/gtktreeview.c
@@ +5274,3 @@
 						   node->children?TRUE:FALSE);
 
+          if (_gtk_rbtree_node_get_index (tree, node) % 2) {

Coding style: opening brace goes on a new line, and a new indentation level.

@@ +5276,3 @@
+          if (_gtk_rbtree_node_get_index (tree, node) % 2) {
+            gtk_style_context_save_to_node (context, tree_view->priv->odd_node);
+          } else {

Coding style: closing brace and else go on two separate new lines, i.e.

      ...
    }
  else
    {
      ...

But since you're using a single statement, you can drop the braces altogether.
Comment 12 kevin.nadaud 2016-12-11 19:27:35 UTC
Hi,
In which version of gtk+ the patch will be added ? Would not be more simple to add again the lines which have been deleted corresponding to row and column attributs ?
Cheers
Comment 13 Tomasz Gąsior 2017-10-27 20:48:12 UTC
When this patch will be included to GTK3? Or when this problem will be solved?
Ability to color odd/even rows in `treeview` is very useful and important. Please, implement it.
Comment 14 Tomasz Gąsior 2017-10-27 20:51:50 UTC
treeview {
	-GtkTreeView-allow-rules: true;
	-GtkTreeView-even-row-color: red;
	-GtkTreeView-odd-row-color: blue;
}

This code placed in `~/.config/gtk-3.0/gtk.css` does not work. Will be possible to color odd/even rows in the future?
Comment 15 GNOME Infrastructure Team 2018-05-02 16:50:05 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/gtk/issues/581.