gi-gtk-3.0.11: Gtk bindings

CopyrightWill Thompson, Iñaki García Etxebarria and Jonas Platte
LicenseLGPL-2.1
MaintainerIñaki García Etxebarria (garetxe@gmail.com)
Safe HaskellNone
LanguageHaskell2010

GI.Gtk.Objects.AccelLabel

Contents

Description

The AccelLabel widget is a subclass of Label that also displays an accelerator key on the right of the label text, e.g. “Ctl+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 accelLabelSetAccel). Instead, the AccelLabel displays the accelerators which have been added to a particular widget. This widget is set by calling accelLabelSetAccelWidget.

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

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

A AccelLabel will only display accelerators which have AccelFlagsVisible 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.

C code

 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

plain code

label
╰── accelerator

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

Synopsis

Exported types

Methods

getAccel

accelLabelGetAccel Source #

Arguments

:: (HasCallStack, MonadIO m, IsAccelLabel a) 
=> a

accelLabel: a AccelLabel

-> m (Word32, [ModifierType]) 

Gets the keyval and modifier mask set with accelLabelSetAccel.

Since: 3.12

getAccelWidget

accelLabelGetAccelWidget Source #

Arguments

:: (HasCallStack, MonadIO m, IsAccelLabel a) 
=> a

accelLabel: a AccelLabel

-> m (Maybe Widget)

Returns: the object monitored by the accelerator label, or Nothing.

Fetches the widget monitored by this accelerator label. See accelLabelSetAccelWidget.

getAccelWidth

accelLabelGetAccelWidth Source #

Arguments

:: (HasCallStack, MonadIO m, IsAccelLabel a) 
=> a

accelLabel: a AccelLabel.

-> m Word32

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

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

new

accelLabelNew Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> Text

string: the label string. Must be non-Nothing.

-> m AccelLabel

Returns: a new AccelLabel.

Creates a new AccelLabel.

refetch

accelLabelRefetch Source #

Arguments

:: (HasCallStack, MonadIO m, IsAccelLabel a) 
=> a

accelLabel: a AccelLabel.

-> m Bool

Returns: always returns False.

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.

setAccel

accelLabelSetAccel Source #

Arguments

:: (HasCallStack, MonadIO m, IsAccelLabel a) 
=> a

accelLabel: a AccelLabel

-> Word32

acceleratorKey: a keyval, or 0

-> [ModifierType]

acceleratorMods: the modifier mask for the accel

-> m () 

Manually sets a keyval and modifier mask as the accelerator rendered by accelLabel.

If a keyval and modifier are explicitly set then these values are used regardless of any associated accel closure or widget.

Providing an acceleratorKey of 0 removes the manual setting.

Since: 3.6

setAccelClosure

accelLabelSetAccelClosure Source #

Arguments

:: (HasCallStack, MonadIO m, IsAccelLabel a) 
=> a

accelLabel: a AccelLabel

-> Closure

accelClosure: the closure to monitor for accelerator changes.

-> m () 

Sets the closure to be monitored by this accelerator label. The closure must be connected to an accelerator group; see accelGroupConnect.

setAccelWidget

accelLabelSetAccelWidget Source #

Arguments

:: (HasCallStack, MonadIO m, IsAccelLabel a, IsWidget b) 
=> a

accelLabel: a AccelLabel

-> b

accelWidget: the widget to be monitored.

-> m () 

Sets the widget to be monitored by this accelerator label.

Properties

accelClosure

data AccelLabelAccelClosurePropertyInfo Source #

Instances

AttrInfo AccelLabelAccelClosurePropertyInfo Source # 
type AttrOrigin AccelLabelAccelClosurePropertyInfo Source # 
type AttrLabel AccelLabelAccelClosurePropertyInfo Source # 
type AttrGetType AccelLabelAccelClosurePropertyInfo Source # 
type AttrBaseTypeConstraint AccelLabelAccelClosurePropertyInfo Source # 
type AttrSetTypeConstraint AccelLabelAccelClosurePropertyInfo Source # 
type AttrAllowedOps AccelLabelAccelClosurePropertyInfo Source # 

accelWidget

data AccelLabelAccelWidgetPropertyInfo Source #

Instances

AttrInfo AccelLabelAccelWidgetPropertyInfo Source # 
type AttrOrigin AccelLabelAccelWidgetPropertyInfo Source # 
type AttrLabel AccelLabelAccelWidgetPropertyInfo Source # 
type AttrGetType AccelLabelAccelWidgetPropertyInfo Source # 
type AttrBaseTypeConstraint AccelLabelAccelWidgetPropertyInfo Source # 
type AttrSetTypeConstraint AccelLabelAccelWidgetPropertyInfo Source # 
type AttrAllowedOps AccelLabelAccelWidgetPropertyInfo Source #