Re: Add spaces
- From: muppet <scott asofyet org>
- To: Beast <beast i6x org>
- Cc: gtk-perl-list gnome org
- Subject: Re: Add spaces
- Date: Fri, 29 Jul 2005 08:25:00 -0400
On Jul 29, 2005, at 2:34 AM, Beast wrote:
In general, how do I add spaces (blank spaces) between the widget?
Each container has its own way of controlling the spacing of its
children. You can also say $widget->set_border_width($pixels) to
place padding on all sides of the widget (on the outside;
Gtk2::Window is a special case which adds border width inside,
because it can't do anything about its outside). But, as you point
out, these are not what you want.
For example, in HBox i can use $hbox->set_spacing(10), it will add
10px space in the left and right, what I need is add space in the
left only.
Sounds like you're trying to implement the Gnome HIG's recommended
way to displaying "frames", which is the bold-faced heading and
indented "children".
According to notes in the HIG, the way to indent grouped blocks is to
pack into the HBox a label whose string is just three spaces. That
way the amount of indentation is related to the current font size.
+------------------------------------------+
| VBox |
|+----------------------------------------+|
|| Bold Label ||
|+----------------------------------------+|
|+----------------------------------------+|
|| HBox ||
||+-----++-------------------------------+||
|||' '|| Contents box |||
||| || |||
||+-----++-------------------------------+||
|+----------------------------------------+|
+------------------------------------------+
Of course, i could just be projecting. :-)
Another evil hack is to use some widget with no contents, but with a
valid size request. I tried a label and an hbox, both worked. This
code uses the Label because it's a little less hackish than an empty
container. ;-)
#!/usr/bin/perl -w
use strict;
use Gtk2 -init;
use Glib ':constants';
my $window = Gtk2::Window->new;
$window->signal_connect (destroy => sub {Gtk2->main_quit});
my $vbox = Gtk2::VBox->new (FALSE, 0); # no padding.
$window->add ($vbox);
foreach (0, 1, 0, 1, 0..10) {
# pack padding is added to *both* sides of the widget, which isn't
# quite what we want here.
#$vbox->pack_start (label ("$_"), FALSE, FALSE, $_);
# instead, pack the widget with no padding...
$vbox->pack_start (label ("$_"), FALSE, FALSE, 0);
# and add spacing manually.
box_add_spacer ($vbox, $_);
}
$window->show_all;
Gtk2->main;
#
# create a label with a colored background so we can see spacing
around it.
#
sub label {
my $ebox = Gtk2::EventBox->new;
$ebox->modify_bg ('normal', Gtk2::Gdk::Color->parse ('blue'));
my $label = Gtk2::Label->new (shift);
$label->show;
$ebox->add ($label);
return $ebox;
}
#
# add a $size-pixel spacer to $box.
#
sub box_add_spacer {
my ($box, $size) = @_;
if ($size > 0) {
my $spacer = Gtk2::Label->new;
if ($box->isa ('Gtk2::VBox')) {
$spacer->set_size_request (0, $_);
} else {
$spacer->set_size_request ($_, 0);
}
$spacer->show;
$box->pack_start ($spacer, FALSE, FALSE, 0);
}
}
--
She's obviously your child. She looks like you, she talks a lot, and
most of it is gibberish.
-- Elysse, to me, of Zella.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]