Re: cell word wrapping



On Thu, 2005-01-20 at 00:17 -0500, muppet wrote:
On Jan 19, 2005, at 11:17 PM, Kevin C. Krinke wrote:

Is there a way to set a Gtk2::CellRendererText to word-wrap it's 
contents?

Put newlines in the text strings.

*cough*

*chokes on a cough*

I've been trying with Gtk2::Pango::Layouts but can't figure out how to 
apply them to a cellrenderer.

GtkCellRendererText creates and initializes a new PangoLayout every 
time it needs to calculate the size of a cell or draw a cell.  It's 
also private, so you can't get a handle to it.

Create your own cell renderer and you can do whatever you want with 
your layouts.

This is actually what I was asking about... I'm trying to make a simple
Gtk2::CellRendererWrapText but am finding that my brain is breaking down
somewhere along the way. Perhaps I need to learn more about using the
PangoLayout in general before attempting to do this.

  If you let the renderer wrap, then you'll need some 
"interesting" logic for choosing a size when the column is in autosize 
mode.

Note taken.

  My memory may be fuzzy, but i seem to recall learning while 
writing Mup::CellRendererMultiline in Gtk2/examples/customrenderer.pl 
that there are deficiencies in the TreeView design that make it 
impossible to write a cellrenderer that can change size while editing.  
(I wanted to have a Mac Aqua-style multi-line editable cell in 
Torsten's odot...)

I don't need the cells to be editable at all, in fact, a read-only
situation would be a bonus in this case.

I've also run into the problem of not being able to find any practical 
help regarding Gtk2::Pango::AttrList. I can get an AttrList from 
$cell->get_property( 'attributes' ) but what can I do with it? If I 
try any methods on it I get the "can't call method on an undefined 
value" even though a Dumper() reveals a blessed Gtk2::Pango::AttrList.

It would appear that you have stumbled into one of the back corners of 
the API that we don't have bound.  A PangoAttrList is what Pango markup 
gets parsed into; it's a collection object for PangoAttrs, and, well, 
we never bound it, probably because it seemed pretty esoteric.

Well, as far as I can tell this is how it could be used to wrap text as
a TreeView column_type from the Simple::List:

[code]
add_column_type
 Gtk2::Ex::Simple::List
  ( 'wrap_text',
    type     => 'Glib::Scalar',
    renderer => 'Gtk2::CellRendererText',
    attr     => sub {
                  my ( $treecol, $cell, $model, $iter, $col_num ) = @_;
                  my $info = $model->get( $iter, $col_num );
                  my $pal = new
                             Gtk2::Pango::AttrList
                              ( 'wrap-mode' => 'word' );
                  $cell->set_property( attributes => $pal );
                  $cell->set( markup => $info );
                }
  );
[/code]

However I may be mistaken on this usage of course and without being able
to test it I'm not sure whether Gtk2::Pango::AttrList is even useful.

If you find you need this, we'll get it on the todo list.  If the job 
isn't too big and we can get it tested quickly, we may be able to make 
an API freeze break.  Otherwise, it will have to wait for 1.10x.  :-(

If my thinking in how to use it (as in the above example) is correct
then I'd say it is necessary. Seems it's a must-have for when you want
to change the "attributes" of a Gtk2::Label or Gtk2::CellRendererText
via the set_property() method inherited from Glib::Object.

I won't ask for it to be done ASAP but done sometime in the future would
be good. At the very least a note in Gtk2::Label and
Gtk2::CellRendererText that it doesn't exist would be helpful.

-- 
Kevin C. Krinke <kckrinke opendoorsoftware com>
Open Door Software Inc.




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]