google
yahoo
bing

GtkCellRenderer bling

I know that a lot of people thing that the whole GtkCellRenderer and GtkTreeView API is a bit complex and intimidating. I am one those that think it is great and very flexible.

One issue with it though is that many applications end up using some custom canvas hacks or HTML implementations when they want to do fancy list views. Consider for example Mugshot and the first Beagle GUI known as Best (which a lot of people think was better than the current!).

It is not possible to implement the old Beagle GUI in a TreeView

It is not possible to implement the old Beagle GUI in a TreeView

I think the reason for this is that it is hard (read: currently impossible) to do more advanced layout in the cells of a treeview. Each row consists of a series of cells lined up next to each other. The cells can consist of text, images, comboboxes, checkboxes what not – thanks to the flexible GtkCellRenderer API. But the constraint is that the cells lie in the same row loosely speaking.

This is not possible to implement in a GtkTreeView atm

It is not possible to implement the Mugshot GUI in a Treeview

So is this just a rant? No.

The Solution, GtkCellRendererComposite

I came up with a solution a good while back. Maybe almost two years ago, but I never got far with it. The solution is to create a new cell renderer that allows you to pack other cellrenderers into it, just like we pack Gtk widgets into boxes. I made a quick Python implementation, that worked more or less:

Early proof-of-concept Python implementation of a composite cell renderer

Early proof-of-concept Python implementation of a composite cell renderer

The ugly colors are just debugging artifacts to make it easier to spot where each sub-cellrenderer is drawn. What you see is a GtkCellRendererText packed in the same composite cellrenderer with a GtkCellRendererTextPixbuf and GtkCellRendererTextToggle.

Anyways; I really want to make this true some day. Then given I implement clickable links in GtkCellRendererText the Mugshot and old Beagle UI should be feasible to implement in a TreeView. Sweet dreams.

5 Responses to “GtkCellRenderer bling”

  1. Marko Anastasov Says:

    I needed to be able to put arbitrary widgets inside a look such as that, so I created a simple tile API in gtkmm-utils.

  2. mikkel.kamstrup Says:

    @Marko For stuff like http://marko.anastasov.name/images/Screenshot-lt-tiles-simple.png I guess?

    The cool thing about doing it with cell renderers is that it will make it work in a lot of places with one swoop; IconView, TreeView, CellView, ComboBoxes, etc.

    Another bonus by using a cell renderer is also that you get the tree layout and navigational model for free. Granted, you only need a list in 75% of all use cases, but it is a nice feature.

  3. wolfer Says:

    Very interesting idea. I currently searching for exactly that, as I don’t want to build a custom HTML implementation for my app (written in python) . Unfortunately you haven’t released any code. Are you working on something or do you know something similar?

    Thanks.

  4. kamstrup Says:

    @wolfer: Sorry, but no. The code I have I a very stupid Python implementation and it is certainly not anything you want to use. It is buggy and incomplete, but demonstrates that it is feasible.

    The most progress I made since this post was to set up and empty autotooled C/Gtk+ project to hack on this. Then I got caught up in tonnes of other projects…

    As it stands I think you are best off with Goocanvas or Hippocanvas if you want to do fancy layout.

  5. rosvall Says:

    Being a complete newbie at gtk programming and needing just that – a composite cellrenderer – i’d really, really love to see your code.

    Pretty please!

Leave a Reply