Class Widget
- All Implemented Interfaces:
Proxy
,Accessible
,Buildable
,ConstraintTarget
- Direct Known Subclasses:
Actionable.ActionableImpl
,ActionBar
,AppChooser.AppChooserImpl
,AppChooserButton
,AppChooserWidget
,AspectFrame
,Avatar
,Banner
,Bin
,BottomSheet
,Box
,BreakpointBin
,Button
,ButtonContent
,Calendar
,Carousel
,CarouselIndicatorDots
,CarouselIndicatorLines
,CellEditable.CellEditableImpl
,CellView
,CenterBox
,CheckButton
,Clamp
,ClampScrollable
,ColorButton
,ColorChooserWidget
,ColorDialogButton
,ColumnView
,ComboBox
,CompletionCell
,Dialog
,DragIcon
,DrawingArea
,DropDown
,Editable.EditableImpl
,EditableLabel
,Entry
,Expander
,FileChooserWidget
,Fixed
,Flap
,FlowBox
,FlowBoxChild
,FontButton
,FontChooserWidget
,FontDialogButton
,Frame
,GLArea
,GraphicsOffload
,Grid
,Gutter
,GutterRenderer
,HeaderBar
,HeaderBar
,HoverDisplay
,IconView
,Image
,InfoBar
,InlineViewSwitcher
,Inscription
,Label
,LayoutSlot
,Leaflet
,LevelBar
,ListBase
,ListBox
,ListBoxRow
,MediaControls
,MenuButton
,MultiLayoutView
,Native.NativeImpl
,NavigationPage
,NavigationSplitView
,NavigationView
,Notebook
,Overlay
,OverlaySplitView
,Paned
,PasswordEntry
,Picture
,Popover
,PopoverMenuBar
,PreferencesGroup
,PreferencesPage
,ProgressBar
,Range
,Revealer
,Root.RootImpl
,ScaleButton
,Scrollbar
,ScrolledWindow
,SearchBar
,SearchEntry
,Separator
,ShortcutLabel
,ShortcutsShortcut
,SpinButton
,Spinner
,Spinner
,SplitButton
,Squeezer
,Stack
,StackSidebar
,StackSwitcher
,Statusbar
,StatusPage
,StyleSchemeChooserWidget
,StyleSchemePreview
,Swipeable.SwipeableImpl
,Switch
,TabBar
,TabButton
,TabOverview
,TabView
,Text
,TextView
,ToastOverlay
,ToggleGroup
,ToolbarView
,TreeExpander
,TreeView
,Video
,Viewport
,ViewStack
,ViewSwitcher
,ViewSwitcherBar
,ViewSwitcherTitle
,WebViewBase
,Widget.WidgetImpl
,Window
,WindowControls
,WindowHandle
,WindowTitle
,WrapBox
It manages the widget lifecycle, layout, states and style.
Height-for-width Geometry Management
GTK uses a height-for-width (and width-for-height) geometry management
system. Height-for-width means that a widget can change how much
vertical space it needs, depending on the amount of horizontal space
that it is given (and similar for width-for-height). The most common
example is a label that reflows to fill up the available width, wraps
to fewer lines, and therefore needs less height.
Height-for-width geometry management is implemented in GTK by way of two virtual methods:
getRequestMode()
measure(org.gnome.gtk.Orientation, int, io.github.jwharm.javagi.base.Out<java.lang.Integer>, io.github.jwharm.javagi.base.Out<java.lang.Integer>, io.github.jwharm.javagi.base.Out<java.lang.Integer>, io.github.jwharm.javagi.base.Out<java.lang.Integer>)
There are some important things to keep in mind when implementing height-for-width and when using it in widget implementations.
If you implement a direct GtkWidget
subclass that supports
height-for-width or width-for-height geometry management for itself
or its child widgets, the getRequestMode()
virtual
function must be implemented as well and return the widget's preferred
request mode. The default implementation of this virtual function
returns SizeRequestMode.CONSTANT_SIZE
, which means that the widget will
only ever get -1 passed as the for_size value to its
measure(org.gnome.gtk.Orientation, int, io.github.jwharm.javagi.base.Out<java.lang.Integer>, io.github.jwharm.javagi.base.Out<java.lang.Integer>, io.github.jwharm.javagi.base.Out<java.lang.Integer>, io.github.jwharm.javagi.base.Out<java.lang.Integer>)
implementation.
The geometry management system will query a widget hierarchy in
only one orientation at a time. When widgets are initially queried
for their minimum sizes it is generally done in two initial passes
in the Gtk.SizeRequestMode
chosen by the toplevel.
For example, when queried in the normal SizeRequestMode.HEIGHT_FOR_WIDTH
mode:
First, the default minimum and natural width for each widget
in the interface will be computed using measure(org.gnome.gtk.Orientation, int, io.github.jwharm.javagi.base.Out<java.lang.Integer>, io.github.jwharm.javagi.base.Out<java.lang.Integer>, io.github.jwharm.javagi.base.Out<java.lang.Integer>, io.github.jwharm.javagi.base.Out<java.lang.Integer>)
with an
orientation of Orientation.HORIZONTAL
and a for_size of -1.
Because the preferred widths for each widget depend on the preferred
widths of their children, this information propagates up the hierarchy,
and finally a minimum and natural width is determined for the entire
toplevel. Next, the toplevel will use the minimum width to query for the
minimum height contextual to that width using measure(org.gnome.gtk.Orientation, int, io.github.jwharm.javagi.base.Out<java.lang.Integer>, io.github.jwharm.javagi.base.Out<java.lang.Integer>, io.github.jwharm.javagi.base.Out<java.lang.Integer>, io.github.jwharm.javagi.base.Out<java.lang.Integer>)
with an
orientation of Orientation.VERTICAL
and a for_size of the just computed
width. This will also be a highly recursive operation. The minimum height
for the minimum width is normally used to set the minimum size constraint
on the toplevel.
After the toplevel window has initially requested its size in both
dimensions it can go on to allocate itself a reasonable size (or a size
previously specified with Window.setDefaultSize(int, int)
). During the
recursive allocation process it’s important to note that request cycles
will be recursively executed while widgets allocate their children.
Each widget, once allocated a size, will go on to first share the
space in one orientation among its children and then request each child's
height for its target allocated width or its width for allocated height,
depending. In this way a widget will typically be requested its size
a number of times before actually being allocated a size. The size a
widget is finally allocated can of course differ from the size it has
requested. For this reason, GtkWidget
caches a small number of results
to avoid re-querying for the same sizes in one allocation cycle.
If a widget does move content around to intelligently use up the
allocated size then it must support the request in both
GtkSizeRequestMode
s even if the widget in question only
trades sizes in a single orientation.
For instance, a Label
that does height-for-width word wrapping
will not expect to have measure(org.gnome.gtk.Orientation, int, io.github.jwharm.javagi.base.Out<java.lang.Integer>, io.github.jwharm.javagi.base.Out<java.lang.Integer>, io.github.jwharm.javagi.base.Out<java.lang.Integer>, io.github.jwharm.javagi.base.Out<java.lang.Integer>)
with an orientation of
Orientation.VERTICAL
called because that call is specific to a
width-for-height request. In this case the label must return the height
required for its own minimum possible width. By following this rule any
widget that handles height-for-width or width-for-height requests will
always be allocated at least enough space to fit its own content.
Here are some examples of how a SizeRequestMode.HEIGHT_FOR_WIDTH
widget
generally deals with width-for-height requests:
static void
foo_widget_measure (GtkWidget *widget,
GtkOrientation orientation,
int for_size,
int *minimum_size,
int *natural_size,
int *minimum_baseline,
int *natural_baseline)
{
if (orientation == GTK_ORIENTATION_HORIZONTAL)
{
// Calculate minimum and natural width
}
else // VERTICAL
{
if (i_am_in_height_for_width_mode)
{
int min_width, dummy;
// First, get the minimum width of our widget
GTK_WIDGET_GET_CLASS (widget)->measure (widget, GTK_ORIENTATION_HORIZONTAL, -1,
&min_width, &dummy, &dummy, &dummy);
// Now use the minimum width to retrieve the minimum and natural height to display
// that width.
GTK_WIDGET_GET_CLASS (widget)->measure (widget, GTK_ORIENTATION_VERTICAL, min_width,
minimum_size, natural_size, &dummy, &dummy);
}
else
{
// ... some widgets do both.
}
}
}
Often a widget needs to get its own request during size request or allocation. For example, when computing height it may need to also compute width. Or when deciding how to use an allocation, the widget may need to know its natural size. In these cases, the widget should be careful to call its virtual methods directly, like in the code example above.
It will not work to use the wrapper function measure(org.gnome.gtk.Orientation, int, io.github.jwharm.javagi.base.Out<java.lang.Integer>, io.github.jwharm.javagi.base.Out<java.lang.Integer>, io.github.jwharm.javagi.base.Out<java.lang.Integer>, io.github.jwharm.javagi.base.Out<java.lang.Integer>)
inside your own sizeAllocate(org.gnome.gtk.Allocation, int)
implementation.
These return a request adjusted by SizeGroup
, the widget's
align and expand flags, as well as its CSS style.
If a widget used the wrappers inside its virtual method implementations, then the adjustments (such as widget margins) would be applied twice. GTK therefore does not allow this and will warn if you try to do it.
Of course if you are getting the size request for another widget, such
as a child widget, you must use measure(org.gnome.gtk.Orientation, int, io.github.jwharm.javagi.base.Out<java.lang.Integer>, io.github.jwharm.javagi.base.Out<java.lang.Integer>, io.github.jwharm.javagi.base.Out<java.lang.Integer>, io.github.jwharm.javagi.base.Out<java.lang.Integer>)
; otherwise, you
would not properly consider widget margins, SizeGroup
, and
so forth.
GTK also supports baseline vertical alignment of widgets. This means that widgets are positioned such that the typographical baseline of widgets in the same row are aligned. This happens if a widget supports baselines, has a vertical alignment using baselines, and is inside a widget that supports baselines and has a natural “row” that it aligns to the baseline, or a baseline assigned to it by the grandparent.
Baseline alignment support for a widget is also done by the
measure(org.gnome.gtk.Orientation, int, io.github.jwharm.javagi.base.Out<java.lang.Integer>, io.github.jwharm.javagi.base.Out<java.lang.Integer>, io.github.jwharm.javagi.base.Out<java.lang.Integer>, io.github.jwharm.javagi.base.Out<java.lang.Integer>)
virtual function. It allows you to report
both a minimum and natural size.
If a widget ends up baseline aligned it will be allocated all the space in
the parent as if it was Align.FILL
, but the selected baseline can be
found via getBaseline()
. If the baseline has a
value other than -1 you need to align the widget such that the baseline
appears at the position.
GtkWidget as GtkBuildable
The GtkWidget
implementation of the GtkBuildable
interface
supports various custom elements to specify additional aspects of widgets
that are not directly expressed as properties.
If the widget uses a LayoutManager
, GtkWidget
supports
a custom <layout>
element, used to define layout properties:
<object class="GtkGrid" id="my_grid">
<child>
<object class="GtkLabel" id="label1">
<property name="label">Description</property>
<layout>
<property name="column">0</property>
<property name="row">0</property>
<property name="row-span">1</property>
<property name="column-span">1</property>
</layout>
</object>
</child>
<child>
<object class="GtkEntry" id="description_entry">
<layout>
<property name="column">1</property>
<property name="row">0</property>
<property name="row-span">1</property>
<property name="column-span">1</property>
</layout>
</object>
</child>
</object>
GtkWidget
allows style information such as style classes to
be associated with widgets, using the custom <style>
element:
<object class="GtkButton" id="button1">
<style>
<class name="my-special-button-class"/>
<class name="dark-button"/>
</style>
</object>
GtkWidget
allows defining accessibility information, such as properties,
relations, and states, using the custom <accessibility>
element:
<object class="GtkButton" id="button1">
<accessibility>
<property name="label">Download</property>
<relation name="labelled-by">label1</relation>
</accessibility>
</object>
Building composite widgets from template XML
GtkWidget
exposes some facilities to automate the procedure
of creating composite widgets using "templates".
To create composite widgets with GtkBuilder
XML, one must associate
the interface description with the widget class at class initialization
time using WidgetClass#setTemplate
.
The interface description semantics expected in composite template descriptions
is slightly different from regular GtkBuilder
XML.
Unlike regular interface descriptions, WidgetClass#setTemplate
will expect a <template>
tag as a direct child of the toplevel
<interface>
tag. The <template>
tag must specify the “class” attribute
which must be the type name of the widget. Optionally, the “parent”
attribute may be specified to specify the direct parent type of the widget
type; this is ignored by GtkBuilder
but can be used by UI design tools to
introspect what kind of properties and internal children exist for a given
type when the actual type does not exist.
The XML which is contained inside the <template>
tag behaves as if it were
added to the <object>
tag defining the widget itself. You may set properties
on a widget by inserting <property>
tags into the <template>
tag, and also
add <child>
tags to add children and extend a widget in the normal way you
would with <object>
tags.
Additionally, <object>
tags can also be added before and after the initial
<template>
tag in the normal way, allowing one to define auxiliary objects
which might be referenced by other widgets declared as children of the
<template>
tag.
Since, unlike the <object>
tag, the <template>
tag does not contain an
“id” attribute, if you need to refer to the instance of the object itself that
the template will create, simply refer to the template class name in an
applicable element content.
Here is an example of a template definition, which includes an example of
this in the <signal>
tag:
<interface>
<template class="FooWidget" parent="GtkBox">
<property name="orientation">horizontal</property>
<property name="spacing">4</property>
<child>
<object class="GtkButton" id="hello_button">
<property name="label">Hello World</property>
<signal name="clicked" handler="hello_button_clicked" object="FooWidget" swapped="yes"/>
</object>
</child>
<child>
<object class="GtkButton" id="goodbye_button">
<property name="label">Goodbye World</property>
</object>
</child>
</template>
</interface>
Typically, you'll place the template fragment into a file that is
bundled with your project, using GResource
. In order to load the
template, you need to call WidgetClass#setTemplateFromResource
from the class initialization of your GtkWidget
type:
static void
foo_widget_class_init (FooWidgetClass *klass)
{
// ...
gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass),
"/com/example/ui/foowidget.ui");
}
You will also need to call initTemplate()
from the
instance initialization function:
static void
foo_widget_init (FooWidget *self)
{
gtk_widget_init_template (GTK_WIDGET (self));
// Initialize the rest of the widget...
}
as well as calling disposeTemplate(org.gnome.glib.Type)
from the dispose
function:
static void
foo_widget_dispose (GObject *gobject)
{
FooWidget *self = FOO_WIDGET (gobject);
// Dispose objects for which you have a reference...
// Clear the template children for this widget type
gtk_widget_dispose_template (GTK_WIDGET (self), FOO_TYPE_WIDGET);
G_OBJECT_CLASS (foo_widget_parent_class)->dispose (gobject);
}
You can access widgets defined in the template using the
getTemplateChild(org.gnome.glib.Type, java.lang.String)
function, but you will typically declare
a pointer in the instance private data structure of your type using the same
name as the widget in the template definition, and call
WidgetClass#bindTemplateChildFull
(or one of its wrapper macros
Gtk#widgetClassBindTemplateChild
and Gtk#widgetClassBindTemplateChildPrivate
)
with that name, e.g.
typedef struct {
GtkWidget *hello_button;
GtkWidget *goodbye_button;
} FooWidgetPrivate;
G_DEFINE_TYPE_WITH_PRIVATE (FooWidget, foo_widget, GTK_TYPE_BOX)
static void
foo_widget_dispose (GObject *gobject)
{
gtk_widget_dispose_template (GTK_WIDGET (gobject), FOO_TYPE_WIDGET);
G_OBJECT_CLASS (foo_widget_parent_class)->dispose (gobject);
}
static void
foo_widget_class_init (FooWidgetClass *klass)
{
// ...
G_OBJECT_CLASS (klass)->dispose = foo_widget_dispose;
gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass),
"/com/example/ui/foowidget.ui");
gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass),
FooWidget, hello_button);
gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass),
FooWidget, goodbye_button);
}
static void
foo_widget_init (FooWidget *widget)
{
gtk_widget_init_template (GTK_WIDGET (widget));
}
You can also use WidgetClass#bindTemplateCallbackFull
(or
is wrapper macro Gtk#widgetClassBindTemplateCallback
) to connect
a signal callback defined in the template with a function visible in the
scope of the class, e.g.
// the signal handler has the instance and user data swapped
// because of the swapped="yes" attribute in the template XML
static void
hello_button_clicked (FooWidget *self,
GtkButton *button)
{
g_print ("Hello, world!\\n");
}
static void
foo_widget_class_init (FooWidgetClass *klass)
{
// ...
gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass),
"/com/example/ui/foowidget.ui");
gtk_widget_class_bind_template_callback (GTK_WIDGET_CLASS (klass), hello_button_clicked);
}
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Widget.Builder<B extends Widget.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.static interface
Functional interface declaration of theDestroyCallback
callback.static interface
Functional interface declaration of theDirectionChangedCallback
callback.static interface
Functional interface declaration of theHideCallback
callback.static interface
Functional interface declaration of theKeynavFailedCallback
callback.static interface
Functional interface declaration of theMapCallback
callback.static interface
Functional interface declaration of theMnemonicActivateCallback
callback.static interface
Functional interface declaration of theMoveFocusCallback
callback.static interface
Functional interface declaration of theQueryTooltipCallback
callback.static interface
Functional interface declaration of theRealizeCallback
callback.static interface
Functional interface declaration of theShowCallback
callback.static interface
Functional interface declaration of theStateFlagsChangedCallback
callback.static interface
Functional interface declaration of theUnmapCallback
callback.static interface
Functional interface declaration of theUnrealizeCallback
callback.static class
static class
The WidgetImpl type represents a native instance of the abstract Widget class.Nested classes/interfaces inherited from class org.gnome.gobject.InitiallyUnowned
InitiallyUnowned.InitiallyUnownedClass
Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
Nested classes/interfaces inherited from interface org.gnome.gtk.Accessible
Accessible.AccessibleImpl, Accessible.AccessibleInterface
Nested classes/interfaces inherited from interface org.gnome.gtk.Buildable
Buildable.BuildableIface, Buildable.BuildableImpl
Nested classes/interfaces inherited from interface org.gnome.gtk.ConstraintTarget
ConstraintTarget.ConstraintTargetImpl, ConstraintTarget.ConstraintTargetInterface
-
Field Summary
Fields inherited from class io.github.jwharm.javagi.base.ProxyInstance
address
-
Constructor Summary
ConstructorsConstructorDescriptionWidget()
Creates a new Widget.Widget
(MemorySegment address) Create a Widget proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionvoid
actionSetEnabled
(String actionName, boolean enabled) Enables or disables an action installed withWidgetClass#installAction
.boolean
activateActionIfExists
(String name, @Nullable Variant args) Activates an action for the widget.void
Activates thedefault.activate
action for the widget.boolean
Activates the widget.void
addController
(EventController controller) Adds an event controller to the widget.void
addCssClass
(String cssClass) Adds a style class to the widget.void
addMnemonicLabel
(Widget label) Adds a widget to the list of mnemonic labels for this widget.int
addTickCallback
(TickCallback callback) Queues an animation frame update and adds a callback to be called before each frame.void
Assigns size, position, (optionally) a baseline and transform to a child widget.protected Widget
asParent()
Returns this instance as if it were its parent type.boolean
childFocus
(DirectionType direction) Called by widgets as the user moves around the window using keyboard shortcuts.boolean
computeBounds
(Widget target, Rect outBounds) Computes the bounds for this Widget in the coordinate space oftarget
.protected void
computeExpand
(MemorySegment hexpandP, MemorySegment vexpandP) Computes whether a container should give this widget extra space when possible.boolean
computeExpand
(Orientation orientation) Computes whether a parent widget should give this widget extra space when possible.boolean
computePoint
(Widget target, Point point, Point outPoint) Translates the givenpoint
in this Widget's coordinates to coordinates intarget
’s coordinate system.boolean
computeTransform
(Widget target, Matrix outTransform) Computes a matrix suitable to describe a transformation from this Widget's coordinate system intotarget
's coordinate system.boolean
contains
(double x, double y) Tests if a given point is contained in the widget.Creates a newPangoContext
that is configured for the widget.createPangoLayout
(@Nullable String text) Creates a newPangoLayout
that is configured for the widget.protected void
cssChanged
(CssStyleChange change) Vfunc called when the CSS used by widget was changed.protected void
directionChanged
(TextDirection previousDirection) Signal emitted when the text direction of a widget changes.void
disposeTemplate
(Type widgetType) Clears the template children for the widget.boolean
dragCheckThreshold
(int startX, int startY, int currentX, int currentY) Checks to see if a drag movement has passed the GTK drag threshold.void
Emits the "destroy" signal.void
emitDirectionChanged
(TextDirection previousDirection) Emits the "direction-changed" signal.void
emitHide()
Emits the "hide" signal.boolean
emitKeynavFailed
(DirectionType direction) Emits the "keynav-failed" signal.void
emitMap()
Emits the "map" signal.boolean
emitMnemonicActivate
(boolean groupCycling) Emits the "mnemonic-activate" signal.void
emitMoveFocus
(DirectionType direction) Emits the "move-focus" signal.boolean
emitQueryTooltip
(int x, int y, boolean keyboardMode, Tooltip tooltip) Emits the "query-tooltip" signal.void
Emits the "realize" signal.void
emitShow()
Emits the "show" signal.void
emitStateFlagsChanged
(Set<StateFlags> flags) Emits the "state-flags-changed" signal.void
Emits the "unmap" signal.void
Emits the "unrealize" signal.void
Notifies the user about an input-related error on the widget.protected boolean
focus
(DirectionType direction) Vfunc for gtk_widget_child_focus()int
Deprecated.int
Deprecated.UsegetHeight()
insteadint
Deprecated.UsegetWidth()
insteadvoid
getAllocation
(Allocation allocation) Deprecated.getAncestor
(Type widgetType) Gets the first ancestor of the widget with typewidgetType
.int
Returns the baseline that has currently been allocated to the widget.boolean
Determines whether the input focus can enter the widget or any of its children.boolean
Queries whether the widget can be the target of pointer events.boolean
Gets the value set withsetChildVisible(boolean)
.Gets the clipboard object for the widget.void
Gets the current foreground color for the widget’s style.String[]
Returns the list of style classes applied to the widget.Returns the CSS name of the widget.Gets the cursor set on the widget.static TextDirection
Obtains the default reading direction.Gets the reading direction for the widget.Get the display for the window that the widget belongs to.Returns the widget’s first child.boolean
Determines whether the widget can own the input focus.Returns the focus child of the widget.boolean
Returns whether the widget should grab focus when it is clicked with the mouse.Gets the font map of the widget.org.freedesktop.cairo.FontOptions
Deprecated.Obtains the frame clock for a widget.Gets the horizontal alignment of the widget.boolean
Returns the current value of thehas-tooltip
property.int
Returns the content height of the widget.boolean
Gets whether the widget would like any available extra horizontal space.boolean
Gets whether thehexpand
flag has been explicitly set.Returns the widget’s last child.Retrieves the layout manager of the widget.boolean
Gets the value of theGtk.Widget:limit-events
property.boolean
Returns whether the widget is mapped.int
Gets the bottom margin of the widget.int
Gets the end margin of the widget.int
Gets the start margin of the widget.int
Gets the top margin of the widget.static MemoryLayout
The memory layout of the native struct.getName()
Retrieves the name of a widget.Returns the nearestGtkNative
ancestor of the widget.Returns the widget’s next sibling.double
Fetches the requested opacity for the widget.Returns the widget’s overflow value.Gets aPangoContext
that is configured for the widget.Returns the parent widget of the widget.void
getPreferredSize
(@Nullable Requisition minimumSize, @Nullable Requisition naturalSize) Retrieves the minimum and natural size of a widget, taking into account the widget’s preference for height-for-width management.Returns the widget’s previous sibling.Gets the primary clipboard of the widget.boolean
Determines whether the widget is realized.boolean
Determines whether the widget is always treated as the default widget within its toplevel when it has the focus, even if another widget is the default.Gets whether the widget prefers a height-for-width layout or a width-for-height layout.getRoot()
Returns theGtkRoot
widget of the widget.int
Retrieves the internal scale factor that maps from window coordinates to the actual device pixels.boolean
Returns the widget’s sensitivity.Gets the settings object holding the settings used for the widget.int
getSize
(Orientation orientation) Returns the content width or height of the widget.void
getSizeRequest
(@Nullable Out<Integer> width, @Nullable Out<Integer> height) Gets the size request that was explicitly set for the widget.Returns the widget state as a flag set.Deprecated.Style contexts will be removed in GTK 5getTemplateChild
(Type widgetType, String name) Fetches an object build from the template XML forwidgetType
in the widget.Gets the contents of the tooltip for the widget.Gets the contents of the tooltip for the widget.static Type
getType()
Get the GType of the Widget classGets the vertical alignment of the widget.boolean
Gets whether the widget would like any available extra vertical space.boolean
Gets whether thevexpand
flag has been explicitly set.boolean
Determines whether the widget is visible.int
getWidth()
Returns the content width of the widget.boolean
Causes this Widget to have the keyboard focus for the window that it belongs to.boolean
hasCssClass
(String cssClass) Returns whether a style class is currently applied to the widget.boolean
Determines whether the widget is the current default widget within its toplevel.boolean
hasFocus()
Determines if the widget has the global input focus.boolean
Determines if the widget should show a visible indication that it has the global input focus.void
hide()
Deprecated.UsesetVisible(boolean)
insteadboolean
Returns whether the widget is currently being destroyed.void
Creates and initializes child widgets defined in templates.void
insertActionGroup
(String name, @Nullable ActionGroup group) Inserts an action group into the widget's actions.void
insertAfter
(Widget parent, @Nullable Widget previousSibling) Sets the parent widget of the widget.void
insertBefore
(Widget parent, @Nullable Widget nextSibling) Sets the parent widget of the widget.boolean
isAncestor
(Widget ancestor) Determines whether the widget is a descendent ofancestor
.boolean
Determines whether the widget can be drawn to.boolean
isFocus()
Determines if the widget is the focus widget within its toplevel.boolean
Returns the widget’s effective sensitivity.boolean
Determines whether the widget and all its parents are marked as visible.boolean
keynavFailed
(DirectionType direction) Emits theGtk.Widget::keynav-failed
signal on the widget.Returns the widgets for which this widget is the target of a mnemonic.void
map()
Causes a widget to be mapped if it isn’t already.void
measure
(Orientation orientation, int forSize, @Nullable Out<Integer> minimum, @Nullable Out<Integer> natural, @Nullable Out<Integer> minimumBaseline, @Nullable Out<Integer> naturalBaseline) Measures this Widget in the orientationorientation
and for the givenforSize
.boolean
mnemonicActivate
(boolean groupCycling) Emits theGtk.Widget::mnemonic-activate
signal.protected void
moveFocus
(DirectionType direction) Signal emitted when a change of focus is requestedReturns a list model to track the children of the widget.Returns a list model to track the event controllers of the widget.onDestroy
(Widget.DestroyCallback handler) Signals that all holders of a reference to the widget should release the reference that they hold.Emitted when the text direction of a widget changes.onHide
(Widget.HideCallback handler) Emitted whenwidget
is hidden.Emitted if keyboard navigation fails.onMap
(Widget.MapCallback handler) Emitted whenwidget
is going to be mapped.Emitted when a widget is activated via a mnemonic.onMoveFocus
(Widget.MoveFocusCallback handler) Emitted when the focus is moved.Emitted when the widget’s tooltip is about to be shown.onRealize
(Widget.RealizeCallback handler) Emitted whenwidget
is associated with aGdkSurface
.onShow
(Widget.ShowCallback handler) Emitted whenwidget
is shown.Emitted when the widget state changes.onUnmap
(Widget.UnmapCallback handler) Emitted whenwidget
is going to be unmapped.onUnrealize
(Widget.UnrealizeCallback handler) Emitted when theGdkSurface
associated withwidget
is destroyed.Finds the descendant of the widget closest to a point.Finds the descendant of the widget closest to a point.protected boolean
queryTooltip
(int x, int y, boolean keyboardTooltip, Tooltip tooltip) Signal emitted when “has-tooltip” istrue
and the hover timeout has expired with the cursor hovering “above” widget; or emitted when widget got focus in keyboard mode.void
Flags the widget for a rerun of thesizeAllocate(org.gnome.gtk.Allocation, int)
function.void
Schedules this widget to be redrawn.void
Flags a widget to have its size renegotiated.void
realize()
Creates the GDK resources associated with a widget.void
removeController
(EventController controller) Removes an event controller from the widget.void
removeCssClass
(String cssClass) Removes a style from the widget.void
removeMnemonicLabel
(Widget label) Removes a widget from the list of mnemonic labels for this widget.void
removeTickCallback
(int id) Removes a tick callback previously registered withaddTickCallback(org.gnome.gtk.TickCallback)
.protected void
root()
Called when the widget gets added to aGtkRoot
widget.void
setCanFocus
(boolean canFocus) Sets whether the input focus can enter the widget or any of its children.void
setCanTarget
(boolean canTarget) Sets whether the widget can be the target of pointer events.void
setChildVisible
(boolean childVisible) Sets whether the widget should be mapped along with its parent.void
setCssClasses
(String[] classes) Replaces the current style classes of the widget withclasses
.void
Sets the cursor to be shown when the pointer hovers over the widget.void
setCursorFromName
(@Nullable String name) Sets the cursor to be shown when the pointer hovers over the widget.static void
Sets the default reading direction for widgets.void
Sets the reading direction on the widget.void
setFocusable
(boolean focusable) Sets whether the widget can own the input focus.void
setFocusChild
(@Nullable Widget child) Set the focus child of the widget.void
setFocusOnClick
(boolean focusOnClick) Sets whether the widget should grab focus when it is clicked with the mouse.void
setFontMap
(@Nullable FontMap fontMap) Sets the font map to use for text rendering in the widget.void
setFontOptions
(@Nullable org.freedesktop.cairo.FontOptions options) Deprecated.void
Sets the horizontal alignment of the widget.void
setHasTooltip
(boolean hasTooltip) Sets thehas-tooltip
property on the widget.void
setHexpand
(boolean expand) Sets whether the widget would like any available extra horizontal space.void
setHexpandSet
(boolean set) Sets whether the hexpand flag will be used.void
setLayoutManager
(@Nullable LayoutManager layoutManager) Sets the layout manager to use for measuring and allocating children of the widget.void
setLimitEvents
(boolean limitEvents) Sets whether the widget acts like a modal dialog, with respect to event delivery.void
setMarginBottom
(int margin) Sets the bottom margin of the widget.void
setMarginEnd
(int margin) Sets the end margin of the widget.void
setMarginStart
(int margin) Sets the start margin of the widget.void
setMarginTop
(int margin) Sets the top margin of the widget.void
Sets a widgets name.void
setOpacity
(double opacity) Requests the widget to be rendered partially transparent.void
setOverflow
(Overflow overflow) Sets how the widget treats content that is drawn outside the it's content area.void
Sets the parent widget of the widget.void
setReceivesDefault
(boolean receivesDefault) Sets whether the widget will be treated as the default widget within its toplevel when it has the focus, even if another widget is the default.void
setSensitive
(boolean sensitive) Sets the sensitivity of the widget.void
setSizeRequest
(int width, int height) Sets the minimum size of the widget.void
setStateFlags
(Set<StateFlags> flags, boolean clear) Turns on flag values in the current widget state.void
setStateFlags
(StateFlags flags, boolean clear) Turns on flag values in the current widget state.void
setTooltipMarkup
(@Nullable String markup) Sets the contents of the tooltip for widget.void
setTooltipText
(@Nullable String text) Sets the contents of the tooltip for the widget.void
Sets the vertical alignment of the widget.void
setVexpand
(boolean expand) Sets whether the widget would like any available extra vertical space.void
setVexpandSet
(boolean set) Sets whether the vexpand flag will be used.void
setVisible
(boolean visible) Sets the visibility state of this Widget.boolean
Returns whether the widget should contribute to the measuring and allocation of its parent.void
show()
Deprecated.UsesetVisible(boolean)
insteadprotected void
sizeAllocate
(int width, int height, int baseline) Called to set the allocation, if the widget does not have a layout manager.void
sizeAllocate
(Allocation allocation, int baseline) Allocates widget with a transformation that translates the origin to the position inallocation
.protected void
Vfunc called when a new snapshot of the widget has to be taken.void
snapshotChild
(Widget child, Snapshot snapshot) Snapshots a child of the widget.protected void
stateFlagsChanged
(Set<StateFlags> previousStateFlags) Signal emitted when the widget state changes, see gtk_widget_get_state_flags().protected void
systemSettingChanged
(SystemSetting settings) Emitted when a system setting was changed.boolean
translateCoordinates
(Widget destWidget, double srcX, double srcY, @Nullable Out<Double> destX, @Nullable Out<Double> destY) Deprecated.void
Triggers a tooltip query on the display of the widget.void
unmap()
Causes a widget to be unmapped if it’s currently mapped.void
unparent()
Removes this Widget from its parent.void
Causes a widget to be unrealized.protected void
unroot()
Called when the widget is about to be removed from itsGtkRoot
widget.void
unsetStateFlags
(Set<StateFlags> flags) Turns off flag values for the current widget state.void
unsetStateFlags
(StateFlags... flags) Turns off flag values for the current widget state.Methods inherited from class org.gnome.gobject.InitiallyUnowned
builder
Methods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newv, notify_, notify_, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.gnome.gtk.Accessible
announce, getAccessibleParent, getAccessibleRole, getAtContext, getBounds, getFirstAccessibleChild, getNextAccessibleSibling, getPlatformState, resetProperty, resetRelation, resetState, setAccessibleParent, updateNextAccessibleSibling, updatePlatformState, updateProperty, updateRelation, updateState
Methods inherited from interface org.gnome.gtk.Buildable
getBuildableId
-
Constructor Details
-
Widget
Create a Widget proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
Widget
public Widget()Creates a new Widget.
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuper
keyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()
doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName()
. This will call the native function pointer of this virtual method in the typeclass of the parent type.- Overrides:
asParent
in classInitiallyUnowned
-
getDefaultDirection
Obtains the default reading direction.- Returns:
- the current default direction
-
setDefaultDirection
Sets the default reading direction for widgets.- Parameters:
dir
- the new default direction, eitherGtk.TextDirection.ltr
orGtk.TextDirection.rtl
-
actionSetEnabled
Enables or disables an action installed withWidgetClass#installAction
.- Parameters:
actionName
- action name, such as "clipboard.paste"enabled
- whether the action is now enabled
-
activateWidget
public boolean activateWidget()Activates the widget.The activation will emit the signal set using
WidgetClass#setActivateSignal
during class initialization.Activation is what happens when you press
Enter
on a widget.If you wish to handle the activation keybinding yourself, it is recommended to use
WidgetClass#addShortcut
with an action created withSignalAction()
.If this Widget is not activatable, the function returns false.
- Returns:
- true if the widget was activated
-
activateActionIfExists
Activates an action for the widget.The action is looked up in the action groups associated with this Widget and its ancestors.
If the action is in an action group added with
insertActionGroup(java.lang.String, org.gnome.gio.ActionGroup)
, thename
is expected to be prefixed with the prefix that was used when the group was inserted.The arguments must match the actions expected parameter type, as returned by
Action.getParameterType()
.- Parameters:
name
- the name of the action to activateargs
- parameters to use- Returns:
- true if the action was activated
-
activateDefault
public void activateDefault()Activates thedefault.activate
action for the widget.The action is looked up in the same was as for
Widget#activateAction
. -
addController
Adds an event controller to the widget.The event controllers of a widget handle the events that are propagated to the widget.
You will usually want to call this function right after creating any kind of
EventController
.- Parameters:
controller
- an event controller that hasn't been added to a widget yet
-
addCssClass
Adds a style class to the widget.After calling this function, the widget’s style will match for
cssClass
, according to CSS matching rules.Use
removeCssClass(java.lang.String)
to remove the style again.- Parameters:
cssClass
- style class to add to this Widget, without the leading period
-
addMnemonicLabel
Adds a widget to the list of mnemonic labels for this widget.See
listMnemonicLabels()
.Note that the list of mnemonic labels for the widget is cleared when the widget is destroyed, so the caller must make sure to update its internal state at this point as well.
- Parameters:
label
- a widget that acts as a mnemonic label for this Widget
-
addTickCallback
Queues an animation frame update and adds a callback to be called before each frame.Until the tick callback is removed, it will be called frequently (usually at the frame rate of the output device or as quickly as the application can be repainted, whichever is slower). For this reason, is most suitable for handling graphics that change every frame or every few frames.
The tick callback does not automatically imply a relayout or repaint. If you want a repaint or relayout, and aren’t changing widget properties that would trigger that (for example, changing the text of a label), then you will have to call
queueResize()
orqueueDraw()
yourself.FrameClock.getFrameTime()
should generally be used for timing continuous animations andFrameTimings.getPredictedPresentationTime()
should be used if you are trying to display isolated frames at particular times.This is a more convenient alternative to connecting directly to the
Gdk.FrameClock::update
signal of the frame clock, since you don't have to worry about when a frame clock is assigned to a widget.To remove a tick callback, pass the ID that is returned by this function to
removeTickCallback(int)
.- Parameters:
callback
- function to call for updating animations- Returns:
- an ID for this callback
-
allocate
Assigns size, position, (optionally) a baseline and transform to a child widget.In this function, the allocation and baseline may be adjusted. The given allocation will be forced to be bigger than the widget's minimum size, as well as at least 0×0 in size.
This function is only used by widget implementations.
For a version that does not take a transform, see
sizeAllocate(org.gnome.gtk.Allocation, int)
.- Parameters:
width
- new widthheight
- new heightbaseline
- new baseline, or -1transform
- transformation to be applied
-
childFocus
Called by widgets as the user moves around the window using keyboard shortcuts.The
direction
argument indicates what kind of motion is taking place (up, down, left, right, tab forward, tab backward).This function calls the
focus(org.gnome.gtk.DirectionType)
virtual function; widgets can override the virtual function in order to implement appropriate focus behavior.The default
focus()
virtual function for a widget should return true if moving indirection
left the focus on a focusable location inside that widget, and false if moving indirection
moved the focus outside the widget. When returning true, widgets normally callgrabFocus()
to place the focus accordingly; when returning false, they don’t modify the current focus location.This function is used by custom widget implementations; if you're writing an app, you’d use
grabFocus()
to move the focus to a particular widget.- Parameters:
direction
- direction of focus movement- Returns:
- true if focus ended up inside this Widget
-
computeBounds
Computes the bounds for this Widget in the coordinate space oftarget
.The bounds of widget are (the bounding box of) the region that it is expected to draw in. See the coordinate system overview to learn more.
If the operation is successful, true is returned. If this Widget has no bounds or the bounds cannot be expressed in
target
's coordinate space (for example if both widgets are in different windows), false is returned andbounds
is set to the zero rectangle.It is valid for this Widget and
target
to be the same widget.- Parameters:
target
- the target widgetoutBounds
- the rectangle taking the bounds- Returns:
- true if the bounds could be computed
-
computeExpand
Computes whether a parent widget should give this widget extra space when possible.Widgets with children should check this, rather than looking at
getHexpand()
orgetVexpand()
.This function already checks whether the widget is visible, so visibility does not need to be checked separately. Non-visible widgets are not expanded.
The computed expand value uses either the expand setting explicitly set on the widget itself, or, if none has been explicitly set, the widget may expand if some of its children do.
- Parameters:
orientation
- expand direction- Returns:
- whether widget tree rooted here should be expanded
-
computePoint
Translates the givenpoint
in this Widget's coordinates to coordinates intarget
’s coordinate system.In order to perform this operation, both widgets must share a a common ancestor. If that is not the case,
outPoint
is set to (0, 0) and false is returned.- Parameters:
target
- the widget to transform intopoint
- a point in this Widget's coordinate systemoutPoint
- set to the corresponding coordinates intarget
's coordinate system- Returns:
- true if
srcWidget
anddestWidget
have a common ancestor, false otherwise
-
computeTransform
Computes a matrix suitable to describe a transformation from this Widget's coordinate system intotarget
's coordinate system.The transform can not be computed in certain cases, for example when this Widget and
target
do not share a common ancestor. In that caseoutTransform
gets set to the identity matrix.To learn more about widget coordinate systems, see the coordinate system overview.
- Parameters:
target
- the target widget that the matrix will transform tooutTransform
- location to store the final transformation- Returns:
- true if the transform could be computed
-
contains
public boolean contains(double x, double y) Tests if a given point is contained in the widget.The coordinates for (x, y) must be in widget coordinates, so (0, 0) is assumed to be the top left of this Widget's content area.
- Parameters:
x
- X coordinate to test, relative to this Widget's originy
- Y coordinate to test, relative to this Widget's origin- Returns:
- true if this Widget contains the point (x, y)
-
createPangoContext
Creates a newPangoContext
that is configured for the widget.The
PangoContext
will have the appropriate font map, font options, font description, and base direction set.See also
getPangoContext()
.- Returns:
- the new
PangoContext
-
createPangoLayout
Creates a newPangoLayout
that is configured for the widget.The
PangoLayout
will have the appropriate font map, font description, and base direction set.If you keep a
PangoLayout
created in this way around, you need to re-create it when the widgetsPangoContext
is replaced. This can be tracked by listening to changes of theGtk.Widget:root
property on the widget.- Parameters:
text
- text to set on the layout- Returns:
- the new
PangoLayout
-
disposeTemplate
Clears the template children for the widget.This function is the opposite of
initTemplate()
, and it is used to clear all the template children from a widget instance. If you bound a template child to a field in the instance structure, or in the instance private data structure, the field will be set toNULL
after this function returns.You should call this function inside the
GObjectClass.dispose()
implementation of any widget that calledinitTemplate()
. Typically, you will want to call this function last, right before chaining up to the parent type's dispose implementation, e.g.static void some_widget_dispose (GObject *gobject) { SomeWidget *self = SOME_WIDGET (gobject); // Clear the template data for SomeWidget gtk_widget_dispose_template (GTK_WIDGET (self), SOME_TYPE_WIDGET); G_OBJECT_CLASS (some_widget_parent_class)->dispose (gobject); }
- Parameters:
widgetType
- the type of the widget to finalize the template for- Since:
- 4.8
-
dragCheckThreshold
public boolean dragCheckThreshold(int startX, int startY, int currentX, int currentY) Checks to see if a drag movement has passed the GTK drag threshold.- Parameters:
startX
- X coordinate of start of dragstartY
- Y coordinate of start of dragcurrentX
- current X coordinatecurrentY
- current Y coordinate- Returns:
- true if the drag threshold has been passed
-
errorBell
public void errorBell()Notifies the user about an input-related error on the widget.If the
Gtk.Settings:gtk-error-bell
setting is true, it callsSurface.beep()
, otherwise it does nothing.Note that the effect of
Surface.beep()
can be configured in many ways, depending on the windowing backend and the desktop environment or window manager that is used. -
getAllocatedBaseline
Deprecated.UsegetBaseline()
insteadReturns the baseline that has currently been allocated to the widget.This function is intended to be used when implementing handlers for the
GtkWidget
Class.snapshot() function, and when allocating child widgets inGtkWidget
Class.size_allocate().- Returns:
- the baseline of the this Widget, or -1 if none
-
getAllocatedHeight
Deprecated.UsegetHeight()
insteadReturns the height that has currently been allocated to the widget.To learn more about widget sizes, see the coordinate system overview.
- Returns:
- the height of the this Widget
-
getAllocatedWidth
Deprecated.UsegetWidth()
insteadReturns the width that has currently been allocated to the widget.To learn more about widget sizes, see the coordinate system overview.
- Returns:
- the width of the this Widget
-
getAllocation
Deprecated.Retrieves the widget’s allocation.Note, when implementing a layout widget: a widget’s allocation will be its “adjusted” allocation, that is, the widget’s parent typically calls
sizeAllocate(org.gnome.gtk.Allocation, int)
with an allocation, and that allocation is then adjusted (to handle margin and alignment for example) before assignment to the widget.getAllocation(org.gnome.gtk.Allocation)
returns the adjusted allocation that was actually assigned to the widget. The adjusted allocation is guaranteed to be completely contained within thesizeAllocate(org.gnome.gtk.Allocation, int)
allocation, however.So a layout widget is guaranteed that its children stay inside the assigned bounds, but not that they have exactly the bounds the widget assigned.
- Parameters:
allocation
- a pointer to aGtkAllocation
to copy to
-
getAncestor
Gets the first ancestor of the widget with typewidgetType
.For example,
gtk_widget_get_ancestor (widget, GTK_TYPE_BOX)
gets the firstGtkBox
that’s an ancestor of this Widget. No reference will be added to the returned widget; it should not be unreferenced.Note that unlike
isAncestor(org.gnome.gtk.Widget)
, this function considers this Widget to be an ancestor of itself.- Parameters:
widgetType
- ancestor type- Returns:
- the ancestor widget
-
getBaseline
public int getBaseline()Returns the baseline that has currently been allocated to the widget.This function is intended to be used when implementing handlers for the
GtkWidgetClass.snapshot()
function, and when allocating child widgets inGtkWidgetClass.size_allocate()
.- Returns:
- the baseline of the this Widget, or -1 if none
- Since:
- 4.12
-
getCanFocus
public boolean getCanFocus()Determines whether the input focus can enter the widget or any of its children.See
setCanFocus(boolean)
.- Returns:
- true if the input focus can enter this Widget
-
getCanTarget
public boolean getCanTarget()Queries whether the widget can be the target of pointer events.- Returns:
- true if this Widget can receive pointer events
-
getChildVisible
public boolean getChildVisible()Gets the value set withsetChildVisible(boolean)
.If you feel a need to use this function, your code probably needs reorganization.
This function is only useful for widget implementations and should never be called by an application.
- Returns:
- true if the widget is mapped with the parent
-
getClipboard
Gets the clipboard object for the widget.This is a utility function to get the clipboard object for the display that this Widget is using.
Note that this function always works, even when this Widget is not realized yet.
- Returns:
- the appropriate clipboard object
-
getColor
Gets the current foreground color for the widget’s style.This function should only be used in snapshot implementations that need to do custom drawing with the foreground color.
- Parameters:
color
- return location for the color- Since:
- 4.10
-
getCssClasses
Returns the list of style classes applied to the widget.- Returns:
- a
NULL
-terminated list of css classes currently applied to this Widget
-
getCssName
-
getCursor
Gets the cursor set on the widget.See
setCursor(org.gnome.gdk.Cursor)
for details.- Returns:
- the cursor that is set on this Widget
-
getDirection
Gets the reading direction for the widget.- Returns:
- the reading direction for the widget
-
getDisplay
Get the display for the window that the widget belongs to.This function can only be called after the widget has been added to a widget hierarchy with a
GtkRoot
at the top.In general, you should only create display-specific resources when a widget has been realized, and you should free those resources when the widget is unrealized.
- Returns:
- the display for this widget
-
getFirstChild
Returns the widget’s first child.This function is primarily meant for widget implementations.
- Returns:
- the widget's first child
-
getFocusChild
Returns the focus child of the widget.- Returns:
- the current focus child of this Widget
-
getFocusOnClick
public boolean getFocusOnClick()Returns whether the widget should grab focus when it is clicked with the mouse.- Returns:
- true if the widget should grab focus when it is clicked with the mouse
-
getFocusable
public boolean getFocusable()Determines whether the widget can own the input focus.- Returns:
- true if this Widget can own the input focus
-
getFontMap
Gets the font map of the widget.- Returns:
- the font map of this Widget
-
getFontOptions
Deprecated.Returns thecairo_font_options_t
of the widget.- Returns:
- the
cairo_font_options_t
of widget
-
getFrameClock
Obtains the frame clock for a widget.The frame clock is a global “ticker” that can be used to drive animations and repaints. The most common reason to get the frame clock is to call
FrameClock.getFrameTime()
, in order to get a time to use for animating. For example you might record the start of the animation with an initial value fromFrameClock.getFrameTime()
, and then update the animation by callingFrameClock.getFrameTime()
again during each repaint.FrameClock.requestPhase(java.util.Set<org.gnome.gdk.FrameClockPhase>)
will result in a new frame on the clock, but won’t necessarily repaint any widgets. To repaint a widget, you have to usequeueDraw()
which invalidates the widget (thus scheduling it to receive a draw on the next frame).queueDraw()
will also end up requesting a frame on the appropriate frame clock.A widget’s frame clock will not change while the widget is mapped. Reparenting a widget (which implies a temporary unmap) can change the widget’s frame clock.
Unrealized widgets do not have a frame clock.
- Returns:
- the frame clock
-
getHalign
Gets the horizontal alignment of the widget.For backwards compatibility reasons this method will never return one of the baseline alignments, but instead it will convert it to
Gtk.Align.fill
orGtk.Align.center
.Baselines are not supported for horizontal alignment.
- Returns:
- the horizontal alignment of this Widget
-
getHasTooltip
public boolean getHasTooltip()Returns the current value of thehas-tooltip
property.- Returns:
- current value of
has-tooltip
on this Widget
-
getHeight
public int getHeight()Returns the content height of the widget.This function returns the height passed to its size-allocate implementation, which is the height you should be using in
snapshot(org.gnome.gtk.Snapshot)
.For pointer events, see
contains(double, double)
.To learn more about widget sizes, see the coordinate system overview.
- Returns:
- The height of this Widget
-
getHexpand
public boolean getHexpand()Gets whether the widget would like any available extra horizontal space.When a user resizes a window, widgets with expand set to true generally receive the extra space. For example, a list or scrollable area or document in your window would often be set to expand.
Widgets with children should use
computeExpand(org.gnome.gtk.Orientation)
rather than this function, to see whether any of its children, has the expand flag set. If any child of a widget wants to expand, the parent may ask to expand also.This function only looks at the widget’s own hexpand flag, rather than computing whether the entire widget tree rooted at this widget wants to expand.
- Returns:
- whether hexpand flag is set
-
getHexpandSet
public boolean getHexpandSet()Gets whether thehexpand
flag has been explicitly set.If
Gtk.Widget:hexpand
property is set, then it overrides any computed expand value based on child widgets. Ifhexpand
is not set, then the expand value depends on whether any children of the widget would like to expand.There are few reasons to use this function, but it’s here for completeness and consistency.
- Returns:
- whether hexpand has been explicitly set
-
getLastChild
Returns the widget’s last child.This function is primarily meant for widget implementations.
- Returns:
- the widget's last child
-
getLayoutManager
Retrieves the layout manager of the widget.- Returns:
- the layout manager of this Widget
-
getLimitEvents
public boolean getLimitEvents()Gets the value of theGtk.Widget:limit-events
property.- Since:
- 4.18
-
getMapped
public boolean getMapped()Returns whether the widget is mapped.- Returns:
- true if the widget is mapped
-
getMarginBottom
public int getMarginBottom()Gets the bottom margin of the widget.- Returns:
- The bottom margin of this Widget
-
getMarginEnd
public int getMarginEnd()Gets the end margin of the widget.- Returns:
- The end margin of this Widget
-
getMarginStart
public int getMarginStart()Gets the start margin of the widget.- Returns:
- The start margin of this Widget
-
getMarginTop
public int getMarginTop()Gets the top margin of the widget.- Returns:
- The top margin of this Widget
-
getName
Retrieves the name of a widget.See
setName(java.lang.String)
for the significance of widget names.- Returns:
- name of the widget
-
getNative
Returns the nearestGtkNative
ancestor of the widget.This function will return
NULL
if the widget is not contained inside a widget tree with a native ancestor.GtkNative
widgets will return themselves here.- Returns:
- the
GtkNative
ancestor of this Widget
-
getNextSibling
Returns the widget’s next sibling.This function is primarily meant for widget implementations.
- Returns:
- the widget's next sibling
-
getOpacity
public double getOpacity()Fetches the requested opacity for the widget.See
setOpacity(double)
.- Returns:
- the requested opacity for this widget
-
getOverflow
Returns the widget’s overflow value.- Returns:
- The widget's overflow value
-
getPangoContext
Gets aPangoContext
that is configured for the widget.The
PangoContext
will have the appropriate font map, font description, and base direction set.Unlike the context returned by
createPangoContext()
, this context is owned by the widget (it can be used until the screen for the widget changes or the widget is removed from its toplevel), and will be updated to match any changes to the widget’s attributes. This can be tracked by listening to changes of theGtk.Widget:root
property on the widget.- Returns:
- the
PangoContext
for the widget
-
getParent
Returns the parent widget of the widget.- Returns:
- the parent widget of this Widget
-
getPreferredSize
public void getPreferredSize(@Nullable @Nullable Requisition minimumSize, @Nullable @Nullable Requisition naturalSize) Retrieves the minimum and natural size of a widget, taking into account the widget’s preference for height-for-width management.This is used to retrieve a suitable size by container widgets which do not impose any restrictions on the child placement. It can be used to deduce toplevel window and menu sizes as well as child widgets in free-form containers such as
GtkFixed
.Handle with care. Note that the natural height of a height-for-width widget will generally be a smaller size than the minimum height, since the required height for the natural width is generally smaller than the required height for the minimum width.
Use
measure(org.gnome.gtk.Orientation, int, io.github.jwharm.javagi.base.Out<java.lang.Integer>, io.github.jwharm.javagi.base.Out<java.lang.Integer>, io.github.jwharm.javagi.base.Out<java.lang.Integer>, io.github.jwharm.javagi.base.Out<java.lang.Integer>)
if you want to support baseline alignment.- Parameters:
minimumSize
- location for storing the minimum sizenaturalSize
- location for storing the natural size
-
getPrevSibling
Returns the widget’s previous sibling.This function is primarily meant for widget implementations.
- Returns:
- the widget's previous sibling
-
getPrimaryClipboard
Gets the primary clipboard of the widget.This is a utility function to get the primary clipboard object for the display that this Widget is using.
Note that this function always works, even when this Widget is not realized yet.
- Returns:
- the appropriate clipboard object
-
getRealized
public boolean getRealized()Determines whether the widget is realized.- Returns:
- true if this Widget is realized
-
getReceivesDefault
public boolean getReceivesDefault()Determines whether the widget is always treated as the default widget within its toplevel when it has the focus, even if another widget is the default.- Returns:
- true if this Widget acts as the default widget when focused
-
getRequestMode
Gets whether the widget prefers a height-for-width layout or a width-for-height layout.Single-child widgets generally propagate the preference of their child, more complex widgets need to request something either in context of their children or in context of their allocation capabilities.
- Returns:
- The
GtkSizeRequestMode
preferred by this Widget.
-
getRoot
Returns theGtkRoot
widget of the widget.This function will return
NULL
if the widget is not contained inside a widget tree with a root widget.GtkRoot
widgets will return themselves here.- Returns:
- the root widget of this Widget
-
getScaleFactor
public int getScaleFactor()Retrieves the internal scale factor that maps from window coordinates to the actual device pixels.On traditional systems this is 1, on high density outputs, it can be a higher value (typically 2).
Note that modern systems may support fractional scaling, where the scale factor is not an integer. On such systems, this function will return the next higher integer value, but you probably want to use
Surface.getScale()
to get the fractional scale value.- Returns:
- the scale factor for this Widget
-
getSensitive
public boolean getSensitive()Returns the widget’s sensitivity.This function returns the value that has been set using
setSensitive(boolean)
).The effective sensitivity of a widget is however determined by both its own and its parent widget’s sensitivity. See
isSensitive()
.- Returns:
- true if the widget is sensitive
-
getSettings
Gets the settings object holding the settings used for the widget.Note that this function can only be called when the
GtkWidget
is attached to a toplevel, since the settings object is specific to a particular display. If you want to monitor the widget for changes in its settings, connect to thenotify::display
signal.- Returns:
- the relevant settings object
-
getSize
Returns the content width or height of the widget.Which dimension is returned depends on
orientation
.This is equivalent to calling
getWidth()
forGtk.Orientation.horizontal
orgetHeight()
forGtk.Orientation.vertical
, but can be used when writing orientation-independent code, such as when implementingOrientable
widgets.To learn more about widget sizes, see the coordinate system overview.
- Parameters:
orientation
- the orientation to query- Returns:
- the size of this Widget in
orientation
-
getSizeRequest
public void getSizeRequest(@Nullable @Nullable Out<Integer> width, @Nullable @Nullable Out<Integer> height) Gets the size request that was explicitly set for the widget.A value of -1 stored in
width
orheight
indicates that that dimension has not been set explicitly and the natural requisition of the widget will be used instead.To get the size a widget will actually request, call
measure(org.gnome.gtk.Orientation, int, io.github.jwharm.javagi.base.Out<java.lang.Integer>, io.github.jwharm.javagi.base.Out<java.lang.Integer>, io.github.jwharm.javagi.base.Out<java.lang.Integer>, io.github.jwharm.javagi.base.Out<java.lang.Integer>)
instead of this function.- Parameters:
width
- return location for widthheight
- return location for height
-
getStateFlags
Returns the widget state as a flag set.It is worth mentioning that the effective
Gtk.StateFlags.insensitive
state will be returned, that is, also based on parent insensitivity, even if this Widget itself is sensitive.Also note that if you are looking for a way to obtain the
Gtk.StateFlags
to pass to aStyleContext
method, you should look atStyleContext.getState()
.- Returns:
- the state flags of widget
-
getStyleContext
Deprecated.Style contexts will be removed in GTK 5Returns the style context associated to the widget.The returned object is guaranteed to be the same for the lifetime of this Widget.
- Returns:
- the widgets style context
-
getTemplateChild
Fetches an object build from the template XML forwidgetType
in the widget.This will only report children which were previously declared with
WidgetClass#bindTemplateChildFull
or one of its variants.This function is only meant to be called for code which is private to the
widgetType
which declared the child and is meant for language bindings which cannot easily make use of the GObject structure offsets.- Parameters:
widgetType
- TheGType
to get a template child forname
- ID of the child defined in the template XML- Returns:
- the object built in the template XML with
the id
name
-
getTooltipMarkup
Gets the contents of the tooltip for the widget.If the tooltip has not been set using
setTooltipMarkup(java.lang.String)
, this function returnsNULL
.- Returns:
- the tooltip text
-
getTooltipText
Gets the contents of the tooltip for the widget.If the this Widget's tooltip was set using
setTooltipMarkup(java.lang.String)
, this function will return the escaped text.- Returns:
- the tooltip text
-
getValign
Gets the vertical alignment of the widget.- Returns:
- the vertical alignment of this Widget
-
getVexpand
public boolean getVexpand()Gets whether the widget would like any available extra vertical space.See
getHexpand()
for more detail.- Returns:
- whether vexpand flag is set
-
getVexpandSet
public boolean getVexpandSet()Gets whether thevexpand
flag has been explicitly set.See
getHexpandSet()
for more detail.- Returns:
- whether vexpand has been explicitly set
-
getVisible
public boolean getVisible()Determines whether the widget is visible.If you want to take into account whether the widget’s parent is also marked as visible, use
isVisible()
instead.This function does not check if the widget is obscured in any way.
See
setVisible(boolean)
.- Returns:
- true if the widget is visible
-
getWidth
public int getWidth()Returns the content width of the widget.This function returns the width passed to its size-allocate implementation, which is the width you should be using in
snapshot(org.gnome.gtk.Snapshot)
.For pointer events, see
contains(double, double)
.To learn more about widget sizes, see the coordinate system overview.
- Returns:
- The width of this Widget
-
grabFocus
public boolean grabFocus()Causes this Widget to have the keyboard focus for the window that it belongs to.If this Widget is not focusable, or its
grabFocus()
implementation cannot transfer the focus to a descendant of this Widget that is focusable, it will not take focus and false will be returned.Calling
grabFocus()
on an already focused widget is allowed, should not have an effect, and return true.- Returns:
- true if focus is now inside this Widget
-
hasCssClass
Returns whether a style class is currently applied to the widget.- Parameters:
cssClass
- style class, without the leading period- Returns:
- true if
cssClass
is currently applied to this Widget
-
hasDefault
public boolean hasDefault()Determines whether the widget is the current default widget within its toplevel.- Returns:
- true if this Widget is the current default widget within its toplevel
-
hasFocus
public boolean hasFocus()Determines if the widget has the global input focus.See
isFocus()
for the difference between having the global input focus, and only having the focus within a toplevel.- Returns:
- true if the widget has the global input focus
-
hasVisibleFocus
public boolean hasVisibleFocus()Determines if the widget should show a visible indication that it has the global input focus.This is a convenience function that takes into account whether focus indication should currently be shown in the toplevel window of this Widget. See
Window.getFocusVisible()
for more information about focus indication.To find out if the widget has the global input focus, use
hasFocus()
.- Returns:
- true if the widget should display a “focus rectangle”
-
hide
Deprecated.UsesetVisible(boolean)
insteadReverses the effects of [method.Gtk.Widget.show].This is causing the widget to be hidden (invisible to the user).
-
inDestruction
public boolean inDestruction()Returns whether the widget is currently being destroyed.This information can sometimes be used to avoid doing unnecessary work.
- Returns:
- true if this Widget is being destroyed
-
initTemplate
public void initTemplate()Creates and initializes child widgets defined in templates.This function must be called in the instance initializer for any class which assigned itself a template using
WidgetClass#setTemplate
.It is important to call this function in the instance initializer of a widget subclass and not in
GObject.constructed()
orGObject.constructor()
for two reasons:- derived widgets will assume that the composite widgets defined by its parent classes have been created in their relative instance initializers
- when calling
g_object_new()
on a widget with composite templates, it’s important to build the composite widgets before the construct properties are set. Properties passed tog_object_new()
should take precedence over properties set in the private template XML
A good rule of thumb is to call this function as the first thing in an instance initialization function.
-
insertActionGroup
Inserts an action group into the widget's actions.Children of this Widget that implement
Actionable
can then be associated with actions ingroup
by setting their “action-name” toprefix
.action-name
.Note that inheritance is defined for individual actions. I.e. even if you insert a group with prefix
prefix
, actions with the same prefix will still be inherited from the parent, unless the group contains an action with the same name.If
group
isNULL
, a previously inserted group forname
is removed from this Widget.- Parameters:
name
- the prefix for actions ingroup
group
- an action group
-
insertAfter
Sets the parent widget of the widget.In contrast to
setParent(org.gnome.gtk.Widget)
, this function inserts this Widget at a specific position into the list of children of theparent
widget.It will be placed after
previousSibling
, or at the beginning ifpreviousSibling
isNULL
.After calling this function,
gtk_widget_get_prev_sibling (widget)
will returnpreviousSibling
.If
parent
is already set as the parent widget of this Widget, this function can also be used to reorder this Widget in the child widget list ofparent
.This function is primarily meant for widget implementations; if you are just using a widget, you must use its own API for adding children.
- Parameters:
parent
- the parent widget to insert this Widget intopreviousSibling
- the new previous sibling of this Widget
-
insertBefore
Sets the parent widget of the widget.In contrast to
setParent(org.gnome.gtk.Widget)
, this function inserts this Widget at a specific position into the list of children of theparent
widget.It will be placed before
nextSibling
, or at the end ifnextSibling
isNULL
.After calling this function,
gtk_widget_get_next_sibling (widget)
will returnnextSibling
.If
parent
is already set as the parent widget of this Widget, this function can also be used to reorder this Widget in the child widget list ofparent
.This function is primarily meant for widget implementations; if you are just using a widget, you must use its own API for adding children.
- Parameters:
parent
- the parent widget to insert this Widget intonextSibling
- the new next sibling of this Widget
-
isAncestor
Determines whether the widget is a descendent ofancestor
.- Parameters:
ancestor
- anotherGtkWidget
- Returns:
- true if
ancestor
contains this Widget as a child, grandchild, great grandchild, etc
-
isDrawable
public boolean isDrawable()Determines whether the widget can be drawn to.A widget can be drawn if it is mapped and visible.
- Returns:
- true if this Widget is drawable
-
isFocus
public boolean isFocus()Determines if the widget is the focus widget within its toplevel.This does not mean that the
Gtk.Widget:has-focus
property is necessarily set;Gtk.Widget:has-focus
will only be set if the toplevel widget additionally has the global input focus.- Returns:
- true if the widget is the focus widget
-
isSensitive
public boolean isSensitive()Returns the widget’s effective sensitivity.This means it is sensitive itself and also its parent widget is sensitive.
- Returns:
- true if the widget is effectively sensitive
-
isVisible
public boolean isVisible()Determines whether the widget and all its parents are marked as visible.This function does not check if the widget is obscured in any way.
See also
getVisible()
andsetVisible(boolean)
.- Returns:
- true if the widget and all its parents are visible
-
listMnemonicLabels
Returns the widgets for which this widget is the target of a mnemonic.Typically, these widgets will be labels. See, for example,
Label.setMnemonicWidget(org.gnome.gtk.Widget)
.The widgets in the list are not individually referenced. If you want to iterate through the list and perform actions involving callbacks that might destroy the widgets, you must call
g_list_foreach (result, (GFunc)g_object_ref, NULL)
first, and then unref all the widgets afterwards.- Returns:
- the list of mnemonic labels
-
map
public void map()Causes a widget to be mapped if it isn’t already.This function is only for use in widget implementations.
-
measure
public void measure(Orientation orientation, int forSize, @Nullable @Nullable Out<Integer> minimum, @Nullable @Nullable Out<Integer> natural, @Nullable @Nullable Out<Integer> minimumBaseline, @Nullable @Nullable Out<Integer> naturalBaseline) Measures this Widget in the orientationorientation
and for the givenforSize
.As an example, if
orientation
isOrientation.HORIZONTAL
andforSize
is 300, this functions will compute the minimum and natural width of this Widget if it is allocated at a height of 300 pixels.See GtkWidget’s geometry management section for a more details on implementing
GtkWidgetClass.measure()
.- Parameters:
orientation
- the orientation to measureforSize
- Size for the opposite oforientation
, i.e. iforientation
isOrientation.HORIZONTAL
, this is the height the widget should be measured with. TheOrientation.VERTICAL
case is analogous. This way, both height-for-width and width-for-height requests can be implemented. If no size is known, -1 can be passed.minimum
- location to store the minimum sizenatural
- location to store the natural sizeminimumBaseline
- location to store the baseline position for the minimum size, or -1 to report no baselinenaturalBaseline
- location to store the baseline position for the natural size, or -1 to report no baseline
-
mnemonicActivate
public boolean mnemonicActivate(boolean groupCycling) Emits theGtk.Widget::mnemonic-activate
signal.- Parameters:
groupCycling
- true if there are other widgets with the same mnemonic- Returns:
- true if the signal has been handled
-
observeChildren
Returns a list model to track the children of the widget.Calling this function will enable extra internal bookkeeping to track children and emit signals on the returned listmodel. It may slow down operations a lot.
Applications should try hard to avoid calling this function because of the slowdowns.
- Returns:
- a list model tracking this Widget's children
-
observeControllers
Returns a list model to track the event controllers of the widget.Calling this function will enable extra internal bookkeeping to track controllers and emit signals on the returned listmodel. It may slow down operations a lot.
Applications should try hard to avoid calling this function because of the slowdowns.
- Returns:
- a list model tracking this Widget's controllers
-
pick
Finds the descendant of the widget closest to a point.The point (x, y) must be given in widget coordinates, so (0, 0) is assumed to be the top left of this Widget's content area.
Usually widgets will return
NULL
if the given coordinate is not contained in this Widget checked viacontains(double, double)
. Otherwise they will recursively try to find a child that does not returnNULL
. Widgets are however free to customize their picking algorithm.This function is used on the toplevel to determine the widget below the mouse cursor for purposes of hover highlighting and delivering events.
- Parameters:
x
- x coordinate to test, relative to this Widget's originy
- y coordinate to test, relative to this Widget's originflags
- flags to influence what is picked- Returns:
- the widget's descendant at (x, y)
-
pick
Finds the descendant of the widget closest to a point.The point (x, y) must be given in widget coordinates, so (0, 0) is assumed to be the top left of this Widget's content area.
Usually widgets will return
NULL
if the given coordinate is not contained in this Widget checked viacontains(double, double)
. Otherwise they will recursively try to find a child that does not returnNULL
. Widgets are however free to customize their picking algorithm.This function is used on the toplevel to determine the widget below the mouse cursor for purposes of hover highlighting and delivering events.
- Parameters:
x
- x coordinate to test, relative to this Widget's originy
- y coordinate to test, relative to this Widget's originflags
- flags to influence what is picked- Returns:
- the widget's descendant at (x, y)
-
queueAllocate
public void queueAllocate()Flags the widget for a rerun of thesizeAllocate(org.gnome.gtk.Allocation, int)
function.Use this function instead of
queueResize()
when the this Widget's size request didn't change but it wants to reposition its contents.An example user of this function is
setHalign(org.gnome.gtk.Align)
.This function is only for use in widget implementations.
-
queueDraw
public void queueDraw()Schedules this widget to be redrawn.The redraw will happen in the paint phase of the current or the next frame.
This means this Widget's
snapshot(org.gnome.gtk.Snapshot)
implementation will be called. -
queueResize
public void queueResize()Flags a widget to have its size renegotiated.This should be called when a widget for some reason has a new size request. For example, when you change the text in a
Label
, the label queues a resize to ensure there’s enough space for the new text.Note that you cannot call gtk_widget_queue_resize() on a widget from inside its implementation of the
sizeAllocate(org.gnome.gtk.Allocation, int)
virtual method. Calls to gtk_widget_queue_resize() from insidesizeAllocate(org.gnome.gtk.Allocation, int)
will be silently ignored.This function is only for use in widget implementations.
-
realize
public void realize()Creates the GDK resources associated with a widget.Normally realization happens implicitly; if you show a widget and all its parent containers, then the widget will be realized and mapped automatically.
Realizing a widget requires all the widget’s parent widgets to be realized; calling this function realizes the widget’s parents in addition to this Widget itself. If a widget is not yet inside a toplevel window when you realize it, bad things will happen.
This function is primarily used in widget implementations, and isn’t very useful otherwise. Many times when you think you might need it, a better approach is to connect to a signal that will be called after the widget is realized automatically, such as
Gtk.Widget::realize
. -
removeController
Removes an event controller from the widget.The removed event controller will not receive any more events, and should not be used again.
Widgets will remove all event controllers automatically when they are destroyed, there is normally no need to call this function.
- Parameters:
controller
- an event controller
-
removeCssClass
Removes a style from the widget.After this, the style of this Widget will stop matching for
cssClass
.- Parameters:
cssClass
- style class to remove from this Widget, without the leading period
-
removeMnemonicLabel
Removes a widget from the list of mnemonic labels for this widget.See
listMnemonicLabels()
.The widget must have previously been added to the list with
addMnemonicLabel(org.gnome.gtk.Widget)
.- Parameters:
label
- a widget that is a mnemonic label for this Widget
-
removeTickCallback
public void removeTickCallback(int id) Removes a tick callback previously registered withaddTickCallback(org.gnome.gtk.TickCallback)
.- Parameters:
id
- an ID returned byaddTickCallback(org.gnome.gtk.TickCallback)
-
setCanFocus
public void setCanFocus(boolean canFocus) Sets whether the input focus can enter the widget or any of its children.Applications should set
canFocus
to false to mark a widget as for pointer/touch use only.Note that having
canFocus
be true is only one of the necessary conditions for being focusable. A widget must also be sensitive and focusable and not have an ancestor that is marked as not can-focus in order to receive input focus.See
grabFocus()
for actually setting the input focus on a widget.- Parameters:
canFocus
- whether the input focus can enter the widget or any of its children
-
setCanTarget
public void setCanTarget(boolean canTarget) Sets whether the widget can be the target of pointer events.- Parameters:
canTarget
- whether this widget should be able to receive pointer events
-
setChildVisible
public void setChildVisible(boolean childVisible) Sets whether the widget should be mapped along with its parent.The child visibility can be set for widget before it is added to a container with
setParent(org.gnome.gtk.Widget)
, to avoid mapping children unnecessary before immediately unmapping them. However it will be reset to its default state of true when the widget is removed from a container.Note that changing the child visibility of a widget does not queue a resize on the widget. Most of the time, the size of a widget is computed from all visible children, whether or not they are mapped. If this is not the case, the container can queue a resize itself.
This function is only useful for widget implementations and should never be called by an application.
- Parameters:
childVisible
- whether this Widget should be mapped along with its parent
-
setCssClasses
Replaces the current style classes of the widget withclasses
.- Parameters:
classes
-NULL
-terminated list of style classes
-
setCursor
Sets the cursor to be shown when the pointer hovers over the widget.If the
cursor
isNULL
, this Widget will use the cursor inherited from its parent.- Parameters:
cursor
- the new cursor
-
setCursorFromName
Sets the cursor to be shown when the pointer hovers over the widget.This is a utility function that creates a cursor via
Cursor.fromName(java.lang.String, org.gnome.gdk.Cursor)
and then sets it on this Widget withsetCursor(org.gnome.gdk.Cursor)
. See those functions for details.On top of that, this function allows
name
to beNULL
, which will do the same as callingsetCursor(org.gnome.gdk.Cursor)
with aNULL
cursor.- Parameters:
name
- the name of the cursor
-
setDirection
Sets the reading direction on the widget.This direction controls the primary direction for widgets containing text, and also the direction in which the children of a container are packed. The ability to set the direction is present in order so that correct localization into languages with right-to-left reading directions can be done.
Generally, applications will let the default reading direction prevail, except for widgets where the children are arranged in an order that is explicitly visual rather than logical (such as buttons for text justification).
If the direction is set to
Gtk.TextDirection.none
, then the value set bysetDefaultDirection(org.gnome.gtk.TextDirection)
will be used.- Parameters:
dir
- the new direction
-
setFocusChild
Set the focus child of the widget.This function is only suitable for widget implementations. If you want a certain widget to get the input focus, call
grabFocus()
on it.- Parameters:
child
- a direct child widget of this Widget orNULL
to unset the focus child
-
setFocusOnClick
public void setFocusOnClick(boolean focusOnClick) Sets whether the widget should 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.
- Parameters:
focusOnClick
- whether the widget should grab focus when clicked with the mouse
-
setFocusable
public void setFocusable(boolean focusable) Sets whether the widget can own the input focus.Widget implementations should set
focusable
to true in their init() function if they want to receive keyboard input.Note that having
focusable
be true is only one of the necessary conditions for being focusable. A widget must also be sensitive and can-focus and not have an ancestor that is marked as not can-focus in order to receive input focus.See
grabFocus()
for actually setting the input focus on a widget.- Parameters:
focusable
- whether or not this Widget can own the input focus
-
setFontMap
Sets the font map to use for text rendering in the widget.The font map is the object that is used to look up fonts. Setting a custom font map can be useful in special situations, e.g. when you need to add application-specific fonts to the set of available fonts.
When not set, the widget will inherit the font map from its parent.
- Parameters:
fontMap
- aPangoFontMap
-
setFontOptions
@Deprecated public void setFontOptions(@Nullable @Nullable org.freedesktop.cairo.FontOptions options) Deprecated.Sets thecairo_font_options_t
used for text rendering in the widget.When not set, the default font options for the
GdkDisplay
will be used.- Parameters:
options
- acairo_font_options_t
struct to unset any previously set default font options
-
setHalign
Sets the horizontal alignment of the widget.- Parameters:
align
- the horizontal alignment
-
setHasTooltip
public void setHasTooltip(boolean hasTooltip) Sets thehas-tooltip
property on the widget.- Parameters:
hasTooltip
- whether or not this Widget has a tooltip
-
setHexpand
public void setHexpand(boolean expand) Sets whether the widget would like any available extra horizontal space.When a user resizes a window, widgets with expand set to true generally receive the extra space. For example, a list or scrollable area or document in your window would often be set to expand.
Call this function to set the expand flag if you would like your widget to become larger horizontally when the window has extra room.
By default, widgets automatically expand if any of their children want to expand. (To see if a widget will automatically expand given its current children and state, call
computeExpand(org.gnome.gtk.Orientation)
. A widget can decide how the expandability of children affects its own expansion by overriding thecompute_expand
virtual method onGtkWidget
.).Setting hexpand explicitly with this function will override the automatic expand behavior.
This function forces the widget to expand or not to expand, regardless of children. The override occurs because
setHexpand(boolean)
sets the hexpand-set property (seesetHexpandSet(boolean)
) which causes the widget’s hexpand value to be used, rather than looking at children and widget state.- Parameters:
expand
- whether to expand
-
setHexpandSet
public void setHexpandSet(boolean set) Sets whether the hexpand flag will be used.The
Gtk.Widget:hexpand-set
property will be set automatically when you callsetHexpand(boolean)
to set hexpand, so the most likely reason to use this function would be to unset an explicit expand flag.If hexpand is set, then it overrides any computed expand value based on child widgets. If hexpand is not set, then the expand value depends on whether any children of the widget would like to expand.
There are few reasons to use this function, but it’s here for completeness and consistency.
- Parameters:
set
- value for hexpand-set property
-
setLayoutManager
Sets the layout manager to use for measuring and allocating children of the widget.- Parameters:
layoutManager
- a layout manager
-
setLimitEvents
public void setLimitEvents(boolean limitEvents) Sets whether the widget acts like a modal dialog, with respect to event delivery.- Parameters:
limitEvents
- whether to limit events- Since:
- 4.18
-
setMarginBottom
public void setMarginBottom(int margin) Sets the bottom margin of the widget.- Parameters:
margin
- the bottom margin
-
setMarginEnd
public void setMarginEnd(int margin) Sets the end margin of the widget.- Parameters:
margin
- the end margin
-
setMarginStart
public void setMarginStart(int margin) Sets the start margin of the widget.- Parameters:
margin
- the start margin
-
setMarginTop
public void setMarginTop(int margin) Sets the top margin of the widget.- Parameters:
margin
- the top margin
-
setName
Sets a widgets name.Setting a name allows you to refer to the widget from a CSS file. You can apply a style to widgets with a particular name in the CSS file. See the documentation for the CSS syntax (on the same page as the docs for
StyleContext
.Note that the CSS syntax has certain special characters to delimit and represent elements in a selector (period,
,
>, *...), so using these will make your widget impossible to match by name. Any combination of alphanumeric symbols, dashes and underscores will suffice.- Parameters:
name
- name for the widget
-
setOpacity
public void setOpacity(double opacity) Requests the widget to be rendered partially transparent.An opacity of 0 is fully transparent and an opacity of 1 is fully opaque.
Opacity works on both toplevel widgets and child widgets, although there are some limitations: For toplevel widgets, applying opacity depends on the capabilities of the windowing system. On X11, this has any effect only on X displays with a compositing manager, see
Display.isComposited()
. On Windows and Wayland it will always work, although setting a window’s opacity after the window has been shown may cause some flicker.Note that the opacity is inherited through inclusion — if you set a toplevel to be partially translucent, all of its content will appear translucent, since it is ultimatively rendered on that toplevel. The opacity value itself is not inherited by child widgets (since that would make widgets deeper in the hierarchy progressively more translucent). As a consequence,
Popover
instances and otherNative
widgets with their own surface will use their own opacity value, and thus by default appear non-translucent, even if they are attached to a toplevel that is translucent.- Parameters:
opacity
- desired opacity, between 0 and 1
-
setOverflow
Sets how the widget treats content that is drawn outside the it's content area.See the definition of
Gtk.Overflow
for details.This setting is provided for widget implementations and should not be used by application code.
The default value is
Gtk.Overflow.visible
.- Parameters:
overflow
- desired overflow value
-
setParent
Sets the parent widget of the widget.This takes care of details such as updating the state and style of the child to reflect its new location and resizing the parent. The opposite function is
unparent()
.This function is useful only when implementing subclasses of
GtkWidget
.- Parameters:
parent
- parent widget
-
setReceivesDefault
public void setReceivesDefault(boolean receivesDefault) Sets whether the widget will be treated as the default widget within its toplevel when it has the focus, even if another widget is the default.- Parameters:
receivesDefault
- whether or not this Widget can be a default widget
-
setSensitive
public void setSensitive(boolean sensitive) Sets the sensitivity of the widget.A widget is sensitive if the user can interact with it. Insensitive widgets are “grayed out” and the user can’t interact with them. Insensitive widgets are known as “inactive”, “disabled”, or “ghosted” in some other toolkits.
- Parameters:
sensitive
- true to make the widget sensitive
-
setSizeRequest
public void setSizeRequest(int width, int height) Sets the minimum size of the widget.That is, the widget’s size request will be at least
width
byheight
. You can use this function to force a widget to be larger than it normally would be.In most cases,
Window.setDefaultSize(int, int)
is a better choice for toplevel windows than this function; setting the default size will still allow users to shrink the window. Setting the size request will force them to leave the window at least as large as the size request.Note the inherent danger of setting any fixed size - themes, translations into other languages, different fonts, and user action can all change the appropriate size for a given widget. So, it is basically impossible to hardcode a size that will always work.
The size request of a widget is the smallest size a widget can accept while still functioning well and drawing itself correctly. However in some strange cases a widget may be allocated less than its requested size, and in many cases a widget may be allocated more space than it requested.
If the size request in a given direction is -1 (unset), then the “natural” size request of the widget will be used instead.
The size request set here does not include any margin from the properties
Gtk.Widget:margin-start
,Gtk.Widget:margin-end
,Gtk.Widget:margin-top
, andGtk.Widget:margin-bottom
, but it does include pretty much all other padding or border properties set by any subclass ofGtkWidget
.- Parameters:
width
- width this Widget should request, or -1 to unsetheight
- height this Widget should request, or -1 to unset
-
setStateFlags
Turns on flag values in the current widget state.Typical widget states are insensitive, prelighted, etc.
This function accepts the values
Gtk.StateFlags.dir-ltr
andGtk.StateFlags.dir-rtl
but ignores them. If you want to set the widget's direction, usesetDirection(org.gnome.gtk.TextDirection)
.This function is for use in widget implementations.
- Parameters:
flags
- state flags to turn onclear
- whether to clear state before turning onflags
-
setStateFlags
Turns on flag values in the current widget state.Typical widget states are insensitive, prelighted, etc.
This function accepts the values
Gtk.StateFlags.dir-ltr
andGtk.StateFlags.dir-rtl
but ignores them. If you want to set the widget's direction, usesetDirection(org.gnome.gtk.TextDirection)
.This function is for use in widget implementations.
- Parameters:
flags
- state flags to turn onclear
- whether to clear state before turning onflags
-
setTooltipMarkup
Sets the contents of the tooltip for widget.markup
must contain Pango markup.This function will take care of setting the
Gtk.Widget:has-tooltip
as a side effect, and of the default handler for theGtk.Widget::query-tooltip
signal.See also
Tooltip.setMarkup(java.lang.String)
.- Parameters:
markup
- the contents of the tooltip for this Widget
-
setTooltipText
Sets the contents of the tooltip for the widget.If
text
contains any markup, it will be escaped.This function will take care of setting
Gtk.Widget:has-tooltip
as a side effect, and of the default handler for theGtk.Widget::query-tooltip
signal.See also
Tooltip.setText(java.lang.String)
.- Parameters:
text
- the contents of the tooltip for this Widget
-
setValign
Sets the vertical alignment of the widget.- Parameters:
align
- the vertical alignment
-
setVexpand
public void setVexpand(boolean expand) Sets whether the widget would like any available extra vertical space.See
setHexpand(boolean)
for more detail.- Parameters:
expand
- whether to expand
-
setVexpandSet
public void setVexpandSet(boolean set) Sets whether the vexpand flag will be used.See
setHexpandSet(boolean)
for more detail.- Parameters:
set
- value for vexpand-set property
-
setVisible
public void setVisible(boolean visible) Sets the visibility state of this Widget.Note that setting this to true doesn’t mean the widget is actually viewable, see
getVisible()
.- Parameters:
visible
- whether the widget should be shown or not
-
shouldLayout
public boolean shouldLayout()Returns whether the widget should contribute to the measuring and allocation of its parent.This is false for invisible children, but also for children that have their own surface, such as
Popover
instances.- Returns:
- true if child should be included in measuring and allocating
-
show
Deprecated.UsesetVisible(boolean)
insteadFlags a widget to be displayed.Any widget that isn’t shown will not appear on the screen.
Remember that you have to show the containers containing a widget, in addition to the widget itself, before it will appear onscreen.
When a toplevel widget is shown, it is immediately realized and mapped; other shown widgets are realized and mapped when their toplevel widget is realized and mapped.
-
sizeAllocate
Allocates widget with a transformation that translates the origin to the position inallocation
.This is a simple form of
allocate(int, int, int, org.gnome.gsk.Transform)
.- Parameters:
allocation
- position and size to be allocated to this Widgetbaseline
- the baseline of the child, or -1
-
snapshotChild
Snapshots a child of the widget.When a widget receives a call to the snapshot function, it must send synthetic
snapshot(org.gnome.gtk.Snapshot)
calls to all children. This function provides a convenient way of doing this. A widget, when it receives a call to itssnapshot(org.gnome.gtk.Snapshot)
function, calls gtk_widget_snapshot_child() once for each child, passing in thesnapshot
the widget received.This function takes care of translating the origin of
snapshot
, and deciding whether the child needs to be snapshot.It does nothing for children that implement
GtkNative
.- Parameters:
child
- a child of this Widgetsnapshot
- snapshot as passed to the widget. In particular, no calls toSnapshot.translate(org.gnome.graphene.Point)
or other transform calls should have been made
-
translateCoordinates
@Deprecated public boolean translateCoordinates(Widget destWidget, double srcX, double srcY, @Nullable @Nullable Out<Double> destX, @Nullable @Nullable Out<Double> destY) Deprecated.Translates coordinates relative to this Widget’s allocation to coordinates relative todestWidget
’s allocations.In order to perform this operation, both widget must share a common ancestor. If that is not the case,
destX
anddestY
are set to 0 and false is returned.- Parameters:
destWidget
- another widgetsrcX
- X position in widget coordinates of this WidgetsrcY
- Y position in widget coordinates of this WidgetdestX
- location to store X position in widget coordinates ofdestWidget
destY
- location to store Y position in widget coordinates ofdestWidget
- Returns:
- true if this Widget and
destWidget
have a common ancestor, false otherwise
-
triggerTooltipQuery
public void triggerTooltipQuery()Triggers a tooltip query on the display of the widget. -
unmap
public void unmap()Causes a widget to be unmapped if it’s currently mapped.This function is only for use in widget implementations.
-
unparent
public void unparent()Removes this Widget from its parent.This function is only for use in widget implementations, typically in dispose.
-
unrealize
public void unrealize()Causes a widget to be unrealized.This frees all GDK resources associated with the widget.
This function is only useful in widget implementations.
-
unsetStateFlags
Turns off flag values for the current widget state.See
setStateFlags(java.util.Set<org.gnome.gtk.StateFlags>, boolean)
.This function is for use in widget implementations.
- Parameters:
flags
- state flags to turn off
-
unsetStateFlags
Turns off flag values for the current widget state.See
setStateFlags(java.util.Set<org.gnome.gtk.StateFlags>, boolean)
.This function is for use in widget implementations.
- Parameters:
flags
- state flags to turn off
-
computeExpand
Computes whether a container should give this widget extra space when possible. -
cssChanged
Vfunc called when the CSS used by widget was changed. Widgets should then discard their caches that depend on CSS and queue resizes or redraws accordingly. The default implementation will take care of this for all the default CSS properties, so implementations must chain up. -
directionChanged
Signal emitted when the text direction of a widget changes. -
focus
Vfunc for gtk_widget_child_focus() -
moveFocus
Signal emitted when a change of focus is requested -
queryTooltip
Signal emitted when “has-tooltip” istrue
and the hover timeout has expired with the cursor hovering “above” widget; or emitted when widget got focus in keyboard mode. -
root
protected void root()Called when the widget gets added to aGtkRoot
widget. Must chain up -
sizeAllocate
protected void sizeAllocate(int width, int height, int baseline) Called to set the allocation, if the widget does not have a layout manager. -
snapshot
Vfunc called when a new snapshot of the widget has to be taken. -
stateFlagsChanged
Signal emitted when the widget state changes, see gtk_widget_get_state_flags(). -
systemSettingChanged
Emitted when a system setting was changed. Must chain up. -
unroot
protected void unroot()Called when the widget is about to be removed from itsGtkRoot
widget. Must chain up -
onDestroy
Signals that all holders of a reference to the widget should release the reference that they hold.May result in finalization of the widget if all references are released.
This signal is not suitable for saving widget state.
- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitDestroy
public void emitDestroy()Emits the "destroy" signal. SeeonDestroy(org.gnome.gtk.Widget.DestroyCallback)
. -
onDirectionChanged
public SignalConnection<Widget.DirectionChangedCallback> onDirectionChanged(Widget.DirectionChangedCallback handler) Emitted when the text direction of a widget changes.- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitDirectionChanged
Emits the "direction-changed" signal. SeeonDirectionChanged(org.gnome.gtk.Widget.DirectionChangedCallback)
. -
onHide
Emitted whenwidget
is hidden.- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitHide
public void emitHide()Emits the "hide" signal. SeeonHide(org.gnome.gtk.Widget.HideCallback)
. -
onMap
Emitted whenwidget
is going to be mapped.A widget is mapped when the widget is visible (which is controlled with
Gtk.Widget:visible
) and all its parents up to the toplevel widget are also visible.The
::map
signal can be used to determine whether a widget will be drawn, for instance it can resume an animation that was stopped during the emission ofGtk.Widget::unmap
.- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitMap
public void emitMap()Emits the "map" signal. SeeonMap(org.gnome.gtk.Widget.MapCallback)
. -
onMnemonicActivate
public SignalConnection<Widget.MnemonicActivateCallback> onMnemonicActivate(Widget.MnemonicActivateCallback handler) Emitted when a widget is activated via a mnemonic.The default handler for this signal activates
widget
ifgroupCycling
is false, or just makeswidget
grab focus ifgroupCycling
is true.- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitMnemonicActivate
public boolean emitMnemonicActivate(boolean groupCycling) Emits the "mnemonic-activate" signal. SeeonMnemonicActivate(org.gnome.gtk.Widget.MnemonicActivateCallback)
. -
onMoveFocus
Emitted when the focus is moved.The
::move-focus
signal is a keybinding signal.The default bindings for this signal are
Tab
to move forward, andShift
+Tab
to move backward.- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitMoveFocus
Emits the "move-focus" signal. SeeonMoveFocus(org.gnome.gtk.Widget.MoveFocusCallback)
. -
onQueryTooltip
public SignalConnection<Widget.QueryTooltipCallback> onQueryTooltip(Widget.QueryTooltipCallback handler) Emitted when the widget’s tooltip is about to be shown.This happens when the
Gtk.Widget:has-tooltip
property is true and the hover timeout has expired with the cursor hovering abovewidget
; or emitted whenwidget
got focus in keyboard mode.Using the given coordinates, the signal handler should determine whether a tooltip should be shown for
widget
. If this is the case true should be returned, false otherwise. Note that ifkeyboardMode
is true, the values ofx
andy
are undefined and should not be used.The signal handler is free to manipulate
tooltip
with the therefore destined function calls.- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitQueryTooltip
Emits the "query-tooltip" signal. SeeonQueryTooltip(org.gnome.gtk.Widget.QueryTooltipCallback)
. -
onRealize
Emitted whenwidget
is associated with aGdkSurface
.This means that
realize()
has been called or the widget has been mapped (that is, it is going to be drawn).- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitRealize
public void emitRealize()Emits the "realize" signal. SeeonRealize(org.gnome.gtk.Widget.RealizeCallback)
. -
onShow
Emitted whenwidget
is shown.- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitShow
public void emitShow()Emits the "show" signal. SeeonShow(org.gnome.gtk.Widget.ShowCallback)
. -
onStateFlagsChanged
public SignalConnection<Widget.StateFlagsChangedCallback> onStateFlagsChanged(Widget.StateFlagsChangedCallback handler) Emitted when the widget state changes.See
getStateFlags()
.- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitStateFlagsChanged
Emits the "state-flags-changed" signal. SeeonStateFlagsChanged(org.gnome.gtk.Widget.StateFlagsChangedCallback)
. -
onUnmap
Emitted whenwidget
is going to be unmapped.A widget is unmapped when either it or any of its parents up to the toplevel widget have been set as hidden.
As
::unmap
indicates that a widget will not be shown any longer, it can be used to, for example, stop an animation on the widget.- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitUnmap
public void emitUnmap()Emits the "unmap" signal. SeeonUnmap(org.gnome.gtk.Widget.UnmapCallback)
. -
onUnrealize
Emitted when theGdkSurface
associated withwidget
is destroyed.This means that
unrealize()
has been called or the widget has been unmapped (that is, it is going to be hidden).- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitUnrealize
public void emitUnrealize()Emits the "unrealize" signal. SeeonUnrealize(org.gnome.gtk.Widget.UnrealizeCallback)
.
-
getBaseline()
instead