Copyright | Will Thompson and Iñaki García Etxebarria |
---|---|
License | LGPL-2.1 |
Maintainer | Iñaki García Etxebarria |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
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 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 “Ctrl+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 “Ctrl+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 *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
plain code
label ╰── accelerator
Like Label
, GtkAccelLabel has a main CSS node with the name label.
It adds a subnode with name accelerator.
Synopsis
- newtype AccelLabel = AccelLabel (ManagedPtr AccelLabel)
- class (GObject o, IsDescendantOf AccelLabel o) => IsAccelLabel o
- toAccelLabel :: (MonadIO m, IsAccelLabel o) => o -> m AccelLabel
- accelLabelGetAccel :: (HasCallStack, MonadIO m, IsAccelLabel a) => a -> m (Word32, [ModifierType])
- accelLabelGetAccelWidget :: (HasCallStack, MonadIO m, IsAccelLabel a) => a -> m (Maybe Widget)
- accelLabelGetAccelWidth :: (HasCallStack, MonadIO m, IsAccelLabel a) => a -> m Word32
- accelLabelNew :: (HasCallStack, MonadIO m) => Text -> m AccelLabel
- accelLabelRefetch :: (HasCallStack, MonadIO m, IsAccelLabel a) => a -> m Bool
- accelLabelSetAccel :: (HasCallStack, MonadIO m, IsAccelLabel a) => a -> Word32 -> [ModifierType] -> m ()
- accelLabelSetAccelClosure :: (HasCallStack, MonadIO m, IsAccelLabel a) => a -> Maybe (GClosure b) -> m ()
- accelLabelSetAccelWidget :: (HasCallStack, MonadIO m, IsAccelLabel a, IsWidget b) => a -> Maybe b -> m ()
- clearAccelLabelAccelClosure :: (MonadIO m, IsAccelLabel o) => o -> m ()
- constructAccelLabelAccelClosure :: (IsAccelLabel o, MonadIO m) => GClosure a -> m (GValueConstruct o)
- getAccelLabelAccelClosure :: (MonadIO m, IsAccelLabel o) => o -> m (Maybe (GClosure ()))
- setAccelLabelAccelClosure :: (MonadIO m, IsAccelLabel o) => o -> GClosure a -> m ()
- clearAccelLabelAccelWidget :: (MonadIO m, IsAccelLabel o) => o -> m ()
- constructAccelLabelAccelWidget :: (IsAccelLabel o, MonadIO m, IsWidget a) => a -> m (GValueConstruct o)
- getAccelLabelAccelWidget :: (MonadIO m, IsAccelLabel o) => o -> m (Maybe Widget)
- setAccelLabelAccelWidget :: (MonadIO m, IsAccelLabel o, IsWidget a) => o -> a -> m ()
Exported types
newtype AccelLabel Source #
Memory-managed wrapper type.
AccelLabel (ManagedPtr AccelLabel) |
Instances
Eq AccelLabel Source # | |
Defined in GI.Gtk.Objects.AccelLabel (==) :: AccelLabel -> AccelLabel -> Bool # (/=) :: AccelLabel -> AccelLabel -> Bool # | |
GObject AccelLabel Source # | |
Defined in GI.Gtk.Objects.AccelLabel | |
ManagedPtrNewtype AccelLabel Source # | |
Defined in GI.Gtk.Objects.AccelLabel toManagedPtr :: AccelLabel -> ManagedPtr AccelLabel | |
TypedObject AccelLabel Source # | |
Defined in GI.Gtk.Objects.AccelLabel | |
HasParentTypes AccelLabel Source # | |
Defined in GI.Gtk.Objects.AccelLabel | |
IsGValue (Maybe AccelLabel) Source # | Convert |
Defined in GI.Gtk.Objects.AccelLabel gvalueGType_ :: IO GType gvalueSet_ :: Ptr GValue -> Maybe AccelLabel -> IO () gvalueGet_ :: Ptr GValue -> IO (Maybe AccelLabel) | |
type ParentTypes AccelLabel Source # | |
Defined in GI.Gtk.Objects.AccelLabel |
class (GObject o, IsDescendantOf AccelLabel o) => IsAccelLabel o Source #
Type class for types which can be safely cast to AccelLabel
, for instance with toAccelLabel
.
Instances
(GObject o, IsDescendantOf AccelLabel o) => IsAccelLabel o Source # | |
Defined in GI.Gtk.Objects.AccelLabel |
toAccelLabel :: (MonadIO m, IsAccelLabel o) => o -> m AccelLabel Source #
Cast to AccelLabel
, for types for which this is known to be safe. For general casts, use castTo
.
Methods
Click to display all available methods, including inherited ones
Methods
activate, addAccelerator, addChild, addDeviceEvents, addEvents, addMnemonicLabel, addTickCallback, bindProperty, bindPropertyFull, canActivateAccel, childFocus, childNotify, classPath, computeExpand, constructChild, createPangoContext, createPangoLayout, customFinished, customTagEnd, customTagStart, destroy, destroyed, deviceIsShadowed, dragBegin, dragBeginWithCoordinates, dragCheckThreshold, dragDestAddImageTargets, dragDestAddTextTargets, dragDestAddUriTargets, dragDestFindTarget, dragDestGetTargetList, dragDestGetTrackMotion, dragDestSet, dragDestSetProxy, dragDestSetTargetList, dragDestSetTrackMotion, dragDestUnset, dragGetData, dragHighlight, dragSourceAddImageTargets, dragSourceAddTextTargets, dragSourceAddUriTargets, dragSourceGetTargetList, dragSourceSet, dragSourceSetIconGicon, dragSourceSetIconName, dragSourceSetIconPixbuf, dragSourceSetIconStock, dragSourceSetTargetList, dragSourceUnset, dragUnhighlight, draw, ensureStyle, errorBell, event, forceFloating, freezeChildNotify, freezeNotify, getv, grabAdd, grabDefault, grabFocus, grabRemove, hasDefault, hasFocus, hasGrab, hasRcStyle, hasScreen, hasVisibleFocus, hide, hideOnDelete, inDestruction, initTemplate, inputShapeCombineRegion, insertActionGroup, intersect, isAncestor, isComposited, isDrawable, isFloating, isFocus, isSensitive, isToplevel, isVisible, keynavFailed, listAccelClosures, listActionPrefixes, listMnemonicLabels, map, mnemonicActivate, modifyBase, modifyBg, modifyCursor, modifyFg, modifyFont, modifyStyle, modifyText, notify, notifyByPspec, overrideBackgroundColor, overrideColor, overrideCursor, overrideFont, overrideSymbolicColor, parserFinished, path, queueAllocate, queueComputeExpand, queueDraw, queueDrawArea, queueDrawRegion, queueResize, queueResizeNoRedraw, realize, ref, refSink, refetch, regionIntersect, registerWindow, removeAccelerator, removeMnemonicLabel, removeTickCallback, renderIcon, renderIconPixbuf, reparent, resetRcStyles, resetStyle, runDispose, selectRegion, sendExpose, sendFocusChange, shapeCombineRegion, show, showAll, showNow, sizeAllocate, sizeAllocateWithBaseline, sizeRequest, stealData, stealQdata, styleAttach, styleGetProperty, thawChildNotify, thawNotify, translateCoordinates, triggerTooltipQuery, unmap, unparent, unrealize, unref, unregisterWindow, unsetStateFlags, watchClosure.
Getters
getAccel, getAccelWidget, getAccelWidth, getAccessible, getActionGroup, getAlignment, getAllocatedBaseline, getAllocatedHeight, getAllocatedSize, getAllocatedWidth, getAllocation, getAncestor, getAngle, getAppPaintable, getAttributes, getCanDefault, getCanFocus, getChildRequisition, getChildVisible, getClip, getClipboard, getCompositeName, getCurrentUri, getData, getDeviceEnabled, getDeviceEvents, getDirection, getDisplay, getDoubleBuffered, getEllipsize, getEvents, getFocusOnClick, getFontMap, getFontOptions, getFrameClock, getHalign, getHasTooltip, getHasWindow, getHexpand, getHexpandSet, getInternalChild, getJustify, getLabel, getLayout, getLayoutOffsets, getLineWrap, getLineWrapMode, getLines, getMapped, getMarginBottom, getMarginEnd, getMarginLeft, getMarginRight, getMarginStart, getMarginTop, getMaxWidthChars, getMnemonicKeyval, getMnemonicWidget, getModifierMask, getModifierStyle, getName, getNoShowAll, getOpacity, getPadding, getPangoContext, getParent, getParentWindow, getPath, getPointer, getPreferredHeight, getPreferredHeightAndBaselineForWidth, getPreferredHeightForWidth, getPreferredSize, getPreferredWidth, getPreferredWidthForHeight, getProperty, getQdata, getRealized, getReceivesDefault, getRequestMode, getRequisition, getRootWindow, getScaleFactor, getScreen, getSelectable, getSelectionBounds, getSensitive, getSettings, getSingleLineMode, getSizeRequest, getState, getStateFlags, getStyle, getStyleContext, getSupportMultidevice, getTemplateChild, getText, getTooltipMarkup, getTooltipText, getTooltipWindow, getToplevel, getTrackVisitedLinks, getUseMarkup, getUseUnderline, getValign, getValignWithBaseline, getVexpand, getVexpandSet, getVisible, getVisual, getWidthChars, getWindow, getXalign, getYalign.
Setters
setAccel, setAccelClosure, setAccelPath, setAccelWidget, setAlignment, setAllocation, setAngle, setAppPaintable, setAttributes, setBuildableProperty, setCanDefault, setCanFocus, setChildVisible, setClip, setCompositeName, setData, setDataFull, setDeviceEnabled, setDeviceEvents, setDirection, setDoubleBuffered, setEllipsize, setEvents, setFocusOnClick, setFontMap, setFontOptions, setHalign, setHasTooltip, setHasWindow, setHexpand, setHexpandSet, setJustify, setLabel, setLineWrap, setLineWrapMode, setLines, setMapped, setMarginBottom, setMarginEnd, setMarginLeft, setMarginRight, setMarginStart, setMarginTop, setMarkup, setMarkupWithMnemonic, setMaxWidthChars, setMnemonicWidget, setName, setNoShowAll, setOpacity, setPadding, setParent, setParentWindow, setPattern, setProperty, setRealized, setReceivesDefault, setRedrawOnAllocate, setSelectable, setSensitive, setSingleLineMode, setSizeRequest, setState, setStateFlags, setStyle, setSupportMultidevice, setText, setTextWithMnemonic, setTooltipMarkup, setTooltipText, setTooltipWindow, setTrackVisitedLinks, setUseMarkup, setUseUnderline, setValign, setVexpand, setVexpandSet, setVisible, setVisual, setWidthChars, setWindow, setXalign, setYalign.
getAccel
:: (HasCallStack, MonadIO m, IsAccelLabel a) | |
=> a |
|
-> m (Word32, [ModifierType]) |
Gets the keyval and modifier mask set with
accelLabelSetAccel
.
Since: 3.12
getAccelWidget
accelLabelGetAccelWidget Source #
:: (HasCallStack, MonadIO m, IsAccelLabel a) | |
=> a |
|
-> m (Maybe Widget) | Returns: the object monitored by the accelerator label, or |
Fetches the widget monitored by this accelerator label. See
accelLabelSetAccelWidget
.
getAccelWidth
accelLabelGetAccelWidth Source #
:: (HasCallStack, MonadIO m, IsAccelLabel a) | |
=> a |
|
-> 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
:: (HasCallStack, MonadIO m) | |
=> Text |
|
-> m AccelLabel | Returns: a new |
Creates a new AccelLabel
.
refetch
:: (HasCallStack, MonadIO m, IsAccelLabel a) | |
=> a |
|
-> m Bool | Returns: always returns |
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
:: (HasCallStack, MonadIO m, IsAccelLabel a) | |
=> a |
|
-> Word32 |
|
-> [ModifierType] |
|
-> 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 #
:: (HasCallStack, MonadIO m, IsAccelLabel a) | |
=> a |
|
-> Maybe (GClosure b) |
|
-> m () |
Sets the closure to be monitored by this accelerator label. The closure
must be connected to an accelerator group; see accelGroupConnect
.
Passing Nothing
for accelClosure
will dissociate accelLabel
from its
current closure, if any.
setAccelWidget
accelLabelSetAccelWidget Source #
:: (HasCallStack, MonadIO m, IsAccelLabel a, IsWidget b) | |
=> a |
|
-> Maybe b |
|
-> m () |
Sets the widget to be monitored by this accelerator label. Passing Nothing
for
accelWidget
will dissociate accelLabel
from its current widget, if any.
Properties
accelClosure
No description available in the introspection data.
clearAccelLabelAccelClosure :: (MonadIO m, IsAccelLabel o) => o -> m () Source #
Set the value of the “accel-closure
” property to Nothing
.
When overloading is enabled, this is equivalent to
clear
#accelClosure
constructAccelLabelAccelClosure :: (IsAccelLabel o, MonadIO m) => GClosure a -> m (GValueConstruct o) Source #
Construct a GValueConstruct
with valid value for the “accel-closure
” property. This is rarely needed directly, but it is used by new
.
getAccelLabelAccelClosure :: (MonadIO m, IsAccelLabel o) => o -> m (Maybe (GClosure ())) Source #
Get the value of the “accel-closure
” property.
When overloading is enabled, this is equivalent to
get
accelLabel #accelClosure
setAccelLabelAccelClosure :: (MonadIO m, IsAccelLabel o) => o -> GClosure a -> m () Source #
Set the value of the “accel-closure
” property.
When overloading is enabled, this is equivalent to
set
accelLabel [ #accelClosure:=
value ]
accelWidget
No description available in the introspection data.
clearAccelLabelAccelWidget :: (MonadIO m, IsAccelLabel o) => o -> m () Source #
Set the value of the “accel-widget
” property to Nothing
.
When overloading is enabled, this is equivalent to
clear
#accelWidget
constructAccelLabelAccelWidget :: (IsAccelLabel o, MonadIO m, IsWidget a) => a -> m (GValueConstruct o) Source #
Construct a GValueConstruct
with valid value for the “accel-widget
” property. This is rarely needed directly, but it is used by new
.
getAccelLabelAccelWidget :: (MonadIO m, IsAccelLabel o) => o -> m (Maybe Widget) Source #
Get the value of the “accel-widget
” property.
When overloading is enabled, this is equivalent to
get
accelLabel #accelWidget
setAccelLabelAccelWidget :: (MonadIO m, IsAccelLabel o, IsWidget a) => o -> a -> m () Source #
Set the value of the “accel-widget
” property.
When overloading is enabled, this is equivalent to
set
accelLabel [ #accelWidget:=
value ]