NAME
TUI::Menus::MenuBar - manages the menu bar at the top of the application
HIERARCHY
TObject
TView
TMenuView
TMenuBar
SYNOPSIS
use TUI::Menus;
my $menuBar = new_TMenuBar($bounds, $menu);
DESCRIPTION
TMenuBar implements the menu bar displayed at the top of a Turbo Vision application. In this Perl implementation, menu structures are created using a declarative, expression-based style rather than explicit builder calls.
Menus are constructed by combining submenu and menu item objects using the overloaded + operator. This allows entire menu trees to be expressed as a single expression that is passed directly to the menu bar constructor.
The resulting structure closely mirrors the logical menu hierarchy while remaining compact and readable. Once created, the menu bar handles drawing, keyboard navigation, and mouse interaction automatically.
CONSTRUCTOR
new
my $menuBar = TMenuBar->new(
bounds => $bounds,
menu => $menu
);
Creates a new menu bar.
- bounds
-
Bounding rectangle of the menu bar (TRect).
-
Root menu structure defining the contents of the menu bar (TMenu or undef).
new_TMenuBar
my $menuBar = new_TMenuBar($bounds, $menu);
Factory-style constructor using positional arguments.
This constructor is equivalent to calling new with named parameters and is provided for compatibility with traditional Turbo Vision construction patterns.
METHODS
draw
$menuBar->draw();
Draws the menu bar and highlights the currently selected menu item.
getItemRect
my $rect = $menuBar->getItemRect($item | undef);
Returns the screen rectangle occupied by the specified menu item. This method is used internally to determine whether a mouse click occurred on a particular menu entry.
EXAMPLE
The following example shows how a menu bar can be constructed using chained menu and submenu objects.
sub initMenuBar {
my ( $class, $r ) = @_;
$r->{b}{y} = $r->{a}{y} + 1;
return new_TMenuBar(
$r,
new_TSubMenu( '~F~ile', hcNoContext )
+ new_TMenuItem( '~O~pen...', cmFileOpen, kbF3, hcNoContext, 'F3' )
+ new_TMenuItem( '~S~ave as...', cmFileSave, hcNoContext )
+ newLine
+ new_TMenuItem( 'E~x~it', cmQuit, kbAltX, hcNoContext, 'Alt-X' )
+ new_TSubMenu( '~H~elp', hcNoContext )
+ new_TMenuItem( '~A~bout', cmAbout, hcNoContext )
);
}
SEE ALSO
TUI::Menus::Menu, TUI::Menus::MenuBox, TUI::Menus::MenuView, TUI::Views::View
AUTHORS
- Borland International (original Turbo Vision design)
- J. Schneider <brickpool@cpan.org> (Perl implementation and maintenance)
COPYRIGHT AND LICENSE
Copyright (c) 1990-1994, 1997 by Borland International
Copyright (c) 2025-2026 the "AUTHORS" as listed above.
This software is licensed under the MIT license (see the LICENSE file, which is part of the distribution).