GNOME Bugzilla – Bug 318761
Add alignment property to GtkCellRenderText
Last modified: 2011-02-04 16:10:23 UTC
Text cell renderers currently don't have a way of setting the alignment of the text. A patch I'm about to submit for IconView needs this, so here it is.
Created attachment 53412 [details] [review] Add ::alignment property The property defaults to PANGO_ALIGN_LEFT so there is no change by default.
How will this interact with the xalign property thats already there ? See Federicos tests/testcellrenderertext.c
xalign sets the X offset of the text, but if the text wraps and xalign is set to 0.5, you get left-aligned text starting in the middle of the cell. By setting x-align to 0 and alignment to CENTER, you get wrapped centered text.
The use case for this is making GtkIconView look like the nautilus icon view, without alignment multi-line labels are left-aligned, which looks odd.
Ross, can you add something to testcellrenderertext.c to demonstrate this ? That would be great
Created attachment 60745 [details] Modified test This test file (backported from HEAD, 2.8 doesn't have it) adds three rows showing what happens if you have xalign 0 and various PangoAlignment. It does the right thing. Setting xalign 0.5 or xalign 1.0 produces strange output, as the text is being aligned by both Pango and the align property (which simply moves the box inside the container). Note that I couldn't seen to get wrap_chars doing the right thing to demonstrate line wrapping though :(
Ross, I figured out what the problem with wrap-width is. The testcase always explicitly sets ellipsize, which has the side effect of setting ellipsize-set (even if the value is PANGO_ELLIPSIZE_NONE). And gtkcellrenderertext bases some behaviour on the value of ellipsize-set. After fixing that, it turns out that alignment works correctly with wrap-width in RTL but not in LTR...
2006-03-14 Matthias Clasen <mclasen@redhat.com> * tests/testcellrenderertext.c: Add test cases for alignment. * gtk/gtkcellrenderertext.c: Add an alignment property, and fix some cases where ellipsize_set was being used to mean "we're ellipsizing" even when ellipsize was set to NONE. (#318761, Ross Burton)