Curses-UI
view release on metacpan or search on metacpan
lib/Curses/UI/Label.pm view on Meta::CPAN
# ----------------------------------------------------------------------
# Curses::UI::Label
#
# (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
# ----------------------------------------------------------------------
# TODO: fix dox
package Curses::UI::Label;
use strict;
use Curses;
use Curses::UI::Widget;
use Curses::UI::Common;
use vars qw(
$VERSION
@ISA
);
$VERSION = '1.11';
@ISA = qw(
Curses::UI::Widget
);
sub new ()
{
my $class = shift;
my %userargs = @_;
keys_to_lowercase(\%userargs);
my %args = (
-parent => undef, # the parent window
-width => undef, # the width of the label
-height => undef, # the height of the label
-x => 0, # the hor. pos. rel. to the parent
-y => 0, # the vert. pos. rel. to the parent
-text => undef, # the text to show
-textalignment => undef, # left / middle / right
-bold => 0, # Special attributes
-reverse => 0,
-underline => 0,
-dim => 0,
-blink => 0,
-paddingspaces => 0, # Pad text with spaces?
-bg => -1,
-fg => -1,
%userargs,
-nocursor => 1, # This widget uses no cursor
-focusable => 0, # This widget can't be focused
);
# Get the text dimension if -width or -height is undefined.
my @text_dimension = (undef,1);
unless (defined $args{-width} and defined $args{-height}) {
@text_dimension = text_dimension($args{-text})
if defined $args{-text};
}
# If the -height is not set, determine the height
# using the initial contents of the -text.
if (not defined $args{-height})
{
my $l = $text_dimension[1];
$l = 1 if $l <= 0;
$args{-height} = height_by_windowscrheight($l, %args);
}
# No width given? Then make the width the same size
# as the text. No initial text? Then let
# Curses::UI::Widget figure it out.
$args{-width} = width_by_windowscrwidth($text_dimension[0], %args)
unless defined $args{-width} or not defined $args{-text};
# If no text was defined (how silly...) we define an empty string.
$args{-text} = '' unless defined $args{-text};
# Create the widget.
my $this = $class->SUPER::new( %args );
$this->layout();
return $this;
}
sub layout()
{
my $this = shift;
$this->SUPER::layout or return;
return $this;
}
sub bold ($;$) { shift()->set_attribute('-bold', shift()) }
sub reverse ($;$) { shift()->set_attribute('-reverse', shift()) }
sub underline ($;$) { shift()->set_attribute('-underline', shift()) }
sub dim ($;$) { shift()->set_attribute('-dim', shift()) }
sub blink ($;$) { shift()->set_attribute('-blink', shift()) }
sub set_attribute($$;)
{
my $this = shift;
my $attribute = shift;
my $value = shift || 0;
$this->{$attribute} = $value;
$this->intellidraw;
return $this;
( run in 1.337 second using v1.01-cache-2.11-cpan-39bf76dae61 )