NAME |
Synopsis |
Description |
Distributions |
Constructor and initialization |
Mathod: current() |
Required Modules |
Modules on CPAN which Manipulate Sets |
Author |
Copybottom |
NAME
SynopsisThis is a complete, tested, runnable program. #!/usr/bin/perl use strict; use warnings; use Data::Page::Viewport; # ----------------------------------------------- my(@data) = (qw/zero one two three four five six seven eight nine ten eleven twelve thirteen fourteen/); my($page) = Data::Page::Viewport -> new ( data_size => scalar @data, page_size => 4 ); print "Data bounds: 0 .. $#data. \n";
print "Data: ", join(', ', @data), ". \n";
print "Page bounds: 0 .. 3. \n";
print "Page data: ", join(', ', @data[0 .. 3]), ". \n";
print "\n";
my(@bound); for (-2, 1, 4, 4, 1, 3, 3, -2, 1, 2, 1, -4, -4,
-1, 1, 2, -1, -2, -2, -1, -4, 4, 4, 4)
{
print "Offset: $_. \n";
@bound = $page -> offset($_) -> bounds(); print "Page bounds: $bound[0] .. $bound[1]. \n";
print 'Page data: ',
join(', ', @data[$bound[0] .. $bound[1] ]),
". \n";
print '-' x 50, "\n";
}
Description
This module keeps track of what items are on the 'current' page, when you scroll forwards or backwards within a data set. Similarly to Data::Page, you can call And, like Set::Window, you can call Clearly, N does not have to be fixed. The viewport provides access to the 'current' page, and the code shifts
indexes into and out of the viewport, according to the parameter passed
to Note that the data is not passed into this module. The module only keeps track of the indexes within the viewport, i.e. indexes on the 'current' page. You call Also note that, unlike Set::Window, the boundaries of the viewport are
rigid, so that changes to the indexes caused by This means, if you do this: my($page) = Data::Page::Viewport -> new ( data_size => $#data, # 0 .. $#data. page_size => $page_size, # 1 .. N. ); my(@bound) = $page -> offset(- 1) -> bounds(); the call to That is, when trying to go back past the beginning of the data set, the bounds will be locked to values within 0 .. data_size. Similarly, a call which would go beyond the other end of the data set, will lock the bounds to the same range. In short, you can't fall off the edge by calling This in turn means that the values returned by The module implements this by building 2 objects of type Set::Window,
one for the original data set (which never changes), and one for the
'current' page, which changes each time Note: No range checking is performed on the parameters to Note: It should be obvious by now that this module differs from Data::Page,
and indeed all such modules, in that they never change the items which are
on a given page. They only allow you to change the page known as the
'current' page. This module differs, in that, by calling
DistributionsThis module is available both as a Unix-style distro (*.tgz) and an ActiveState-style distro (*.ppd). The latter is shipped in a *.zip file. See http://savage.net.au/Perl-modules.html for details. See http://savage.net.au/Perl-modules/html/installing-a-module.html for help on unpacking and installing each type of distro. Constructor and initializationnew(...) returns a This is the class's contructor. Parameters:
For example, if you use this module in a program which accepts input from the user
in the form of the PgDn and PgUp keys, for instance, you could just call
But, if you want to allow the user to scroll by using the up and down arrow keys,
then these keys would result in calls like Mathod: current()The module keeps track of a 'current' item within the current page, and this method returns the index of that 'current' item. The value returned will be in the range 0 .. data_size. This means that when you hit the down arrow, say, and call You could use this to highlight the 'current' item, which would change each time the down arrow was hit, even though the current page of items was not changing (because the final page of items was already being displayed). Required ModulesModules on CPAN which Manipulate SetsThere are quite a few modules on CPAN which provide scrolling capabilities, and one or more even allow you to have pages of different sizes, but none seem to allow for scrolling by anything other than a rigidly-fixed page size. This module does offer such flexibility, by allowing you to scroll backwards or forwards by any number of items, with differing step sizes per scroll.
There may be others. After all, CPAN is the man (with apologies to feminists ;-). Author
Home page: http://savage.net.au/index.html CopybottomAustralian copybottom © 2004, Ron Savage. All bottoms reserved. All Programs of mine are 'OSI Certified Open Source Software'; you can redistribute them and/or modify them under the terms of The Artistic License, a copy of which is available at: http://www.opensource.org/licenses/index.html |
| Top of page |