Documentation | InterfaceKit | MenuItem
SYNOPSIS
Perl
use HaikuR1::MenuItem;
my $item = HaikuR1::MenuItem->new(
label => $label,
message => $message,
frame => $frame,
shortcut => $shortcut,
modifiers => $modifiers,
);
$menu->AddItem($item);
Python
from HaikuR1.InterfaceKit import MenuItem
item = MenuItem(
label = label,
message = message,
frame = frame,
shortcut = shortcut,
modifiers = modifiers,
)
menu.AddItem(item)
DESCRIPTION
Exposes the BMenuItem object.
For more information on MenuItem, see the Be Book class description, the Be Book overview, and the Haiku Book class description.
METHODS
Constructor
Creates a MenuItem.
Perl
HaikuR1::MenuItem->new(
label => $label,
message => $message,
shortcut => $shortcut,
modifiers => $modifiers,
);
HaikuR1::MenuItem->new(
menu => $menu,
message => $message,
);
HaikuR1::MenuItem->new($archive);
Python
MenuItem(
label = label,
message = message,
shortcut = shortcut,
modifiers = modifiers,
)
MenuItem(
menu = menu,
message = message,
)
MenuItem(archive)
labelA string, the menu label.
submenuA Menu containing a submenu.
messageA Message that will be sent when the item is selected; optional when creating a submenu item.
shortcutA single character that acts as a shortcut for the menu.
modifiersAn integer combination of modifier key constants.
archiveA Message, contains an archived version of the MenuItem.
ContentLocation
Returns a Rect indicating the area in which the MenuItem should be drawn; meant to be called from within a hook.
Perl
$menuitem->ContentLocation();
Python
menuitem.ContentLocation()
Enabled state
IsEnabled
SetEnabled
Gets or sets the MenuItem's enabled state. SetEnabled can also be called as
a hook.
Perl
$menuitem->IsEnabled(); $menuitem->SetEnabled($enabled);
Python
menuitem.IsEnabled() menuitem.SetEnabled(enabled)
enabledA boolean, the new state.
Frame
Gets the frame.
Perl
$menuitem->Frame();
Python
menuitem.Frame()
IsSelected
Returns true is the MenuItem is selected; meant to be called from within a hook.
Perl
$menuitem->IsSelected();
Python
menuitem.IsSelected()
Label
SetLabel
Gets or sets the MenuItem's label. SetLabel can also be called as a hook.
Perl
$menuitem->Label(); $menuitem->SetLabel($string);
Python
menuitem.Label() menuitem.SetLabel(string)
stringA string, the new label.
Marked state
IsMarked
SetMarked
Gets or sets the MenuItem's marked state. SetMarked can also be called as a
hook.
Perl
$menuitem->IsMarked(); $menuitem->SetMarked($flag);
Python
menuitem.IsMarked() menuitem.SetMarked(flag)
flagA boolean, the new state.
Menu
Returns the parent Menu.
Perl
$menuitem->Menu();
Python
menuitem.Menu()
Shortcut
SetShortcut
Gets or sets the MenuItem's shortcut. SetShortcut can also be called as a
hook.
Perl
$menuitem->Shortcut(); $menuitem->SetShortcut($shortcut, $modifiers);
Python
menuitem.Shortcut() menuitem.SetShortcut(shortcut, modifiers)
shortcutA single character that acts as a shortcut for the menu.
modifiersAn integer combination of modifier key constants.
Submenu
Returns the Menu object for the associated submenu (or the empty value if there is no submenu).
Perl
$menuitem->Submenu();
Python
menuitem.Submenu()
Trigger
SetTrigger
Gets or sets the MenuItem's trigger. SetTrigger can also be called as a
hook.
The difference between a trigger and a shortcut is that a shortcut activates a MenuItem from the owning Window, while a trigger activates a MenuItem when the parent Menu is open on the screen.
The trigger character must be part of the MenuItem's label, and will be underlined. (At least it should be, although as of hrev50791, this doesn't appear to be working.)
A trigger will be automatically selected, so you only need this method if you want to change the default selection.
Perl
$menuitem->Trigger(); $menuitem->SetTrigger($trigger);
Python
menuitem.Trigger() menuitem.SetTrigger(trigger)
triggerA character, the new trigger.
HOOKS
Draw
DrawContent
Highlight
Called when the parent Menu draws the MenuItem.
The default version of Draw draws the background, then calls DrawContent,
then draws the check mark (if any) and the shortcut symbols (if any), then
calls Highlight. It draws within the area specified by Frame.
The default version of DrawContent writes the label. It draws within the
area specified by ContentLocation and
GetContentSize.
The default version of Highlight inverts the colors with the MenuItem's
Frame.
Perl
$menuitem->Draw(); $menuitem->DrawContent(); $menuitem->Highlight($highlight);
Python
menuitem.Draw() menuitem.DrawContent() menuitem.Highlight(highlight)
highlightA boolean indicating whether highlighting is necessary.
GetContentSize
Called when the parent menu is determining its own size. The default version returns the Rect neccesary to display the label. You can override this hook if you want to do something fancy, like displaying an image.
Perl
$menuitem->GetContentSize();
Python
menuitem.GetContentSize()
TruncateLabel
Called when the label needs to be truncated. The default version removes characters from the middle of label and replaces them with an ellipsis.
Do not remove the Trigger character when truncating the label.
Perl
$menuitem->TruncateLabel($maxWidth);
Python
menuitem.TruncateLabel(maxWidth)
maxWidthA floating point number, the maximum width available to display the item.
ARCHIVABLE INTERFACE
MenuItem inherits the methods and hooks of Archivable.
INVOKER INTERFACE
MenuItem inherits the methods and hooks of Invoker.