Re: Clist column width



Do you mean the lenth of the string in the cell or the actual pixel
length of the cell?

string length is easy: $len = length($clist->get_text($row, $col));

pixel length is damn near impossible as far as I know, the closest I
have gotten is

<CODE>
#!/usr/bin/perl -w

use strict;
use Gtk;

Gtk->init;

my $window = new Gtk::Window;
my $clist  = new_with_titles Gtk::CList("A", "B");
my $font   = $clist->get_style->font;
my @optimal;

$clist->append("this is a string", "hi, I am a string");
$clist->append("this is a number", "12034");

$optimal[0] = $clist->optimal_column_width(0);
$optimal[1] = $clist->optimal_column_width(1);

print "column 0 has width of $optimal[0]\n";
print "column 1 has width of $optimal[1]\n";

$clist->set_column_width(0, $optimal[0]);
$clist->set_column_width(1, $optimal[1]);

for (my $i = 0; $i < 2; $i++) {
   for (my $j = 0; $j < 2; $j++) {
      my $text = $clist->get_text($i, $j);
      my $style = $clist->get_cell_style($i, $j);
      my $f;

      if (defined $style) {
         $f = $style->font;
      } else {
         $f = $font;
      }

      printf "col $j character length = %d and pixel length = %d\n",
             length($text), $f->string_width($text);
   }
}
</CODE>

<OUTPUT>
column 0 has width of 114
column 1 has width of 108
col 0 character length = 16 and pixel length = 77
col 1 character length = 17 and pixel length = 86
col 0 character length = 16 and pixel length = 88
col 1 character length = 5 and pixel length = 35
</OUTPUT>

This seams to show that column length is roughly
$clist->get_style->font->string_length($clist->get_text($row, $col)) +
30.  Of course, if you always set column width to optimal (or any other
size for that matter) you know exactly what the width is.

What do you want to do with the width?


On 06 Jun 2001 17:45:08 +0200, Major Csaba wrote:
 Hi!

How can I get the width of a column? I would like do something like this:
$clist->get_column_width($col); (but this function doesn't exist ;( 

MCS


_______________________________________________
gtk-perl-list mailing list
gtk-perl-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

-- 
Today is Boomtime, the 11st day of Confusion in the YOLD 3167
P'tang!






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