[]Struct gtk::AccelLabel

pub struct AccelLabel(_, _);

The AccelLabel widget is a subclass of Label that also displays an accelerator key on the right of the label text, e.g. “Ctrl+S”. It is commonly used in menus to show the keyboard short-cuts for commands.

The accelerator key to display is typically not set explicitly (although it can be, with AccelLabelExt::set_accel). Instead, the AccelLabel displays the accelerators which have been added to a particular widget. This widget is set by calling AccelLabelExt::set_accel_widget.

For example, a MenuItem widget may have an accelerator added to emit the “activate” signal when the “Ctrl+S” key combination is pressed. A AccelLabel is created and added to the MenuItem, and AccelLabelExt::set_accel_widget is called with the MenuItem as the second argument. The AccelLabel will now display “Ctrl+S” after its label.

Note that creating a MenuItem with MenuItem::new_with_label (or one of the similar functions for CheckMenuItem and RadioMenuItem) automatically adds a AccelLabel to the MenuItem and calls AccelLabelExt::set_accel_widget to set it up for you.

A AccelLabel will only display accelerators which have AccelFlags::Visible set (see AccelFlags). A AccelLabel can display multiple accelerators and even signal names, though it is almost always used to display just one accelerator key.

Creating a simple menu item with an accelerator key.

  GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  GtkWidget *menu = gtk_menu_new ();
  GtkWidget *save_item;
  GtkAccelGroup *accel_group;

  // Create a GtkAccelGroup and add it to the window.
  accel_group = gtk_accel_group_new ();
  gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);

  // Create the menu item using the convenience function.
  save_item = gtk_menu_item_new_with_label ("Save");
  gtk_widget_show (save_item);
  gtk_container_add (GTK_CONTAINER (menu), save_item);

  // Now add the accelerator to the GtkMenuItem. Note that since we
  // called gtk_menu_item_new_with_label() to create the GtkMenuItem
  // the GtkAccelLabel is automatically set up to display the
  // GtkMenuItem accelerators. We just need to make sure we use
  // GTK_ACCEL_VISIBLE here.
  gtk_widget_add_accelerator (save_item, "activate", accel_group,
                              GDK_KEY_s, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);

CSS nodes

label
╰── accelerator

Like Label, AccelLabel has a main CSS node with the name label. It adds a subnode with name accelerator.

Implements

AccelLabelExt, LabelExt, MiscExt, WidgetExt, glib::object::ObjectExt, BuildableExt, WidgetExtManual, BuildableExtManual

Implementations

impl AccelLabel[src]

pub fn new(string: &str) -> AccelLabel[src]

Creates a new AccelLabel.

string

the label string. Must be non-None.

Returns

a new AccelLabel.

Trait Implementations

impl Clone for AccelLabel

impl Debug for AccelLabel

impl Display for AccelLabel[src]

impl Eq for AccelLabel

impl Hash for AccelLabel

impl IsA<Buildable> for AccelLabel

impl IsA<Label> for AccelLabel

impl IsA<Misc> for AccelLabel

impl IsA<Widget> for AccelLabel

impl Ord for AccelLabel

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

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

impl StaticType for AccelLabel

Auto Trait Implementations

impl RefUnwindSafe for AccelLabel

impl !Send for AccelLabel

impl !Sync for AccelLabel

impl Unpin for AccelLabel

impl UnwindSafe for AccelLabel

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, *const GPtrArray> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 

type Storage = (Option<PtrArray>, 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<'a, T> ToGlibContainerFromSlice<'a, *mut GPtrArray> for T where
    T: GlibPtrDefault + ToGlibPtr<'a, <T as GlibPtrDefault>::GlibType>, 

type Storage = (Option<PtrArray>, 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 = Infallible

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.