 |
|
| |
AG_MENU(3) |
FreeBSD Library Functions Manual |
AG_MENU(3) |
AG_Menu — agar
menu system
#include <agar/core.h>
#include <agar/gui.h>
The AG_Menu widget displays a hierarchical
menu composed of items of the following types:
- Selecting the item causes a specified function to be invoked, with the
specified arguments. See
AG_MenuAction ().
- A menu item tied to a variable describing a boolean value (either an
integer, or specific bits in an integer). Selecting an active boolean item
will toggle the value. See
AG_MenuBool ().
- Separators
- A cosmetic separator, displayed as a horizontal or vertical bar depending
on the display mode. See
AG_MenuSeparator ().
- Dynamic items
- A dynamically updated menu item. The item itself (possibly including child
items) are expected to be generated by a specified callback routine. The
first argument to the callback routine is a pointer to the
AG_MenuItem. An example of a dynamic item would be a
submenu displaying the current contents of a folder. See
AG_MenuDynamicItem ().
Menu elements can be displayed in text format with the
AG_MenuView widget, or in icon format using
AG_Toolbar(3).
Note: Many functions of AG_Menu accept
fn and fnArgs arguments; see
AG_Event(3)
for details on event handler functions in Agar.
AG_Menu *
(AG_Widget
*parent, Uint
flags);
void
AG_MenuExpand (AG_Widget
*parentWidget,
AG_MenuItem *item,
int x,
int y);
The
AG_MenuExpand ()
function creates a new window containing an
AG_MenuView widget displaying the menu items under
item. The optional parentWidget
argument should point to some parent widget or window. The new window is
created at coordinates x, y
relative to parentWidget. The newly created window is
also attached to the parent window of
parentWidget.
AG_MenuItem *
AG_MenuNode (AG_MenuItem
*parent, const char
*text, const AG_Surface
*icon);
AG_MenuItem *
AG_MenuBool (AG_MenuItem
*, const char
*text, const AG_Surface
*icon, int *value,
int invert);
void
AG_MenuSeparator (AG_MenuItem
*item);
AG_PopupMenu *
AG_PopupNew (AG_Widget
*widget);
Once a popup menu is created, new items can be inserted using the
root member of the AG_PopupMenu
structure as parent.
The AG_Menu widget does not generate any
event.
The AG_Menu widget does not provide any
binding.
For the AG_Menu object:
- AG_MenuItem *root
- The root menu item (read-only).
- AG_MenuItem *itemSel
- The currently selected top-level item (read-only). Top-level items are
attached directly to root.
- int selecting
- Selection is in progress if set to 1 (read-only).
For the AG_MenuItem structure:
- Displayed text for the menu item (read-only, set by
AG_MenuSetLabel ()).
- AG_Surface *icon
- The
AG_Surface(3)
of the menu icon, or NULL (read-only, set by
AG_MenuSetIcon ()).
- int value
- The boolean state of the item, used by default. If the boolean state was
bound to another variable (e.g., using
AG_MenuBool ()) then this value will be
ignored.
- int state
- Make item clickable (1) or disabled (0).
- int (*stateFn)(AG_Event *)
- Evaluate function to determine if item is active. Overrides the
state flag.
- AG_Menu *pmenu
- Back pointer to the parent AG_Menu (read-only).
The flags member of the
AG_Menu structure accepts the following flags:
- AG_MENU_HFILL
- Fill any remaining horizontal space (hint to vertically-packing
containers).
- AG_MENU_VFILL
- Fill any remaining vertical space (hint to horizontal-packing
containers).
- Shorthand for
AG_MENU_HFILL |
AG_MENU_VFILL .
- AG_MENU_NO_COLOR_BG
- By default, the "background-color" of menu expansion windows is
inherited from the "color" attribute associated with the
AG_MenuView class (see
AG_Style(3)).
This flag disables that behavior, which can be useful for some
applications (for example, if alternate colors are to be assigned to
specific menu expansions).
- AG_MENU_NO_BOOL_MSG
- By default, a notification message is displayed in order to provide visual
feedback when the user toggles a Menu-bound boolean value with a keyboard
shortcut (and the menu is currently hidden). This flag disables that
behavior.
- AG_MENU_FAST_BOOL_MSG
- By default, the notification message displayed when the user toggles a
boolean is displayed for 1s. This flag causes the message to be displayed
for 250ms instead.
The following code fragment creates a popup menu with a disabled
item:
AG_PopupMenu *pm;
AG_MenuItem *mi;
pm = AG_PopupNew(myParentWidget);
AG_MenuAction(pm->root, "Copy", NULL, DoCopy, NULL);
mi = AG_MenuAction(pm->root, "Paste", NULL, DoPaste, NULL);
mi->state = (myClipboard->contents > 0);
The following code fragment creates a popup menu with a
dynamically determined "disabled" state:
static int
PasteActive(AG_Event *event)
{
Clipboard *C = AG_PTR(1);
return (C->contents > 0);
}
AG_PopupMenu *pm;
AG_MenuItem *mi;
pm = AG_PopupNew(myParentWidget);
AG_MenuAction(pm->root, "Copy", NULL, DoCopy, NULL);
mi = AG_MenuAction(pm->root, "Paste", NULL, DoPaste, NULL);
mi->stateFn = AG_SetIntFn(pm->menu, NULL,
PasteActive, "%p", myClipboard);
The following code fragment associates a menu with an
AG_Toolbar(3).
Buttons and menu entries are created for the same actions.
AG_Toolbar *toolbar;
AG_Menu *menu;
AG_MenuItem *item;
toolbar = AG_ToolbarNew(win, AG_TOOLBAR_HORIZ, 1, 0);
menu = AG_MenuNew(win, 0);
item = AG_MenuNode(menu->root, "File", NULL);
{
AG_MenuToolbar(item, toolbar);
AG_MenuAction(item, "Load", NULL, LoadFile, NULL);
AG_MenuAction(item, "Save", NULL, SaveFile, NULL);
AG_MenuToolbar(item, NULL);
}
The following code fragment creates a menu with an action item, a
boolean item and two bitmask items.
Uint16 flags = 0;
#define FOO_FLAG 0x01
#define BAR_FLAG 0x02
void
SayHello(AG_Event *event)
{
char *s = AG_STRING(1);
AG_TextMsg(AG_MSG_INFO, "Hello, %s!", s);
}
void
QuitApplication(AG_Event *event)
{
AG_Quit();
}
...
AG_Menu *menu = AG_MenuNew(win);
AG_MenuItem *item = AG_MenuNode(menu->root, "File", NULL);
{
AG_MenuInt16Flags(item, "Foo", NULL, &flags, FOO_FLAG, 0);
AG_MenuInt16Flags(item, "Bar", NULL, &flags, BAR_FLAG, 0);
AG_MenuAction(item, "Say hello", NULL,
SayHello, "%s", "world");
AG_MenuAction(item, "Quit", NULL,
QuitApplication, NULL);
}
The AG_Menu widget first appeared in Agar
1.0.
Visit the GSP FreeBSD Man Page Interface. Output converted with ManDoc.
|