The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

LibUI::DatePicker - Control to Enter a Date

SYNOPSIS

    use LibUI ':all';
    use LibUI::VBox;
    use LibUI::Window;
    use LibUI::DatePicker;
    use Time::Piece;
    Init && die;
    my $window = LibUI::Window->new( 'Schedule an Event', 320, 100, 0 );
    $window->setMargined( 1 );
    my $box    = LibUI::VBox->new();
    my $date   = LibUI::DatePicker->new();
    $box->append( $date, 0 );
    $date->setTime( Time::Piece->new->add_months(60) );    # Five years from now
    $date->onChanged(
        sub {
            my $picker = shift;
            my $t      = $picker->time;
            warn sprintf 'Setting an appointment for %s', $t->date;
        },
        undef
    );
    $window->setChild($box);
    $window->onClosing(
        sub {
            Quit();
            return 1;
        },
        undef
    );
    $window->show;
    Main();

DESCRIPTION

A LibUI::DatePicker object represents a control used to enter a date.

All functions operate on struct tm as defined in <time.h> which is wrapped by LibUI::Time.

All functions assume local time and do NOT perform any time zone conversions.

Functions

Not a lot here but... well, it's just a simple widget.

new( )

    my $dt = LibUI::DatePicker->new( );

Creates a new date picker.

onChanged( ... )

    $date->onChanged(
    sub {
        my ($ctrl, $data) = @_;
        warn $ctrl->time;
    }, undef);

Registers a callback for when the date picker value is changed by the user.

Expected parameters include:

$callback - CodeRef that should expect the following:
$date - backreference to the instance that initiated the callback
$data - user data registered with the sender instance
$data - user data to be passed to the callback

Note: The callback is not triggered when calling setTime( ... ).

time( ... )

    warn scalar $date->time;

Returns date stored in the date picker.

By default, this returns a Time::Piece object.

setTime( ... )

    $date->setTime( localtime );

Sets date of the date picker.

You may pass a Time::Piece object or a LibUI::Time structure.

See Also

LibUI::TimePicker - Select a time of day

LibUI::DateTimePickerPicker - Select a calendar date and time

LibUI::Time - Wraps the date/time structure

LICENSE

Copyright (C) Sanko Robinson.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHOR

Sanko Robinson <sanko@cpan.org>