CtkAccelLabel

CtkAccelLabel — A label which displays an accelerator key on the right of the text

Functions

Properties

GClosure * accel-closure Read / Write
CtkWidget * accel-widget Read / Write

Types and Values

struct CtkAccelLabel

Object Hierarchy

    GObject
    ╰── GInitiallyUnowned
        ╰── CtkWidget
            ╰── CtkMisc
                ╰── CtkLabel
                    ╰── CtkAccelLabel

Implemented Interfaces

CtkAccelLabel implements AtkImplementorIface and CtkBuildable.

Includes

#include <ctk/ctk.h>

Description

The CtkAccelLabel widget is a subclass of CtkLabel 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 ctk_accel_label_set_accel()). Instead, the CtkAccelLabel displays the accelerators which have been added to a particular widget. This widget is set by calling ctk_accel_label_set_accel_widget().

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

Note that creating a CtkMenuItem with ctk_menu_item_new_with_label() (or one of the similar functions for CtkCheckMenuItem and CtkRadioMenuItem) automatically adds a CtkAccelLabel to the CtkMenuItem and calls ctk_accel_label_set_accel_widget() to set it up for you.

A CtkAccelLabel will only display accelerators which have CTK_ACCEL_VISIBLE set (see CtkAccelFlags). A CtkAccelLabel 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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
CtkWidget *window = ctk_window_new (CTK_WINDOW_TOPLEVEL);
CtkWidget *menu = ctk_menu_new ();
CtkWidget *save_item;
CtkAccelGroup *accel_group;

// Create a CtkAccelGroup and add it to the window.
accel_group = ctk_accel_group_new ();
ctk_window_add_accel_group (CTK_WINDOW (window), accel_group);

// Create the menu item using the convenience function.
save_item = ctk_menu_item_new_with_label ("Save");
ctk_widget_show (save_item);
ctk_container_add (CTK_CONTAINER (menu), save_item);

// Now add the accelerator to the CtkMenuItem. Note that since we
// called ctk_menu_item_new_with_label() to create the CtkMenuItem
// the CtkAccelLabel is automatically set up to display the
// CtkMenuItem accelerators. We just need to make sure we use
// CTK_ACCEL_VISIBLE here.
ctk_widget_add_accelerator (save_item, "activate", accel_group,
                            CDK_KEY_s, CDK_CONTROL_MASK, CTK_ACCEL_VISIBLE);

CSS nodes

1
2
label
╰── accelerator

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

Functions

ctk_accel_label_new ()

CtkWidget *
ctk_accel_label_new (const gchar *string);

Creates a new CtkAccelLabel.

Parameters

string

the label string. Must be non-NULL.

 

Returns

a new CtkAccelLabel.


ctk_accel_label_set_accel_closure ()

void
ctk_accel_label_set_accel_closure (CtkAccelLabel *accel_label,
                                   GClosure *accel_closure);

Sets the closure to be monitored by this accelerator label. The closure must be connected to an accelerator group; see ctk_accel_group_connect(). Passing NULL for accel_closure will dissociate accel_label from its current closure, if any.

Parameters

accel_label

a CtkAccelLabel

 

accel_closure

the closure to monitor for accelerator changes, or NULL.

[nullable]

ctk_accel_label_get_accel_widget ()

CtkWidget *
ctk_accel_label_get_accel_widget (CtkAccelLabel *accel_label);

Fetches the widget monitored by this accelerator label. See ctk_accel_label_set_accel_widget().

Parameters

accel_label

a CtkAccelLabel

 

Returns

the object monitored by the accelerator label, or NULL.

[nullable][transfer none]


ctk_accel_label_set_accel_widget ()

void
ctk_accel_label_set_accel_widget (CtkAccelLabel *accel_label,
                                  CtkWidget *accel_widget);

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

a CtkAccelLabel

 

accel_widget

the widget to be monitored, or NULL.

[nullable]

ctk_accel_label_get_accel_width ()

guint
ctk_accel_label_get_accel_width (CtkAccelLabel *accel_label);

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

Parameters

accel_label

a CtkAccelLabel.

 

Returns

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


ctk_accel_label_set_accel ()

void
ctk_accel_label_set_accel (CtkAccelLabel *accel_label,
                           guint accelerator_key,
                           CdkModifierType accelerator_mods);

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.

Parameters

accel_label

a CtkAccelLabel

 

accelerator_key

a keyval, or 0

 

accelerator_mods

the modifier mask for the accel

 

Since: 3.6


ctk_accel_label_get_accel ()

void
ctk_accel_label_get_accel (CtkAccelLabel *accel_label,
                           guint *accelerator_key,
                           CdkModifierType *accelerator_mods);

Gets the keyval and modifier mask set with ctk_accel_label_set_accel().

Parameters

accel_label

a CtkAccelLabel

 

accelerator_key

return location for the keyval.

[out]

accelerator_mods

return location for the modifier mask.

[out]

Since: 3.12


ctk_accel_label_refetch ()

gboolean
ctk_accel_label_refetch (CtkAccelLabel *accel_label);

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

a CtkAccelLabel.

 

Returns

always returns FALSE.

Types and Values

struct CtkAccelLabel

struct CtkAccelLabel;

The CtkAccelLabel contains private data only, and should be accessed using the functions below.

Property Details

The “accel-closure” property

  “accel-closure”            GClosure *

The closure to be monitored for accelerator changes.

Owner: CtkAccelLabel

Flags: Read / Write


The “accel-widget” property

  “accel-widget”             CtkWidget *

The widget to be monitored for accelerator changes.

Owner: CtkAccelLabel

Flags: Read / Write

See Also

CtkAccelGroup