gi-gtk4-4.0.12: Gtk 4.x bindings

Copyright | Will Thompson and Iñaki García Etxebarria
License | LGPL-2.1
Maintainer | Iñaki García Etxebarria
Safe Haskell | None
Language | Haskell2010

GI.Gtk.Objects.ToggleButton

Contents

- Exported types
- Methods
  - getActive
  - new
  - newWithLabel
  - newWithMnemonic
  - setActive
  - setGroup
  - toggled
- Properties
  - active
  - group
- Signals
  - toggled

Description

Shows a button which remains “pressed-in” when clicked.

<picture> <source srcset="toggle-button-dark.png" media="(prefers-color-scheme: dark)"> <img alt="Example GtkToggleButtons" src="toggle-button.png"> </picture>

Clicking again will cause the toggle button to return to its normal state.

A toggle button is created by calling either `toggleButtonNew` or `toggleButtonNewWithLabel`. If using the former, it is advisable to pack a widget, (such as a `GtkLabel` and/or a `GtkImage`), into the toggle button’s container. (See `Button` for more information).

The state of a `GtkToggleButton` can be set specifically using `toggleButtonSetActive`, and retrieved using `toggleButtonGetActive`.

## Grouping

Toggle buttons can be grouped together, to form mutually exclusive groups - only one of the buttons can be toggled at a time, and toggling another one will switch the currently toggled one off.

To add a `GtkToggleButton` to a group, use `toggleButtonSetGroup`.

## CSS nodes

`GtkToggleButton` has a single CSS node with name button. To differentiate it from a plain `GtkButton`, it gets the `.toggle` style class.

## Accessibility

`GtkToggleButton` uses the `AccessibleRoleToggleButton` role.

## Creating two `GtkToggleButton` widgets.

### c code

    static void
    output_state (GtkToggleButton *source,
                  gpointer         user_data)
    {
      g_print ("Toggle button "%s" is active: %s",
               gtk_button_get_label (GTK_BUTTON (source)),
               gtk_toggle_button_get_active (source) ? "Yes" : "No");
    }

    static void
    make_toggles (void)
    {
      GtkWidget *window, *toggle1, *toggle2;
      GtkWidget *box;
      const char *text;

      window = gtk_window_new ();
      box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);

      text = "Hi, I’m toggle button one";
      toggle1 = gtk_toggle_button_new_with_label (text);

      g_signal_connect (toggle1, "toggled",
                        G_CALLBACK (output_state),
                        NULL);
      gtk_box_append (GTK_BOX (box), toggle1);

      text = "Hi, I’m toggle button two";
      toggle2 = gtk_toggle_button_new_with_label (text);
      g_signal_connect (toggle2, "toggled",
                        G_CALLBACK (output_state),
                        NULL);
      gtk_box_append (GTK_BOX (box), toggle2);

      gtk_window_set_child (GTK_WINDOW (window), box);
      gtk_window_present (GTK_WINDOW (window));
    }

Synopsis

- newtype ToggleButton = ToggleButton (ManagedPtr ToggleButton)
- class (GObject o, IsDescendantOf ToggleButton o) => IsToggleButton o
- toToggleButton :: (MonadIO m, IsToggleButton o) => o -> m ToggleButton
- toggleButtonGetActive :: (HasCallStack, MonadIO m, IsToggleButton a) => a -> m Bool
- toggleButtonNew :: (HasCallStack, MonadIO m) => m ToggleButton
- toggleButtonNewWithLabel :: (HasCallStack, MonadIO m) => Text -> m ToggleButton
- toggleButtonNewWithMnemonic :: (HasCallStack, MonadIO m) => Text -> m ToggleButton
- toggleButtonSetActive :: (HasCallStack, MonadIO m, IsToggleButton a) => a -> Bool -> m ()
- toggleButtonSetGroup :: (HasCallStack, MonadIO m, IsToggleButton a, IsToggleButton b) => a -> Maybe b -> m ()
- toggleButtonToggled :: (HasCallStack, MonadIO m, IsToggleButton a) => a -> m ()
- constructToggleButtonActive :: (IsToggleButton o, MonadIO m) => Bool -> m (GValueConstruct o)
- getToggleButtonActive :: (MonadIO m, IsToggleButton o) => o -> m Bool
- setToggleButtonActive :: (MonadIO m, IsToggleButton o) => o -> Bool -> m ()
- clearToggleButtonGroup :: (MonadIO m, IsToggleButton o) => o -> m ()
- constructToggleButtonGroup :: (IsToggleButton o, MonadIO m, IsToggleButton a) => a -> m (GValueConstruct o)
- setToggleButtonGroup :: (MonadIO m, IsToggleButton o, IsToggleButton a) => o -> a -> m ()
- type ToggleButtonToggledCallback = IO ()
- afterToggleButtonToggled :: (IsToggleButton a, MonadIO m) => a -> ((?self :: a) => ToggleButtonToggledCallback) -> m SignalHandlerId
- onToggleButtonToggled :: (IsToggleButton a, MonadIO m) => a -> ((?self :: a) => ToggleButtonToggledCallback) -> m SignalHandlerId

# Exported types

newtype ToggleButton Source #

Memory-managed wrapper type.

Constructors

ToggleButton (ManagedPtr ToggleButton) |

#### Instances

Instances details

Eq ToggleButton Source # |
Instance details Defined in GI.Gtk.Objects.ToggleButton Methods (==) :: ToggleButton -> ToggleButton -> Bool Source # (/=) :: ToggleButton -> ToggleButton -> Bool Source #
GObject ToggleButton Source # |
Instance details Defined in GI.Gtk.Objects.ToggleButton
ManagedPtrNewtype ToggleButton Source # |
Instance details Defined in GI.Gtk.Objects.ToggleButton Methods toManagedPtr :: ToggleButton -> ManagedPtr ToggleButton Source #
TypedObject ToggleButton Source # |
Instance details Defined in GI.Gtk.Objects.ToggleButton Methods glibType :: IO GType Source #
HasParentTypes ToggleButton Source # |
Instance details Defined in GI.Gtk.Objects.ToggleButton
IsGValue (Maybe ToggleButton) Source # | Convert `ToggleButton` to and from `GValue`. See `toGValue` and `fromGValue`.
Instance details Defined in GI.Gtk.Objects.ToggleButton Methods gvalueGType_ :: IO GType Source # gvalueSet_ :: Ptr GValue -> Maybe ToggleButton -> IO () Source # gvalueGet_ :: Ptr GValue -> IO (Maybe ToggleButton) Source #
type ParentTypes ToggleButton Source # |
Instance details Defined in GI.Gtk.Objects.ToggleButton type ParentTypes ToggleButton = '[Button, Widget, Object, Accessible, Actionable, Buildable, ConstraintTarget]

class (GObject o, IsDescendantOf ToggleButton o) => IsToggleButton o Source #

Type class for types which can be safely cast to `ToggleButton`, for instance with `toToggleButton`.

#### Instances

Instances details

(GObject o, IsDescendantOf ToggleButton o) => IsToggleButton o Source # |
Instance details Defined in GI.Gtk.Objects.ToggleButton

toToggleButton :: (MonadIO m, IsToggleButton o) => o -> m ToggleButton Source #

Cast to `ToggleButton`, 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

Expand

#### Methods

actionSetEnabled, activate, activateAction, activateDefault, addController, addCssClass, addMnemonicLabel, addTickCallback, allocate, announce, bindProperty, bindPropertyFull, childFocus, computeBounds, computeExpand, computePoint, computeTransform, contains, createPangoContext, createPangoLayout, disposeTemplate, dragCheckThreshold, errorBell, forceFloating, freezeNotify, getv, grabFocus, hasCssClass, hasDefault, hasFocus, hasVisibleFocus, hide, inDestruction, initTemplate, insertActionGroup, insertAfter, insertBefore, isAncestor, isDrawable, isFloating, isFocus, isSensitive, isVisible, keynavFailed, listMnemonicLabels, map, measure, mnemonicActivate, notify, notifyByPspec, observeChildren, observeControllers, pick, queueAllocate, queueDraw, queueResize, realize, ref, refSink, removeController, removeCssClass, removeMnemonicLabel, removeTickCallback, resetProperty, resetRelation, resetState, runDispose, shouldLayout, show, sizeAllocate, snapshotChild, stealData, stealQdata, thawNotify, toggled, translateCoordinates, triggerTooltipQuery, unmap, unparent, unrealize, unref, unsetStateFlags, updateNextAccessibleSibling, updatePlatformState, updateProperty, updateRelation, updateState, watchClosure.

#### Getters

getAccessibleId, getAccessibleParent, getAccessibleRole, getActionName, getActionTargetValue, getActive, getAllocatedBaseline, getAllocatedHeight, getAllocatedWidth, getAllocation, getAncestor, getAtContext, getBaseline, getBounds, getBuildableId, getCanFocus, getCanShrink, getCanTarget, getChild, getChildVisible, getClipboard, getColor, getCssClasses, getCssName, getCursor, getData, getDirection, getDisplay, getFirstAccessibleChild, getFirstChild, getFocusChild, getFocusOnClick, getFocusable, getFontMap, getFontOptions, getFrameClock, getHalign, getHasFrame, getHasTooltip, getHeight, getHexpand, getHexpandSet, getIconName, getLabel, getLastChild, getLayoutManager, getLimitEvents, getMapped, getMarginBottom, getMarginEnd, getMarginStart, getMarginTop, getName, getNative, getNextAccessibleSibling, getNextSibling, getOpacity, getOverflow, getPangoContext, getParent, getPlatformState, getPreferredSize, getPrevSibling, getPrimaryClipboard, getProperty, getQdata, getRealized, getReceivesDefault, getRequestMode, getRoot, getScaleFactor, getSensitive, getSettings, getSize, getSizeRequest, getStateFlags, getStyleContext, getTemplateChild, getTooltipMarkup, getTooltipText, getUseUnderline, getValign, getVexpand, getVexpandSet, getVisible, getWidth.

#### Setters

setAccessibleParent, setActionName, setActionTargetValue, setActive, setCanFocus, setCanShrink, setCanTarget, setChild, setChildVisible, setCssClasses, setCursor, setCursorFromName, setData, setDataFull, setDetailedActionName, setDirection, setFocusChild, setFocusOnClick, setFocusable, setFontMap, setFontOptions, setGroup, setHalign, setHasFrame, setHasTooltip, setHexpand, setHexpandSet, setIconName, setLabel, setLayoutManager, setLimitEvents, setMarginBottom, setMarginEnd, setMarginStart, setMarginTop, setName, setOpacity, setOverflow, setParent, setProperty, setReceivesDefault, setSensitive, setSizeRequest, setStateFlags, setTooltipMarkup, setTooltipText, setUseUnderline, setValign, setVexpand, setVexpandSet, setVisible.

## getActive

toggleButtonGetActive Source #

Arguments

:: (HasCallStack, MonadIO m, IsToggleButton a) |
=> a | `toggleButton`: a `GtkToggleButton`.
-> m Bool | Returns: whether the button is pressed

Queries a `GtkToggleButton` and returns its current state.

Returns `True` if the toggle button is pressed in and `False` if it is raised.

## new

toggleButtonNew Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> m ToggleButton | Returns: a new toggle button.

Creates a new toggle button.

A widget should be packed into the button, as in `buttonNew`.

## newWithLabel

toggleButtonNewWithLabel Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Text | `label`: a string containing the message to be placed in the toggle button.
-> m ToggleButton | Returns: a new toggle button.

Creates a new toggle button with a text label.

## newWithMnemonic

toggleButtonNewWithMnemonic Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Text | `label`: the text of the button, with an underscore in front of the mnemonic character
-> m ToggleButton | Returns: a new `GtkToggleButton`

Creates a new `GtkToggleButton` containing a label.

The label will be created using `labelNewWithMnemonic`, so underscores in `label` indicate the mnemonic for the button.

## setActive

toggleButtonSetActive Source #

Arguments

:: (HasCallStack, MonadIO m, IsToggleButton a) |
=> a | `toggleButton`: a `GtkToggleButton`.
-> Bool | `isActive`: `True` or `False`.
-> m () |

Sets the status of the toggle button.

Set to `True` if you want the `GtkToggleButton` to be “pressed in”, and `False` to raise it.

If the status of the button changes, this action causes the ToggleButton::toggled signal to be emitted.

## setGroup

toggleButtonSetGroup Source #

Arguments

:: (HasCallStack, MonadIO m, IsToggleButton a, IsToggleButton b) |
=> a | `toggleButton`: a `GtkToggleButton`
-> Maybe b | `group`: another `GtkToggleButton` to form a group with
-> m () |

Adds `self` to the group of `group`.

In a group of multiple toggle buttons, only one button can be active at a time.

Setting up groups in a cycle leads to undefined behavior.

Note that the same effect can be achieved via the `Actionable` API, by using the same action with parameter type and state type 's' for all buttons in the group, and giving each button its own target value.

## toggled

toggleButtonToggled Source #

Arguments

:: (HasCallStack, MonadIO m, IsToggleButton a) |
=> a | `toggleButton`: a `GtkToggleButton`.
-> m () |

Deprecated: (Since version 4.10)There is no good reason for an application ever to call this function.

Emits the toggled signal on the `GtkToggleButton`.

# Properties

## active

If the toggle button should be pressed in.

constructToggleButtonActive :: (IsToggleButton o, MonadIO m) => Bool -> m (GValueConstruct o) Source #

Construct a `GValueConstruct` with valid value for the “`active`” property. This is rarely needed directly, but it is used by `new`.

getToggleButtonActive :: (MonadIO m, IsToggleButton o) => o -> m Bool Source #

Get the value of the “`active`” property. When overloading is enabled, this is equivalent to

    get toggleButton #active

setToggleButtonActive :: (MonadIO m, IsToggleButton o) => o -> Bool -> m () Source #

Set the value of the “`active`” property. When overloading is enabled, this is equivalent to

    set toggleButton [ #active := value ]

## group

The toggle button whose group this widget belongs to.

clearToggleButtonGroup :: (MonadIO m, IsToggleButton o) => o -> m () Source #

Set the value of the “`group`” property to `Nothing`. When overloading is enabled, this is equivalent to

    clear #group

constructToggleButtonGroup :: (IsToggleButton o, MonadIO m, IsToggleButton a) => a -> m (GValueConstruct o) Source #

Construct a `GValueConstruct` with valid value for the “`group`” property. This is rarely needed directly, but it is used by `new`.

setToggleButtonGroup :: (MonadIO m, IsToggleButton o, IsToggleButton a) => o -> a -> m () Source #

Set the value of the “`group`” property. When overloading is enabled, this is equivalent to

    set toggleButton [ #group := value ]

# Signals

## toggled

type ToggleButtonToggledCallback = IO () Source #

Emitted whenever the `GtkToggleButton`'s state is changed.

afterToggleButtonToggled :: (IsToggleButton a, MonadIO m) => a -> ((?self :: a) => ToggleButtonToggledCallback) -> m SignalHandlerId Source #

Connect a signal handler for the toggled signal, to be run after the default handler. When overloading is enabled, this is equivalent to

    after toggleButton #toggled callback

By default the object invoking the signal is not passed to the callback. If you need to access it, you can use the implit `?self` parameter. Note that this requires activating the `ImplicitParams` GHC extension.

onToggleButtonToggled :: (IsToggleButton a, MonadIO m) => a -> ((?self :: a) => ToggleButtonToggledCallback) -> m SignalHandlerId Source #

Connect a signal handler for the toggled signal, to be run before the default handler. When overloading is enabled, this is equivalent to

    on toggleButton #toggled callback