[gtkada] more control when displaying numeric values by a Gtk_Cell_Renderer_Text

Emmanuel Briot briot at adacore.com
Mon Aug 17 15:47:49 CEST 2015


> I have Gtk_List_Store with 1 column of Gtype_Double. In the corresponding Gtk_Tree_View I have a Gtk_Tree_Column with a Gtk_Cell_Renderer_Text (the renderer has attribute "text" added) to show the data. Now the data is shown in standard formatting, something like 1234.56789. But I want the data to be shown with 2 decimal places.
> What I don't want to do is to add an extra column to the store (of type Gtype_String) and have the values stored there as strings.
> 
> At first, Gtk_Tree_Cell_Data_Func seems an obvious choice, but the only thing you can do is add attributes to the renderer or change its properties. And there is no attribute/property that defines how to display Gtype_Doubles.
> 
> How can I achieve more control on how numeric values are displayed by a Gtk_Cell_Renderer_Text?

Rob,

I think the intent from the gtk+ team is that people would create their own cell renderers here.
This is not something we have already done in Ada, so I don't even know whether that is possible.

Another approach you could explore is to use a Gtk_Tree_Model_Filter, which allows you to simulate
extra columns. You could therefore simulate a text column, whose value is automatically computed
from that of your double.

The filter is useful in any case to implement dynamic filtering on a tree (as we do in a lot of places
in GPS for instance), so the added cost is not that much.

regards
Emmanuel


More information about the gtkada mailing list