TreeView widget width != the sum of all cell widths
- From: Samuel <expires200404 debain org>
- To: gtk-perl-list gnome org
- Subject: TreeView widget width != the sum of all cell widths
- Date: Mon, 05 Jan 2004 13:50:24 +0100
Hello,
I have a question regarding the GTK2 TreeView widget.
I am writing a class derived from the TreeView widget that is supposed
to draw something like a multipart progress bar:
+----------------------------------------------------+
| slice 1 | slice 2 | slice 3 |
+----------------------------------------------------+
Thus, I am trying to set the width of all columns manually.
To calculate the width of a single cell, I require the currently visible
width of the treeview.
I use this:
my $rectangle = $self->get_visible_rect;
my $width = $rectangle->width - (2 * $self->get_border_width);
This returns a sane value, but after changing all the cell widths, the
TreeView width is growing by some pixels, even though the calculated
total does not exceed the visible rectangle's width.
So I'm wondering why the sum of all cell widths does not equal the
visible rectangle width.
Where do the additional pixels come from?
I have included all of the relevant code below.
Any hints on how to solve this problem would be greatly appreciated.
Thanks,
-Samuel
----------------------------------------------------------------
The complete class is at
http://sv.nongnu.org/cgi-bin/viewcvs/gnoppix/perl-installer/ui-gtk2/Partitionbar.pm?rev=1.1&content-type=text/vnd.viewcvs-markup
## Purpose: Draw all slices to the GUI.
##
sub _draw {
my $self = shift;
# Calculate the sum of all slices.
my $sum = 0;
foreach my $descr (sort keys %{$self->{columns}}) {
$sum += $self->{columns}{$descr};
}
my $rectangle = $self->get_visible_rect;
my $width = $rectangle->width - (2 * $self->get_border_width);
#my $width = $self->size_request;
print "Width: $width\n";
# Set the width for every single slice.
my $liststore = $self->get_model;
my $iter = $liststore->get_iter_first;
my $colnum = 0;
foreach my $descr (sort keys %{$self->{columns}}) {
my $col = $self->get_column($colnum);
my $renderer = ($col->get_cell_renderers)[0];
print "$colnum, Sum $sum, Size ", $self->{columns}{$descr}, ", Width ", int($width / $sum *
$self->{columns}{$descr}) || 1, "\n";
$liststore->set($iter, $colnum, $descr);
$renderer->set_fixed_size(int($width / $sum * $self->{columns}{$descr}), 40);
$col->set_fixed_width(int($width / $sum * $self->{columns}{$descr}) || 1);
$col->set_visible(1);
$colnum++;
}
}
## Purpose: Hide all slices from the GUI.
##
sub _undraw {
my $self = shift;
my $colnum = 0;
foreach my $descr (keys %{$self->{columns}}) {
my $col = $self->get_column($colnum);
$col->set_visible(0);
$colnum++;
}
}
## Purpose: Update the bar.
##
sub update {
my $self = shift;
$self->_undraw;
$self->_draw;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]