[]Struct gtk::Menu

pub struct Menu(_, _);

A Menu is a MenuShell that implements a drop down menu consisting of a list of MenuItem objects which can be navigated and activated by the user to perform application functions.

A Menu is most commonly dropped down by activating a MenuItem in a MenuBar or popped up by activating a MenuItem in another Menu.

A Menu can also be popped up by activating a ComboBox. Other composite widgets such as the Notebook can pop up a Menu as well.

Applications can display a Menu as a popup menu by calling the GtkMenuExt::popup function. The example below shows how an application can pop up a menu when the 3rd mouse button is pressed.

Connecting the popup signal handler.

  // connect our handler which will popup the menu
  g_signal_connect_swapped (window, "button_press_event",
G_CALLBACK (my_popup_handler), menu);

Signal handler which displays a popup menu.

static gint
my_popup_handler (GtkWidget *widget, GdkEvent *event)
{
  GtkMenu *menu;
  GdkEventButton *event_button;

  g_return_val_if_fail (widget != NULL, FALSE);
  g_return_val_if_fail (GTK_IS_MENU (widget), FALSE);
  g_return_val_if_fail (event != NULL, FALSE);

  // The "widget" is the menu that was supplied when
  // g_signal_connect_swapped() was called.
  menu = GTK_MENU (widget);

  if (event->type == GDK_BUTTON_PRESS)
    {
      event_button = (GdkEventButton *) event;
      if (event_button->button == GDK_BUTTON_SECONDARY)
        {
          gtk_menu_popup (menu, NULL, NULL, NULL, NULL,
                          event_button->button, event_button->time);
          return TRUE;
        }
    }

  return FALSE;
}

CSS nodes

menu
├── arrow.top
├── <child>
┊
├── <child>
╰── arrow.bottom

The main CSS node of Menu has name menu, and there are two subnodes with name arrow, for scrolling menu arrows. These subnodes get the .top and .bottom style classes.

Implements

GtkMenuExt, MenuShellExt, ContainerExt, WidgetExt, glib::object::ObjectExt, BuildableExt, GtkMenuExtManual, WidgetExtManual, BuildableExtManual

Methods

impl Menu[src]

pub fn new() -> Menu[src]

Creates a new Menu

Returns

a new Menu

pub fn new_from_model<P: IsA<MenuModel>>(model: &P) -> Menu[src]

Creates a Menu and populates it with menu items and submenus according to model.

The created menu items are connected to actions found in the ApplicationWindow to which the menu belongs - typically by means of being attached to a widget (see GtkMenuExt::attach_to_widget) that is contained within the GtkApplicationWindows widget hierarchy.

Actions can also be added using WidgetExt::insert_action_group on the menu's attach widget or on any of its parent widgets.

model

a gio::MenuModel

Returns

a new Menu

pub fn get_for_attach_widget<P: IsA<Widget>>(widget: &P) -> Vec<Widget>[src]

Returns a list of the menus which are attached to this widget. This list is owned by GTK+ and must not be modified.

widget

a Widget

Returns

the list of menus attached to his widget.

Trait Implementations

impl Clone for Menu

impl Debug for Menu

impl Default for Menu[src]

impl Display for Menu[src]

impl Eq for Menu

impl Hash for Menu

impl IsA<Buildable> for Menu

impl IsA<Container> for Menu

impl IsA<Menu> for RecentChooserMenu

impl IsA<MenuShell> for Menu

impl IsA<Widget> for Menu

impl Ord for Menu

impl<T: ObjectType> PartialEq<T> for Menu

impl<T: ObjectType> PartialOrd<T> for Menu

impl StaticType for Menu

Auto Trait Implementations

impl RefUnwindSafe for Menu

impl !Send for Menu

impl !Sync for Menu

impl Unpin for Menu

impl UnwindSafe for Menu

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<Super, Sub> CanDowncast<Sub> for Super where
    Sub: IsA<Super>,
    Super: IsA<Super>, 

impl<T> Cast for T where
    T: ObjectType, 

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ObjectExt for T where
    T: ObjectType, 

impl<'a, T> ToGlibContainerFromSlice<'a, *const GList> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 

type Storage = (Option<List>, Vec<Stash<'a, <T as GlibPtrDefault>::GlibType, T>>)

impl<'a, T> ToGlibContainerFromSlice<'a, *mut GArray> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 

type Storage = (Option<Array>, Vec<Stash<'a, <T as GlibPtrDefault>::GlibType, T>>)

impl<'a, T> ToGlibContainerFromSlice<'a, *mut GList> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 

type Storage = (Option<List>, Vec<Stash<'a, <T as GlibPtrDefault>::GlibType, T>>)

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T> ToValue for T where
    T: SetValue + ?Sized

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = !

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.