And another TreeView problem, should've used qt ;)
I have a TreeView in which I use the following function to render text:
private void RenderEntryValue (Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
{
(cell as Gtk.CellRendererText).Markup = "" + someMarkupText;
(cell as Gtk.CellRendererText).Alignment = Pango.Alignment.Center;
}
As you might have guessed from the Subject, this does not work. The text remains left-aligned. Any ideas how to make it work, other than adding spaces to the left of it?
There is no other place in the code which would do anything to the TreeView other than adding and feining the columns. And nowhere in there an Alignment is set.
While not a solution, I have at least found a workaround in the form of a custom CellRenderer. Somehow, this does not put the text really at center, but some pixels to the left of it, but that is still a lot better than completely ignoring the alignment ;)
public class CellRendererAlignedText : CellRendererText
{
/**
* Overridden render method to position text correctly.
* */
protected override void Render (Gdk.Drawable window,
Widget widget,
Gdk.Rectangle background_area,
Gdk.Rectangle cell_area,
Gdk.Rectangle expose_area,
CellRendererState flags)
{
if (Alignment == Pango.Alignment.Center)
{
cell_area.X += background_area.Width/4;
cell_area.Width /= 2;
}
base.Render (window, widget, background_area, cell_area, expose_area, flags);
}
}