Gtk.Accel_Label

Entities

Tagged Types

Access Types

Constants

Subprograms

Generic Instantiations

Description

The Gtk.Accel_Label.Gtk_Accel_Label widget is a subclass of Gtk.Label.Gtk_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 Gtk.Accel_Label.Set_Accel). Instead, the Gtk.Accel_Label.Gtk_Accel_Label displays the accelerators which have been added to a particular widget. This widget is set by calling Gtk.Accel_Label.Set_Accel_Widget.

For example, a Gtk.Menu_Item.Gtk_Menu_Item widget may have an accelerator added to emit the "activate" signal when the "Ctrl+S" key combination is pressed. A Gtk.Accel_Label.Gtk_Accel_Label is created and added to the Gtk.Menu_Item.Gtk_Menu_Item, and Gtk.Accel_Label.Set_Accel_Widget is called with the Gtk.Menu_Item.Gtk_Menu_Item as the second argument. The Gtk.Accel_Label.Gtk_Accel_Label will now display "Ctrl+S" after its label.

Note that creating a Gtk.Menu_Item.Gtk_Menu_Item with Gtk.Menu_Item.Gtk_New_With_Label (or one of the similar functions for Gtk.Check_Menu_Item.Gtk_Check_Menu_Item and Gtk.Radio_Menu_Item.Gtk_Radio_Menu_Item) automatically adds a Gtk.Accel_Label.Gtk_Accel_Label to the Gtk.Menu_Item.Gtk_Menu_Item and calls Gtk.Accel_Label.Set_Accel_Widget to set it up for you.

A Gtk.Accel_Label.Gtk_Accel_Label will only display accelerators which have Gtk.Target_List.Accel_Visible set (see Gtk.Accel_Group.Gtk_Accel_Flags). A Gtk.Accel_Label.Gtk_Accel_Label 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.Gtk_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 Gtk.Label.Gtk_Label, GtkAccelLabel has a main CSS node with the name label. It adds a subnode with name accelerator.

"+"

function "+"
  (Widget : access Gtk_Accel_Label_Record'Class)
return Gtk.Buildable.Gtk_Buildable
Parameters
Widget
Return Value

"-"

function "-"
  (Interf : Gtk.Buildable.Gtk_Buildable)
return Gtk_Accel_Label
Parameters
Interf
Return Value

Accel_Closure_Property

Accel_Closure_Property : constant Glib.Properties.Property_String :=
Glib.Properties.Build ("accel-closure");

Unknown type: GObject.Closure

Accel_Widget_Property

Accel_Widget_Property : constant Glib.Properties.Property_Object;

Type: Gtk.Widget.Gtk_Widget

Get_Accel

procedure Get_Accel
   (Accel_Label      : not null access Gtk_Accel_Label_Record;
    Accelerator_Key  : out Gdk.Types.Gdk_Key_Type;
    Accelerator_Mods : out Gdk.Types.Gdk_Modifier_Type)

Gets the keyval and modifier mask set with Gtk.Accel_Label.Set_Accel. Since: gtk+ 3.12

Parameters
Accel_Label
Accelerator_Key

return location for the keyval

Accelerator_Mods

return location for the modifier mask

Get_Accel_Widget

function Get_Accel_Widget
   (Accel_Label : not null access Gtk_Accel_Label_Record)
    return Gtk.Widget.Gtk_Widget

Fetches the widget monitored by this accelerator label. See Gtk.Accel_Label.Set_Accel_Widget.

Parameters
Accel_Label
Return Value

the object monitored by the accelerator label, or null.

Get_Accel_Width

function Get_Accel_Width
   (Accel_Label : not null access Gtk_Accel_Label_Record) return Guint

Returns the width needed to display the accelerator key(s). This is used by menus to align all of the Gtk.Menu_Item.Gtk_Menu_Item widgets, and shouldn't be needed by applications.

Parameters
Accel_Label
Return Value

the width needed to display the accelerator key(s).

Get_Type

function Get_Type return Glib.GType
Return Value

Gtk_Accel_Label

type Gtk_Accel_Label is access all Gtk_Accel_Label_Record'Class;

Gtk_Accel_Label_New

function Gtk_Accel_Label_New
   (String : UTF8_String) return Gtk_Accel_Label

Creates a new Gtk.Accel_Label.Gtk_Accel_Label.

Parameters
String

the label string. Must be non-null.

Return Value

Gtk_Accel_Label_Record

type Gtk_Accel_Label_Record is new Gtk_Label_Record with null record;

Gtk_New

procedure Gtk_New
   (Accel_Label : out Gtk_Accel_Label;
    String      : UTF8_String)

Creates a new Gtk.Accel_Label.Gtk_Accel_Label. Initialize does nothing if the object was already created with another call to Initialize* or G_New.

Parameters
Accel_Label
String

the label string. Must be non-null.

Implements_Gtk_Buildable

package Implements_Gtk_Buildable is new Glib.Types.Implements
  (Gtk.Buildable.Gtk_Buildable, Gtk_Accel_Label_Record, Gtk_Accel_Label);

Initialize

procedure Initialize
   (Accel_Label : not null access Gtk_Accel_Label_Record'Class;
    String      : UTF8_String)

Creates a new Gtk.Accel_Label.Gtk_Accel_Label. Initialize does nothing if the object was already created with another call to Initialize* or G_New.

Parameters
Accel_Label
String

the label string. Must be non-null.

Refetch

function Refetch
   (Accel_Label : not null access Gtk_Accel_Label_Record) return Boolean

Recreates the string representing the accelerator keys. This should not be needed since the string is automatically updated whenever accelerators are added or removed from the associated widget.

Parameters
Accel_Label
Return Value

always returns False.

Set_Accel

procedure Set_Accel
   (Accel_Label      : not null access Gtk_Accel_Label_Record;
    Accelerator_Key  : Gdk.Types.Gdk_Key_Type;
    Accelerator_Mods : Gdk.Types.Gdk_Modifier_Type)

Manually sets a keyval and modifier mask as the accelerator rendered by Accel_Label. If a keyval and modifier are explicitly set then these values are used regardless of any associated accel closure or widget. Providing an Accelerator_Key of 0 removes the manual setting. Since: gtk+ 3.6

Parameters
Accel_Label
Accelerator_Key

a keyval, or 0

Accelerator_Mods

the modifier mask for the accel

Set_Accel_Closure

procedure Set_Accel_Closure
   (Accel_Label   : not null access Gtk_Accel_Label_Record;
    Accel_Closure : System.Address)

Sets the closure to be monitored by this accelerator label. The closure must be connected to an accelerator group; see Gtk.Accel_Group.Connect. Passing null for Accel_Closure will dissociate Accel_Label from its current closure, if any.

Parameters
Accel_Label
Accel_Closure

the closure to monitor for accelerator changes, or null

Set_Accel_Widget

procedure Set_Accel_Widget
   (Accel_Label  : not null access Gtk_Accel_Label_Record;
    Accel_Widget : access Gtk.Widget.Gtk_Widget_Record'Class)

Sets the widget to be monitored by this accelerator label. Passing null for Accel_Widget will dissociate Accel_Label from its current widget, if any.

Parameters
Accel_Label
Accel_Widget

the widget to be monitored, or null