Package ch.bailu.gtk.gtk
Class Button
- All Implemented Interfaces:
PointerInterface
- Direct Known Subclasses:
LinkButton
,LockButton
,ToggleButton
The `GtkButton` widget is generally used to trigger a callback function that is
called when the button is pressed.
![An example GtkButton](button.png)
The `GtkButton` widget can hold any valid child widget. That is, it can hold
almost any other standard `GtkWidget`. The most commonly used child is the
`GtkLabel`.
# 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.
When activating a button via the keyboard, the button will temporarily
gain the .keyboard-activating 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 [class@Gtk.ToggleButton], [class@Gtk.MenuButton],
[class@Gtk.VolumeButton], [class@Gtk.LockButton], [class@Gtk.ColorButton]
or [class@Gtk.FontButton] use style classes such as .toggle, .popup, .scale,
.lock, .color on the button node to differentiate themselves from a plain
`GtkButton`.
# Accessibility
`GtkButton` uses the %GTK_ACCESSIBLE_ROLE_BUTTON role.
called when the button is pressed.
![An example GtkButton](button.png)
The `GtkButton` widget can hold any valid child widget. That is, it can hold
almost any other standard `GtkWidget`. The most commonly used child is the
`GtkLabel`.
# 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.
When activating a button via the keyboard, the button will temporarily
gain the .keyboard-activating 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 [class@Gtk.ToggleButton], [class@Gtk.MenuButton],
[class@Gtk.VolumeButton], [class@Gtk.LockButton], [class@Gtk.ColorButton]
or [class@Gtk.FontButton] use style classes such as .toggle, .popup, .scale,
.lock, .color on the button node to differentiate themselves from a plain
`GtkButton`.
# Accessibility
`GtkButton` uses the %GTK_ACCESSIBLE_ROLE_BUTTON role.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
static interface
Nested classes/interfaces inherited from class ch.bailu.gtk.gtk.Widget
Widget.OnDestroy, Widget.OnDestroyNotify, Widget.OnDirectionChanged, Widget.OnHide, Widget.OnKeynavFailed, Widget.OnMap, Widget.OnMnemonicActivate, Widget.OnMoveFocus, Widget.OnQueryTooltip, Widget.OnRealize, Widget.OnShow, Widget.OnStateFlagsChanged, Widget.OnTickCallback, Widget.OnUnmap, Widget.OnUnrealize
Nested classes/interfaces inherited from class ch.bailu.gtk.gobject.Object
Object.OnBindingTransformFunc, Object.OnDuplicateFunc, Object.OnNotify, Object.OnToggleNotify, Object.OnWeakNotify
-
Field Summary
Fields inherited from class ch.bailu.gtk.gtk.Widget
SIGNAL_ON_DESTROY, SIGNAL_ON_DIRECTION_CHANGED, SIGNAL_ON_HIDE, SIGNAL_ON_KEYNAV_FAILED, SIGNAL_ON_MAP, SIGNAL_ON_MNEMONIC_ACTIVATE, SIGNAL_ON_MOVE_FOCUS, SIGNAL_ON_QUERY_TOOLTIP, SIGNAL_ON_REALIZE, SIGNAL_ON_SHOW, SIGNAL_ON_STATE_FLAGS_CHANGED, SIGNAL_ON_UNMAP, SIGNAL_ON_UNREALIZE
Fields inherited from class ch.bailu.gtk.gobject.Object
SIGNAL_ON_NOTIFY
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionImplements interfaceAccessible
.Implements interfaceActionable
.Implements interfaceBuildable
.Implements interfaceConstraintTarget
.getChild()
Gets the child widget of @button.static ClassHandler
boolean
Returns whether the button has a frame.Returns the icon name of the button.static int
getLabel()
Fetches the text from the label of the button.static long
static TypeSystem.TypeSize
static long
static TypeSystem.TypeSize
boolean
gets whether underlines are interpreted as mnemonics.static Button
newFromIconNameButton
(Str icon_name) Creates a new button containing an icon from the current icon theme.static Button
newFromIconNameButton
(String icon_name) Creates a new button containing an icon from the current icon theme.static Button
newWithLabelButton
(Str label) Creates a `GtkButton` widget with a `GtkLabel` child.static Button
newWithLabelButton
(String label) Creates a `GtkButton` widget with a `GtkLabel` child.static Button
newWithMnemonicButton
(Str label) Creates a new `GtkButton` containing a label.static Button
newWithMnemonicButton
(String label) Creates a new `GtkButton` containing a label.onActivate
(Button.OnActivate signal) Connect to signal "activate".onClicked
(Button.OnClicked signal) Connect to signal "clicked".void
Sets the child widget of @button.void
setHasFrame
(boolean has_frame) Sets the style of the button.void
setIconName
(Str icon_name) Adds a `GtkImage` with the given icon name as a child.void
setIconName
(String icon_name) Adds a `GtkImage` with the given icon name as a child.void
Sets the text of the label of the button to @label.void
Sets the text of the label of the button to @label.void
setUseUnderline
(boolean use_underline) Sets whether to use underlines as mnemonics.Methods inherited from class ch.bailu.gtk.gtk.Widget
actionSetEnabled, actionSetEnabled, activate, activateAction, activateAction, activateActionVariant, activateActionVariant, activateDefault, addController, addCssClass, addCssClass, addMnemonicLabel, addTickCallback, allocate, childFocus, computeBounds, computeExpand, computePoint, computeTransform, contains, createPangoContext, createPangoLayout, createPangoLayout, disposeTemplate, dragCheckThreshold, errorBell, getAllocatedBaseline, getAllocatedHeight, getAllocatedWidth, getAllocation, getAncestor, getCanFocus, getCanTarget, getChildVisible, getClipboard, getCssClasses, getCssName, getCursor, getDefaultDirection, getDirection, getDisplay, getFirstChild, getFocusable, getFocusChild, getFocusOnClick, getFontMap, getFontOptions, getFrameClock, getHalign, getHasTooltip, getHeight, getHexpand, getHexpandSet, getLastChild, getLayoutManager, getMapped, getMarginBottom, getMarginEnd, getMarginStart, getMarginTop, getName, getNative, getNextSibling, getOpacity, getOverflow, getPangoContext, getParent, getPreferredSize, getPrevSibling, getPrimaryClipboard, getRealized, getReceivesDefault, getRequestMode, getRoot, getScaleFactor, getSensitive, getSettings, getSize, getSizeRequest, getStateFlags, getStyleContext, getTemplateChild, getTemplateChild, getTooltipMarkup, getTooltipText, getValign, getVexpand, getVexpandSet, getVisible, getWidth, grabFocus, hasCssClass, hasCssClass, hasDefault, hasFocus, hasVisibleFocus, hide, inDestruction, initTemplate, insertActionGroup, insertActionGroup, insertAfter, insertBefore, isAncestor, isDrawable, isFocus, isSensitive, isVisible, keynavFailed, listMnemonicLabels, map, measure, mnemonicActivate, observeChildren, observeControllers, onDestroy, onDirectionChanged, onHide, onKeynavFailed, onMap, onMnemonicActivate, onMoveFocus, onQueryTooltip, onRealize, onShow, onStateFlagsChanged, onUnmap, onUnrealize, pick, queueAllocate, queueDraw, queueResize, realize, removeController, removeCssClass, removeCssClass, removeMnemonicLabel, removeTickCallback, setCanFocus, setCanTarget, setChildVisible, setCssClasses, setCursor, setCursorFromName, setCursorFromName, setDefaultDirection, setDirection, setFocusable, setFocusChild, setFocusOnClick, setFontMap, setFontOptions, setHalign, setHasTooltip, setHexpand, setHexpandSet, setLayoutManager, setMarginBottom, setMarginEnd, setMarginStart, setMarginTop, setName, setName, setOpacity, setOverflow, setParent, setReceivesDefault, setSensitive, setSizeRequest, setStateFlags, setTooltipMarkup, setTooltipMarkup, setTooltipText, setTooltipText, setValign, setVexpand, setVexpandSet, setVisible, shouldLayout, show, sizeAllocate, snapshotChild, triggerTooltipQuery, unmap, unparent, unrealize, unsetStateFlags
Methods inherited from class ch.bailu.gtk.gobject.Object
addToggleRef, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, disconnect, disconnect, dupData, dupData, dupQdata, forceFloating, freezeNotify, get, get, getData, getData, getProperty, getProperty, getQdata, interfaceFindProperty, interfaceInstallProperty, isFloating, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, replaceData, replaceData, replaceQdata, runDispose, set, set, setData, setData, setDataFull, setDataFull, setProperty, setProperty, setQdata, setQdataFull, stealData, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref
Methods inherited from class ch.bailu.gtk.type.Pointer
asCPointer, cast, connectSignal, disconnectSignals, disconnectSignals, equals, hashCode, throwIfNull, throwNullPointerException, toString, unregisterCallbacks, unregisterCallbacks
Methods inherited from class ch.bailu.gtk.type.Type
asCPointer, asCPointer, asCPointerNotNull, asJnaPointer, asJnaPointer, asPointer, asPointer, cast, cast, throwIfNull
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface ch.bailu.gtk.type.PointerInterface
asCPointerNotNull, asJnaPointer, asPointer, isNotNull, isNull
-
Field Details
-
SIGNAL_ON_ACTIVATE
- See Also:
-
SIGNAL_ON_CLICKED
- See Also:
-
-
Constructor Details
-
Button
-
Button
public Button()Creates a new `GtkButton` widget.
To add a child widget to the button, use [method@Gtk.Button.set_child].
-
-
Method Details
-
getClassHandler
-
newFromIconNameButton
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.- Parameters:
icon_name
- an icon name- Returns:
- a new `GtkButton` displaying the themed icon
-
newFromIconNameButton
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.- Parameters:
icon_name
- an icon name- Returns:
- a new `GtkButton` displaying the themed icon
-
newWithLabelButton
Creates a `GtkButton` widget with a `GtkLabel` child.- Parameters:
label
- The text you want the `GtkLabel` to hold- Returns:
- The newly created `GtkButton` widget
-
newWithLabelButton
Creates a `GtkButton` widget with a `GtkLabel` child.- Parameters:
label
- The text you want the `GtkLabel` to hold- Returns:
- The newly created `GtkButton` widget
-
newWithMnemonicButton
Creates a new `GtkButton` 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.- Parameters:
label
- The text of the button, with an underscore in front of the mnemonic character- Returns:
- a new `GtkButton`
-
newWithMnemonicButton
Creates a new `GtkButton` 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.- Parameters:
label
- The text of the button, with an underscore in front of the mnemonic character- Returns:
- a new `GtkButton`
-
getChild
Gets the child widget of @button.- Returns:
- the child widget of @button
-
getHasFrame
public boolean getHasFrame()Returns whether the button has a frame.- Returns:
- %TRUE if the button has a frame
-
getIconName
Returns the icon name of the button.
If the icon name has not been set with [method@Gtk.Button.set_icon_name]
the return value will be %NULL. This will be the case if you create
an empty button with [ctor@Gtk.Button.new] to use as a container.- Returns:
- The icon name set via [method@Gtk.Button.set_icon_name]
-
getLabel
Fetches the text from the label of the button.
If the label text has not been set with [method@Gtk.Button.set_label]
the return value will be %NULL. This will be the case if you create
an empty button with [ctor@Gtk.Button.new] to use as a container.- Returns:
- The text of the label widget. This string is owned by the widget and must not be modified or freed.
-
getUseUnderline
public boolean getUseUnderline()gets whether underlines are interpreted as mnemonics.
See [method@Gtk.Button.set_use_underline].- Returns:
- %TRUE if an embedded underline in the button label indicates the mnemonic accelerator keys.
-
setChild
Sets the child widget of @button.
Note that by using this API, you take full responsibility for setting
up the proper accessibility label and description information for @button.
Most likely, you'll either set the accessibility label or description
for @button explicitly, or you'll set a labelled-by or described-by
relations from @child to @button.- Parameters:
child
- the child widget
-
setHasFrame
public void setHasFrame(boolean has_frame) Sets the style of the button.
Buttons can has a flat appearance or have a frame drawn around them.- Parameters:
has_frame
- whether the button should have a visible frame
-
setIconName
Adds a `GtkImage` with the given icon name as a child.
If @button already contains a child widget, that child widget will
be removed and replaced with the image.- Parameters:
icon_name
- An icon name
-
setIconName
Adds a `GtkImage` with the given icon name as a child.
If @button already contains a child widget, that child widget will
be removed and replaced with the image.- Parameters:
icon_name
- An icon name
-
setLabel
Sets the text of the label of the button to @label.
This will also clear any previously set labels.- Parameters:
label
- a string
-
setLabel
Sets the text of the label of the button to @label.
This will also clear any previously set labels.- Parameters:
label
- a string
-
setUseUnderline
public void setUseUnderline(boolean use_underline) Sets whether to use underlines as mnemonics.
If true, an underline in the text of the button label indicates
the next character should be used for the mnemonic accelerator key.- Parameters:
use_underline
- %TRUE if underlines in the text indicate mnemonics
-
onActivate
Connect to signal "activate".
SeeButton.OnActivate.onActivate()
for signal description.
FieldSIGNAL_ON_ACTIVATE
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
onClicked
Connect to signal "clicked".
SeeButton.OnClicked.onClicked()
for signal description.
FieldSIGNAL_ON_CLICKED
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
asAccessible
Implements interfaceAccessible
. Call this to get access to interface functions.- Overrides:
asAccessible
in classWidget
- Returns:
Accessible
-
asActionable
Implements interfaceActionable
. Call this to get access to interface functions.- Returns:
Actionable
-
asBuildable
Implements interfaceBuildable
. Call this to get access to interface functions.- Overrides:
asBuildable
in classWidget
- Returns:
Buildable
-
asConstraintTarget
Implements interfaceConstraintTarget
. Call this to get access to interface functions.- Overrides:
asConstraintTarget
in classWidget
- Returns:
ConstraintTarget
-
getTypeID
public static long getTypeID() -
getParentTypeID
public static long getParentTypeID() -
getTypeSize
-
getParentTypeSize
-
getInstanceSize
public static int getInstanceSize()
-