
=pod

=head1 NAME

FLTK::Cookbook::MenuBar::Toggle - Shows how to toggle menu items at run time

=head1 Description

Demonstrates how to toggle a menu item procedurally.  Click on C<Options> to
view the toggled menu items.

=head1 The Code

    use strict;
    use warnings;
    use FLTK;
    my $win = FLTK::Window->new(720, 486);
    my $menubar = FLTK::MenuBar->new(0, 0, 720, 25);
    $win->add($menubar);
    for my $mnu (qw[One Two Three]) {
        $menubar->add("Options/$mnu")->type(FLTK::Widget::TOGGLE());
    }
    $win->show();

    # Test the state changes -- turn 'One' off, others on
    warn 'FAILED[1]' if (SetMenuItemState($menubar, "Options/One",   0) < 0);
    warn 'FAILED[2]' if (SetMenuItemState($menubar, "Options/Two",   1) < 0);
    warn 'FAILED[3]' if (SetMenuItemState($menubar, "Options/Three", 1) < 0);
    exit FLTK::run();

    sub SetMenuItemState {
        my ($self, $name, $state) = @_;
        my $m = $self->find($name);
        return -1 if !$m;
        return $m->set() if $state;
        $m->clear;
        return 0;
    }

=head1 Awknowlegements

Code based on the work of Greg Ercolano

=head1 Author

Sanko Robinson <sanko@cpan.org> - http://sankorobinson.com/

=head1 License and Legal

Copyright (C) 2008-2009 by Sanko Robinson E<lt>sanko@cpan.orgE<gt>

This program is free software; you can redistribute it and/or modify it under
the terms of The Artistic License 2.0.  See the F<LICENSE> file included with
this distribution or http://www.perlfoundation.org/artistic_license_2_0.  For
clarification, see http://www.perlfoundation.org/artistic_2_0_notes.

When separated from the distribution, all original POD documentation is
covered by the Creative Commons Attribution-Share Alike 3.0 License.  See
http://creativecommons.org/licenses/by-sa/3.0/us/legalcode.  For
clarification, see http://creativecommons.org/licenses/by-sa/3.0/us/.

=for git $Id: Toggle.pod 99e9075 2009-10-27 16:07:55Z sanko@cpan.org $

=cut
