| Top |
| CtkWidget * | ctk_accel_label_new () |
| void | ctk_accel_label_set_accel_closure () |
| CtkWidget * | ctk_accel_label_get_accel_widget () |
| void | ctk_accel_label_set_accel_widget () |
| guint | ctk_accel_label_get_accel_width () |
| void | ctk_accel_label_set_accel () |
| void | ctk_accel_label_get_accel () |
| gboolean | ctk_accel_label_refetch () |
GObject
╰── GInitiallyUnowned
╰── CtkWidget
╰── CtkMisc
╰── CtkLabel
╰── CtkAccelLabel
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.
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); |
1 2 |
label ╰── accelerator |
Like CtkLabel, CtkAccelLabel has a main CSS node with the name label. It adds a subnode with name accelerator.
CtkWidget *
ctk_accel_label_new (const gchar *string);
Creates a new CtkAccelLabel.
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.
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().
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.
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.
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.
accel_label |
||
accelerator_key |
a keyval, or 0 |
|
accelerator_mods |
the modifier mask for the accel |
Since: 3.6
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().
accel_label |
||
accelerator_key |
return location for the keyval. |
[out] |
accelerator_mods |
return location for the modifier mask. |
[out] |
Since: 3.12
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.
struct CtkAccelLabel;
The CtkAccelLabel contains private data only, and should be accessed using the functions below.
“accel-closure” property “accel-closure” GClosure *
The closure to be monitored for accelerator changes.
Owner: CtkAccelLabel
Flags: Read / Write
“accel-widget” property“accel-widget” CtkWidget *
The widget to be monitored for accelerator changes.
Owner: CtkAccelLabel
Flags: Read / Write