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

Dmitry A. Kazakov mailbox at dmitry-kazakov.de
Mon Aug 17 16:16:31 CEST 2015


On Mon, 17 Aug 2015 15:41:45 +0200, you wrote:

> 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?

Yes, you can. You would use the Cell_Render_Text and set its property
"text" formatted as you wished from Cell_Data function.

However there is another problem. When you have fixed-point formatted
values in a tree view, you want all values aligned at their decimal point
positions. So that the decimal points of the cells would be at a straight
vertical line. This can be done only with a custom renderer.

An implementation of such a renderer is here:

http://www.dmitry-kazakov.de/ada/gtkada_contributions.htm#2.5

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


More information about the gtkada mailing list