AntTweakBar

 view release on metacpan or  search on metacpan

lib/AntTweakBar.pm  view on Meta::CPAN

=head2 EXPORT

Constants only


=head1 CONSTANTS

The following constants let AntTweakBar know which graphic system do
you use, to know how to render itself

=head2 TW_OPENGL

Render using plain old OpenGL

=head2 TW_OPENGL_CORE

Render AntTweakBar using OpenGL core profile, which excludes deprecated
OpenGL functions. See: L<https://en.wikipedia.org/wiki/OpenGL_4#OpenGL_3.2>

=head2 TW_DIRECT3D9 (not implemented)

=head2 TW_DIRECT3D10 (not implemented)

=head2 TW_DIRECT3D11 (not implemented)

=cut

require XSLoader;
XSLoader::load('AntTweakBar', $VERSION);


=head1 METHODS

=head2 new

  my $bar = AntTweakBar->new(
    "TweakBar & Perl",
    size  => '200 400',
    color => '96 216 224'
  );

  my $another_bar = AntTweakBar->new(
    "Misc.",
  );


Creates new AntTweakBar instance. Optionally the list of strings of
bar-related parameters can be provided. See the list of available
at L<http://anttweakbar.sourceforge.net/doc/tools:anttweakbar:twbarparamsyntax>.

=cut

sub new {
    my ($class, $name, %bar_params) = @_;
    croak "AntTweakBar name should be specified"
        unless defined $name;
    my $self = {
        _name    => $name,
        _bar_ptr => _create( $name ),
    };
    bless $self => $class;
    $self->set_bar_params(%bar_params);
    return $self;
}

sub DESTROY {
    my $self = shift;
    _destroy($self->{_bar_ptr});
}


sub _as_definition_string {
    my $d = shift;
    return join(' ', map {
        my $key = $_;
        my $value = $d->{$key};
        $value =~ s/'/\\'/g;
        "$key='$value'";
    } sort keys %$d);
}

=head2 add_button

  $bar->add_button(
    name       => 'my_btn',
    cb         => sub { say "clicked!" },
    definition => "label='Click me!'",    # optional
  );

  $bar->add_button(
    name       => 'my_btn',
    cb         => sub { say "clicked!" },
    definition => { # optional
      label => 'Click me!'
    }
  );


The definition parameters are the same as for variable. See
L<http://anttweakbar.sourceforge.net/doc/tools:anttweakbar:varparamsyntax#parameters>.

=cut


sub add_button {
    my ($self, %args) = @_;

    my $name        = $args{name      };
    my $cb          = $args{cb        };
    my $definition  = $args{definition} // "";

    croak "Button name should be specified"
        unless defined $name;
    croak "Button callback should be specified"
        if(!defined($cb) || ref($cb) ne 'CODE');
    $definition = _as_definition_string($definition)
        if ($definition && ref($definition) eq 'HASH');

    _add_button($self->{_bar_ptr}, $name, $cb, $definition);
}

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 1.029 second using v1.00-cache-1.14-grep-28634ff-cpan-4d46879620f )