Hello list :)
I'm currently writing a curses app that part of display a long list of
check boxes. As long as the options are short enough to fit on the page
it looks like this:
[ ] Foo
[X] Bar
[ ] Baz
Which is good :)
But when there are more options that fit on the screen I get:
Your screen is currently too small for this application.
Resize the screen and restart the application.
Press <CTRL-C> to exit...
What I want to do is make the page scrollable, as in if 50 options show
on the page and there are 60 then you see 1..50 and once you tab down to
51 it "scrolls" down to show 2 ..51, 52 it "scrolls" down to 3 .. 52,
etc etc, much like many OS's curses[like] kernel or package configurators.
I've tried different variations of the commented out code and the way it
is now ( -vscrollpos of parent and shift(), and putting the scrolled
Window in another Window)
on my terminal I can do `./curses_scroll.pl 52` ok (IE 52 fit) but
`./curses_scroll.pl 53` gives the error (IE 53 does not fit and it does
not "scroll"
Any ideas how to get it to do this or what I'm doing wrong or a better
way to have a widget whose content will scroll if its longer vertically
than the screen?
#!/usr/bin/perl
use strict;
use warnings;
use Curses::UI;
my $cui = Curses::UI->new();
my $num = defined $ARGV[0] && $ARGV[0] =~ m/^\d+$/ ? $ARGV[0] : 10;
my @checkboxes;
my $off = 1;
for(1 .. $num) {
$off++;
# add a very simple checkbox with no onchange or checked status
since we're just
# trying to get them to fit and are not worried about if they're
check or what they do when they change
push @checkboxes, [
"cb_$_" => 'Checkbox',
-x => 2,
-y => $off,
-onfocus => sub { shift->parentwindow()->{'-vscrollpos'} = $off },
# -onfocus => sub { shift->{'-vscrollpos'} = $off },
-label => "Number $_ of $num",
];
}
#my $pwi = $cui->add(
# 'wi' => 'Window',
# -title => "Scroll $num Please",
#);
#my $wi = $pwi->add(
my $wi = $cui->add(
'wi' => 'Window',
-vscrollbar => 1,
-vscrollpos => 0, # start @ 0 or 1 ???
-vscrolllen => $off + 1,
-title => "Scroll $num Please",
);
for(@checkboxes) {
$wi->add(@{ $_ });
}
$cui->set_binding(
sub { exit; },
'q',
);
$cui->mainloop;
TIA :)
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>