Curses-UI

 view release on metacpan or  search on metacpan

lib/Curses/UI/Dialog/Status.pm  view on Meta::CPAN


@ISA = qw(
    Curses::UI::Window
    Curses::UI::Common
);

$VERSION = '1.10';

sub new ()
{
    my $class = shift;

    my %userargs = @_;
    keys_to_lowercase(\%userargs);

    my %args = ( 
        -message     => undef,   # The message to show
        -ipad        => 1,
        -border      => 1,
        -width       => undef,
        -height      => undef,
        -fg          => -1,
        -bg          => -1,

        %userargs,

        -centered    => 1,
    );

    my $this = $class->SUPER::new(%args);
    $args{-message} = 'no message' unless defined $args{-message};

    my $l = $this->add(
        'label', 'Label',
        -text  => $this->{-message},
        -fg    => $this->{-fg},
        -bg    => $this->{-bg},
    );

    $this->layout();

    bless $this, $class;
}

# There is no need to focus a status dialog
sub focus() {} ;

sub layout()
{
    my $this = shift;

    my $label = $this->getobj('label');

    # The label might not be added at this point.
    if (defined $label)
    {
        # Compute the width the dialog window needs.
        if (not defined $this->{-width})
        {
            $this->{-width} = $this->width_by_windowscrwidth(
                $label->{-width} + 1, # +1 for visible cursor 
                %$this
            );
        }

        # Compute the height the dialog window needs.
        if (not defined $this->{-height})
        {
            $this->{-height} = $this->height_by_windowscrheight(
                $label->{-height}, 
                %$this
            );
        }

    }

    $this->SUPER::layout or return;

    return $this;
}
    
sub message($;)
{
    my $this = shift;
    my $message = shift;
    $message = 'no message' unless defined $message;
    $this->getobj('label')->text($message);
    return $this;
}

1;


=pod

=head1 NAME

Curses::UI::Dialog::Status - Create and manipulate status dialogs 

=head1 CLASS HIERARCHY

 Curses::UI::Widget
    |
    +----Curses::UI::Container
            |
            +----Curses::UI::Window
                    |
                    +----Curses::UI::Dialog::Status


=head1 SYNOPSIS

    use Curses::UI;
    my $cui = new Curses::UI;
    my $win = $cui->add('window_id', 'Window');

    # The hard way.
    # -------------
    my $dialog = $win->add(
        'mydialog', 'Dialog::Status',
    -message   => 'Hello, world!',



( run in 0.644 second using v1.01-cache-2.11-cpan-39bf76dae61 )