Curses-UI
view release on metacpan or search on metacpan
lib/Curses/UI/Window.pm view on Meta::CPAN
# ----------------------------------------------------------------------
# Curses::UI::Window
#
# (c) 2001-2002 by Maurice Makaay. All rights reserved.
# This file is part of Curses::UI. Curses::UI is free software.
# You can redistribute it and/or modify it under the same terms
# as perl itself.
#
# Currently maintained by Marcus Thiesen
# e-mail: marcus@cpan.thiesenweb.de
# ----------------------------------------------------------------------
package Curses::UI::Window;
use strict;
use Curses;
use Curses::UI::Container;
use Curses::UI::Common;
use vars qw(
$VERSION
@ISA
);
$VERSION = '1.10';
@ISA = qw(
Curses::UI::Container
);
sub new ()
{
my $class = shift;
my %userargs = @_;
keys_to_lowercase(\%userargs);
# Create the window.
my $this = $class->SUPER::new(
-width => undef,
-height => undef,
-x => 0,
-y => 0,
-centered => 0, # Center the window in the display?
%userargs,
-nocursor => 1, # This widget does not use a cursor
-assubwin => 1, # Always constructed as a subwindow
);
return $this;
}
sub layout ()
{
my $this = shift;
# Compute the coordinates of the Window if
# it has to be centered.
if ($this->{-centered})
{
# The maximum available space on the screen.
my $avail_width = $ENV{COLS};
my $avail_height = $ENV{LINES};
# Compute the coordinates for the widget.
my $w = $this->{-width} || 1;
my $h = $this->{-height} || 1;
my $x = int(($avail_width - $w) / 2);
my $y = int(($avail_height - $h) / 2);
$x = 0 if $x < 0;
$y = 0 if $y < 0;
$this->{-x} = $x;
$this->{-y} = $y;
}
$this->SUPER::layout or return;
return $this;
}
1;
=pod
=head1 NAME
Curses::UI::Window - Create and manipulate Window widgets
=head1 CLASS HIERARCHY
Curses::UI::Widget
|
+----Curses::UI::Container
|
+----Curses::UI::Window
=head1 SYNOPSIS
use Curses::UI;
my $cui = new Curses::UI;
my $win = $cui->add(
'window_id', 'Window',
%options,
);
( run in 0.505 second using v1.01-cache-2.11-cpan-39bf76dae61 )