Copyright | Will Thompson Iñaki García Etxebarria and Jonas Platte |
---|---|
License | LGPL-2.1 |
Maintainer | Iñaki García Etxebarria (garetxe@gmail.com) |
Safe Haskell | None |
Language | Haskell2010 |
GI.Gtk.Objects.Button
Contents
- Exported types
- Methods
- clicked
- enter
- getAlignment
- getAlwaysShowImage
- getEventWindow
- getFocusOnClick
- getImage
- getImagePosition
- getLabel
- getRelief
- getUseStock
- getUseUnderline
- leave
- new
- newFromIconName
- newFromStock
- newWithLabel
- newWithMnemonic
- pressed
- released
- setAlignment
- setAlwaysShowImage
- setFocusOnClick
- setImage
- setImagePosition
- setLabel
- setRelief
- setUseStock
- setUseUnderline
- Properties
- Signals
Description
The Button
widget is generally used to trigger a callback function that is
called when the button is pressed. The various signals and how to use them
are outlined below.
The Button
widget can hold any valid child widget. That is, it can hold
almost any other standard Widget
. The most commonly used child is the
Label
.
CSS nodes
GtkButton has a single CSS node with name button. The node will get the style classes .image-button or .text-button, if the content is just an image or label, respectively. It may also receive the .flat style class.
Other style classes that are commonly used with GtkButton include .suggested-action and .destructive-action. In special cases, buttons can be made round by adding the .circular style class.
Button-like widgets like ToggleButton
, MenuButton
, VolumeButton
,
LockButton
, ColorButton
, FontButton
or FileChooserButton
use
style classes such as .toggle, .popup, .scale, .lock, .color, .font, .file
to differentiate themselves from a plain GtkButton.
- newtype Button = Button (ManagedPtr Button)
- class GObject o => IsButton o
- toButton :: (MonadIO m, IsButton o) => o -> m Button
- noButton :: Maybe Button
- buttonClicked :: (HasCallStack, MonadIO m, IsButton a) => a -> m ()
- buttonEnter :: (HasCallStack, MonadIO m, IsButton a) => a -> m ()
- buttonGetAlignment :: (HasCallStack, MonadIO m, IsButton a) => a -> m (Float, Float)
- buttonGetAlwaysShowImage :: (HasCallStack, MonadIO m, IsButton a) => a -> m Bool
- buttonGetEventWindow :: (HasCallStack, MonadIO m, IsButton a) => a -> m Window
- buttonGetFocusOnClick :: (HasCallStack, MonadIO m, IsButton a) => a -> m Bool
- buttonGetImage :: (HasCallStack, MonadIO m, IsButton a) => a -> m (Maybe Widget)
- buttonGetImagePosition :: (HasCallStack, MonadIO m, IsButton a) => a -> m PositionType
- buttonGetLabel :: (HasCallStack, MonadIO m, IsButton a) => a -> m Text
- buttonGetRelief :: (HasCallStack, MonadIO m, IsButton a) => a -> m ReliefStyle
- buttonGetUseStock :: (HasCallStack, MonadIO m, IsButton a) => a -> m Bool
- buttonGetUseUnderline :: (HasCallStack, MonadIO m, IsButton a) => a -> m Bool
- buttonLeave :: (HasCallStack, MonadIO m, IsButton a) => a -> m ()
- buttonNew :: (HasCallStack, MonadIO m) => m Button
- buttonNewFromIconName :: (HasCallStack, MonadIO m) => Maybe Text -> Int32 -> m Button
- buttonNewFromStock :: (HasCallStack, MonadIO m) => Text -> m Button
- buttonNewWithLabel :: (HasCallStack, MonadIO m) => Text -> m Button
- buttonNewWithMnemonic :: (HasCallStack, MonadIO m) => Text -> m Button
- buttonPressed :: (HasCallStack, MonadIO m, IsButton a) => a -> m ()
- buttonReleased :: (HasCallStack, MonadIO m, IsButton a) => a -> m ()
- buttonSetAlignment :: (HasCallStack, MonadIO m, IsButton a) => a -> Float -> Float -> m ()
- buttonSetAlwaysShowImage :: (HasCallStack, MonadIO m, IsButton a) => a -> Bool -> m ()
- buttonSetFocusOnClick :: (HasCallStack, MonadIO m, IsButton a) => a -> Bool -> m ()
- buttonSetImage :: (HasCallStack, MonadIO m, IsButton a, IsWidget b) => a -> b -> m ()
- buttonSetImagePosition :: (HasCallStack, MonadIO m, IsButton a) => a -> PositionType -> m ()
- buttonSetLabel :: (HasCallStack, MonadIO m, IsButton a) => a -> Text -> m ()
- buttonSetRelief :: (HasCallStack, MonadIO m, IsButton a) => a -> ReliefStyle -> m ()
- buttonSetUseStock :: (HasCallStack, MonadIO m, IsButton a) => a -> Bool -> m ()
- buttonSetUseUnderline :: (HasCallStack, MonadIO m, IsButton a) => a -> Bool -> m ()
- constructButtonAlwaysShowImage :: IsButton o => Bool -> IO (GValueConstruct o)
- getButtonAlwaysShowImage :: (MonadIO m, IsButton o) => o -> m Bool
- setButtonAlwaysShowImage :: (MonadIO m, IsButton o) => o -> Bool -> m ()
- constructButtonImage :: (IsButton o, IsWidget a) => a -> IO (GValueConstruct o)
- getButtonImage :: (MonadIO m, IsButton o) => o -> m (Maybe Widget)
- setButtonImage :: (MonadIO m, IsButton o, IsWidget a) => o -> a -> m ()
- constructButtonImagePosition :: IsButton o => PositionType -> IO (GValueConstruct o)
- getButtonImagePosition :: (MonadIO m, IsButton o) => o -> m PositionType
- setButtonImagePosition :: (MonadIO m, IsButton o) => o -> PositionType -> m ()
- constructButtonLabel :: IsButton o => Text -> IO (GValueConstruct o)
- getButtonLabel :: (MonadIO m, IsButton o) => o -> m Text
- setButtonLabel :: (MonadIO m, IsButton o) => o -> Text -> m ()
- constructButtonRelief :: IsButton o => ReliefStyle -> IO (GValueConstruct o)
- getButtonRelief :: (MonadIO m, IsButton o) => o -> m ReliefStyle
- setButtonRelief :: (MonadIO m, IsButton o) => o -> ReliefStyle -> m ()
- constructButtonUseStock :: IsButton o => Bool -> IO (GValueConstruct o)
- getButtonUseStock :: (MonadIO m, IsButton o) => o -> m Bool
- setButtonUseStock :: (MonadIO m, IsButton o) => o -> Bool -> m ()
- constructButtonUseUnderline :: IsButton o => Bool -> IO (GValueConstruct o)
- getButtonUseUnderline :: (MonadIO m, IsButton o) => o -> m Bool
- setButtonUseUnderline :: (MonadIO m, IsButton o) => o -> Bool -> m ()
- constructButtonXalign :: IsButton o => Float -> IO (GValueConstruct o)
- getButtonXalign :: (MonadIO m, IsButton o) => o -> m Float
- setButtonXalign :: (MonadIO m, IsButton o) => o -> Float -> m ()
- constructButtonYalign :: IsButton o => Float -> IO (GValueConstruct o)
- getButtonYalign :: (MonadIO m, IsButton o) => o -> m Float
- setButtonYalign :: (MonadIO m, IsButton o) => o -> Float -> m ()
- type ButtonActivateCallback = IO ()
- type C_ButtonActivateCallback = Ptr () -> Ptr () -> IO ()
- afterButtonActivate :: (IsButton a, MonadIO m) => a -> ButtonActivateCallback -> m SignalHandlerId
- genClosure_ButtonActivate :: ButtonActivateCallback -> IO Closure
- mk_ButtonActivateCallback :: C_ButtonActivateCallback -> IO (FunPtr C_ButtonActivateCallback)
- noButtonActivateCallback :: Maybe ButtonActivateCallback
- onButtonActivate :: (IsButton a, MonadIO m) => a -> ButtonActivateCallback -> m SignalHandlerId
- wrap_ButtonActivateCallback :: ButtonActivateCallback -> Ptr () -> Ptr () -> IO ()
- type ButtonClickedCallback = IO ()
- type C_ButtonClickedCallback = Ptr () -> Ptr () -> IO ()
- afterButtonClicked :: (IsButton a, MonadIO m) => a -> ButtonClickedCallback -> m SignalHandlerId
- genClosure_ButtonClicked :: ButtonClickedCallback -> IO Closure
- mk_ButtonClickedCallback :: C_ButtonClickedCallback -> IO (FunPtr C_ButtonClickedCallback)
- noButtonClickedCallback :: Maybe ButtonClickedCallback
- onButtonClicked :: (IsButton a, MonadIO m) => a -> ButtonClickedCallback -> m SignalHandlerId
- wrap_ButtonClickedCallback :: ButtonClickedCallback -> Ptr () -> Ptr () -> IO ()
- type ButtonEnterCallback = IO ()
- type C_ButtonEnterCallback = Ptr () -> Ptr () -> IO ()
- afterButtonEnter :: (IsButton a, MonadIO m) => a -> ButtonEnterCallback -> m SignalHandlerId
- genClosure_ButtonEnter :: ButtonEnterCallback -> IO Closure
- mk_ButtonEnterCallback :: C_ButtonEnterCallback -> IO (FunPtr C_ButtonEnterCallback)
- noButtonEnterCallback :: Maybe ButtonEnterCallback
- onButtonEnter :: (IsButton a, MonadIO m) => a -> ButtonEnterCallback -> m SignalHandlerId
- wrap_ButtonEnterCallback :: ButtonEnterCallback -> Ptr () -> Ptr () -> IO ()
- type ButtonLeaveCallback = IO ()
- type C_ButtonLeaveCallback = Ptr () -> Ptr () -> IO ()
- afterButtonLeave :: (IsButton a, MonadIO m) => a -> ButtonLeaveCallback -> m SignalHandlerId
- genClosure_ButtonLeave :: ButtonLeaveCallback -> IO Closure
- mk_ButtonLeaveCallback :: C_ButtonLeaveCallback -> IO (FunPtr C_ButtonLeaveCallback)
- noButtonLeaveCallback :: Maybe ButtonLeaveCallback
- onButtonLeave :: (IsButton a, MonadIO m) => a -> ButtonLeaveCallback -> m SignalHandlerId
- wrap_ButtonLeaveCallback :: ButtonLeaveCallback -> Ptr () -> Ptr () -> IO ()
- type ButtonPressedCallback = IO ()
- type C_ButtonPressedCallback = Ptr () -> Ptr () -> IO ()
- afterButtonPressed :: (IsButton a, MonadIO m) => a -> ButtonPressedCallback -> m SignalHandlerId
- genClosure_ButtonPressed :: ButtonPressedCallback -> IO Closure
- mk_ButtonPressedCallback :: C_ButtonPressedCallback -> IO (FunPtr C_ButtonPressedCallback)
- noButtonPressedCallback :: Maybe ButtonPressedCallback
- onButtonPressed :: (IsButton a, MonadIO m) => a -> ButtonPressedCallback -> m SignalHandlerId
- wrap_ButtonPressedCallback :: ButtonPressedCallback -> Ptr () -> Ptr () -> IO ()
- type ButtonReleasedCallback = IO ()
- type C_ButtonReleasedCallback = Ptr () -> Ptr () -> IO ()
- afterButtonReleased :: (IsButton a, MonadIO m) => a -> ButtonReleasedCallback -> m SignalHandlerId
- genClosure_ButtonReleased :: ButtonReleasedCallback -> IO Closure
- mk_ButtonReleasedCallback :: C_ButtonReleasedCallback -> IO (FunPtr C_ButtonReleasedCallback)
- noButtonReleasedCallback :: Maybe ButtonReleasedCallback
- onButtonReleased :: (IsButton a, MonadIO m) => a -> ButtonReleasedCallback -> m SignalHandlerId
- wrap_ButtonReleasedCallback :: ButtonReleasedCallback -> Ptr () -> Ptr () -> IO ()
Exported types
Constructors
Button (ManagedPtr Button) |
class GObject o => IsButton o Source #
Instances
Methods
clicked
Arguments
:: (HasCallStack, MonadIO m, IsButton a) | |
=> a |
|
-> m () |
enter
Arguments
:: (HasCallStack, MonadIO m, IsButton a) | |
=> a |
|
-> m () |
getAlignment
Deprecated: (Since version 3.14)Access the child widget directly if you need to controlits alignment.
Gets the alignment of the child in the button.
Since: 2.4
getAlwaysShowImage
buttonGetAlwaysShowImage Source #
Arguments
:: (HasCallStack, MonadIO m, IsButton a) | |
=> a |
|
-> m Bool | Returns: |
Returns whether the button will ignore the Settings
:gtk-button-images
setting and always show the image, if available.
Since: 3.6
getEventWindow
Arguments
:: (HasCallStack, MonadIO m, IsButton a) | |
=> a |
|
-> m Window | Returns: |
Returns the button’s event window if it is realized, Nothing
otherwise.
This function should be rarely needed.
Since: 2.22
getFocusOnClick
buttonGetFocusOnClick Source #
Arguments
:: (HasCallStack, MonadIO m, IsButton a) | |
=> a |
|
-> m Bool | Returns: |
Deprecated: (Since version 3.20)Use widgetGetFocusOnClick
instead
Returns whether the button grabs focus when it is clicked with the mouse.
See buttonSetFocusOnClick
.
Since: 2.4
getImage
Gets the widget that is currenty set as the image of button
.
This may have been explicitly set by buttonSetImage
or constructed by buttonNewFromStock
.
Since: 2.6
getImagePosition
buttonGetImagePosition Source #
Arguments
:: (HasCallStack, MonadIO m, IsButton a) | |
=> a |
|
-> m PositionType | Returns: the position |
Gets the position of the image relative to the text inside the button.
Since: 2.10
getLabel
Arguments
:: (HasCallStack, MonadIO m, IsButton a) | |
=> a |
|
-> m Text | Returns: The text of the label widget. This string is owned by the widget and must not be modified or freed. |
Fetches the text from the label of the button, as set by
buttonSetLabel
. If the label text has not
been set the return value will be Nothing
. This will be the
case if you create an empty button with buttonNew
to
use as a container.
getRelief
Arguments
:: (HasCallStack, MonadIO m, IsButton a) | |
=> a |
|
-> m ReliefStyle | Returns: The current |
Returns the current relief style of the given Button
.
getUseStock
Arguments
:: (HasCallStack, MonadIO m, IsButton a) | |
=> a |
|
-> m Bool | Returns: |
Deprecated: (Since version 3.10)
Returns whether the button label is a stock item.
getUseUnderline
buttonGetUseUnderline Source #
Arguments
:: (HasCallStack, MonadIO m, IsButton a) | |
=> a |
|
-> m Bool | Returns: |
Returns whether an embedded underline in the button label indicates a mnemonic. See gtk_button_set_use_underline ().
leave
Arguments
:: (HasCallStack, MonadIO m, IsButton a) | |
=> a |
|
-> m () |
new
Arguments
:: (HasCallStack, MonadIO m) | |
=> m Button | Returns: The newly created |
Creates a new Button
widget. To add a child widget to the button,
use containerAdd
.
newFromIconName
buttonNewFromIconName Source #
Arguments
:: (HasCallStack, MonadIO m) | |
=> Maybe Text |
|
-> Int32 |
|
-> m Button | Returns: a new |
Creates a new button containing an icon from the current icon theme.
If the icon name isn’t known, a “broken image” icon will be displayed instead. If the current icon theme is changed, the icon will be updated appropriately.
This function is a convenience wrapper around buttonNew
and
buttonSetImage
.
Since: 3.10
newFromStock
Arguments
:: (HasCallStack, MonadIO m) | |
=> Text |
|
-> m Button | Returns: a new |
Deprecated: (Since version 3.10)Use buttonNewWithLabel
instead.
Creates a new Button
containing the image and text from a stock item.
Some stock ids have preprocessor macros like STOCK_OK
and
STOCK_APPLY
.
If stockId
is unknown, then it will be treated as a mnemonic
label (as for buttonNewWithMnemonic
).
newWithLabel
newWithMnemonic
buttonNewWithMnemonic Source #
Arguments
:: (HasCallStack, MonadIO m) | |
=> Text |
|
-> m Button | Returns: a new |
Creates a new Button
containing a label.
If characters in label
are preceded by an underscore, they are underlined.
If you need a literal underscore character in a label, use “__” (two
underscores). The first underlined character represents a keyboard
accelerator called a mnemonic.
Pressing Alt and that key activates the button.
pressed
Arguments
:: (HasCallStack, MonadIO m, IsButton a) | |
=> a |
|
-> m () |
released
Arguments
:: (HasCallStack, MonadIO m, IsButton a) | |
=> a |
|
-> m () |
setAlignment
setAlwaysShowImage
setFocusOnClick
buttonSetFocusOnClick Source #
Arguments
:: (HasCallStack, MonadIO m, IsButton a) | |
=> a |
|
-> Bool |
|
-> m () |
Deprecated: (Since version 3.20)Use widgetSetFocusOnClick
instead
Sets whether the button will grab focus when it is clicked with the mouse. Making mouse clicks not grab focus is useful in places like toolbars where you don’t want the keyboard focus removed from the main area of the application.
Since: 2.4
setImage
Arguments
:: (HasCallStack, MonadIO m, IsButton a, IsWidget b) | |
=> a |
|
-> b |
|
-> m () |
Set the image of button
to the given widget. The image will be
displayed if the label text is Nothing
or if
Button
:always-show-image
is True
. You don’t have to call
widgetShow
on image
yourself.
Since: 2.6
setImagePosition
buttonSetImagePosition Source #
Arguments
:: (HasCallStack, MonadIO m, IsButton a) | |
=> a |
|
-> PositionType |
|
-> m () |
Sets the position of the image relative to the text inside the button.
Since: 2.10
setLabel
Arguments
:: (HasCallStack, MonadIO m, IsButton a) | |
=> a |
|
-> Text |
|
-> m () |
Sets the text of the label of the button to str
. This text is
also used to select the stock item if buttonSetUseStock
is used.
This will also clear any previously set labels.
setRelief
Arguments
:: (HasCallStack, MonadIO m, IsButton a) | |
=> a |
|
-> ReliefStyle |
|
-> m () |
Sets the relief style of the edges of the given Button
widget.
Two styles exist, ReliefStyleNormal
and ReliefStyleNone
.
The default style is, as one can guess, ReliefStyleNormal
.
The deprecated value ReliefStyleHalf
behaves the same as
ReliefStyleNormal
.
setUseStock
Arguments
:: (HasCallStack, MonadIO m, IsButton a) | |
=> a |
|
-> Bool |
|
-> m () |
Deprecated: (Since version 3.10)
If True
, the label set on the button is used as a
stock id to select the stock item for the button.
setUseUnderline
buttonSetUseUnderline Source #
Arguments
:: (HasCallStack, MonadIO m, IsButton a) | |
=> a |
|
-> Bool |
|
-> m () |
If true, an underline in the text of the button label indicates the next character should be used for the mnemonic accelerator key.
Properties
alwaysShowImage
constructButtonAlwaysShowImage :: IsButton o => Bool -> IO (GValueConstruct o) Source #
image
constructButtonImage :: (IsButton o, IsWidget a) => a -> IO (GValueConstruct o) Source #
imagePosition
constructButtonImagePosition :: IsButton o => PositionType -> IO (GValueConstruct o) Source #
getButtonImagePosition :: (MonadIO m, IsButton o) => o -> m PositionType Source #
setButtonImagePosition :: (MonadIO m, IsButton o) => o -> PositionType -> m () Source #
label
constructButtonLabel :: IsButton o => Text -> IO (GValueConstruct o) Source #
relief
constructButtonRelief :: IsButton o => ReliefStyle -> IO (GValueConstruct o) Source #
getButtonRelief :: (MonadIO m, IsButton o) => o -> m ReliefStyle Source #
setButtonRelief :: (MonadIO m, IsButton o) => o -> ReliefStyle -> m () Source #
useStock
constructButtonUseStock :: IsButton o => Bool -> IO (GValueConstruct o) Source #
useUnderline
constructButtonUseUnderline :: IsButton o => Bool -> IO (GValueConstruct o) Source #
xalign
constructButtonXalign :: IsButton o => Float -> IO (GValueConstruct o) Source #
yalign
constructButtonYalign :: IsButton o => Float -> IO (GValueConstruct o) Source #
Signals
activate
type ButtonActivateCallback = IO () Source #
afterButtonActivate :: (IsButton a, MonadIO m) => a -> ButtonActivateCallback -> m SignalHandlerId Source #
mk_ButtonActivateCallback :: C_ButtonActivateCallback -> IO (FunPtr C_ButtonActivateCallback) Source #
onButtonActivate :: (IsButton a, MonadIO m) => a -> ButtonActivateCallback -> m SignalHandlerId Source #
wrap_ButtonActivateCallback :: ButtonActivateCallback -> Ptr () -> Ptr () -> IO () Source #
clicked
type ButtonClickedCallback = IO () Source #
afterButtonClicked :: (IsButton a, MonadIO m) => a -> ButtonClickedCallback -> m SignalHandlerId Source #
onButtonClicked :: (IsButton a, MonadIO m) => a -> ButtonClickedCallback -> m SignalHandlerId Source #
wrap_ButtonClickedCallback :: ButtonClickedCallback -> Ptr () -> Ptr () -> IO () Source #
enter
type ButtonEnterCallback = IO () Source #
Deprecated: (Since version 2.8)Use the Widget
::enter-notify-event
signal.
afterButtonEnter :: (IsButton a, MonadIO m) => a -> ButtonEnterCallback -> m SignalHandlerId Source #
onButtonEnter :: (IsButton a, MonadIO m) => a -> ButtonEnterCallback -> m SignalHandlerId Source #
wrap_ButtonEnterCallback :: ButtonEnterCallback -> Ptr () -> Ptr () -> IO () Source #
leave
type ButtonLeaveCallback = IO () Source #
Deprecated: (Since version 2.8)Use the Widget
::leave-notify-event
signal.
afterButtonLeave :: (IsButton a, MonadIO m) => a -> ButtonLeaveCallback -> m SignalHandlerId Source #
onButtonLeave :: (IsButton a, MonadIO m) => a -> ButtonLeaveCallback -> m SignalHandlerId Source #
wrap_ButtonLeaveCallback :: ButtonLeaveCallback -> Ptr () -> Ptr () -> IO () Source #
pressed
type ButtonPressedCallback = IO () Source #
Deprecated: (Since version 2.8)Use the Widget
::button-press-event
signal.
afterButtonPressed :: (IsButton a, MonadIO m) => a -> ButtonPressedCallback -> m SignalHandlerId Source #
onButtonPressed :: (IsButton a, MonadIO m) => a -> ButtonPressedCallback -> m SignalHandlerId Source #
wrap_ButtonPressedCallback :: ButtonPressedCallback -> Ptr () -> Ptr () -> IO () Source #
released
type ButtonReleasedCallback = IO () Source #
Deprecated: (Since version 2.8)Use the Widget
::button-release-event
signal.
afterButtonReleased :: (IsButton a, MonadIO m) => a -> ButtonReleasedCallback -> m SignalHandlerId Source #
mk_ButtonReleasedCallback :: C_ButtonReleasedCallback -> IO (FunPtr C_ButtonReleasedCallback) Source #
onButtonReleased :: (IsButton a, MonadIO m) => a -> ButtonReleasedCallback -> m SignalHandlerId Source #
wrap_ButtonReleasedCallback :: ButtonReleasedCallback -> Ptr () -> Ptr () -> IO () Source #