Sanko Robinson > FLTK-0.532009 > FLTK::Cookbook::MenuBar::Label

Download:
FLTK-0.532009.tar.gz

Annotate this POD

Website

View/Report Bugs
Source  

NAME ^

FLTK::Cookbook::MenuBar::Label - Changing MenuItem's Labels At Runtime

Description ^

Demonstrates how to access and change menu items at run time. Click on Edit -> Change to change the contents of the Edit menu.

The Code ^

    use strict;
    use warnings;
    use FLTK;
    my $win = FLTK::Window->new(400, 400);
    $win->begin;
    my $menu = FLTK::MenuBar->new(0, 0, 400, 25);
    $menu->add("File/Quit", FLTK::CTRL() + ord 'q', sub { exit 0 });
    $menu->add(
        "Edit/Change",
        FLTK::CTRL() + ord 'c',
        sub {
            my $p = $menu->find('Edit/Submenu/Original Aaa');
            return if !$p;
            $p->parent->label("New Name");    # Change submenu name
            $p->label('New Aaa');             # Change item name
        }
    );
    $menu->add('Edit/Submenu/Original Aaa');
    $menu->add('Edit/Submenu/Bbb');
    $win->end;
    $win->show;
    exit FLTK::run();

Awknowlegements ^

Code based on the work of Greg Ercolano

Author ^

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

License and Legal ^

Copyright (C) 2008-2009 by Sanko Robinson <sanko@cpan.org>

This program is free software; you can redistribute it and/or modify it under the terms of The Artistic License 2.0. See the 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/.

syntax highlighting: