Class LayoutManager
- All Implemented Interfaces:
Proxy
- Direct Known Subclasses:
BinLayout
,BoxLayout
,CenterLayout
,ClampLayout
,ConstraintLayout
,FixedLayout
,GridLayout
,LayoutManager.LayoutManagerImpl
,OverlayLayout
You typically subclass GtkLayoutManager
if you want to implement a
layout policy for the children of a widget, or if you want to determine
the size of a widget depending on its contents.
Each GtkWidget
can only have a GtkLayoutManager
instance associated
to it at any given time; it is possible, though, to replace the layout
manager instance using Widget.setLayoutManager(org.gnome.gtk.LayoutManager)
.
Layout properties
A layout manager can expose properties for controlling the layout of
each child, by creating an object type derived from LayoutChild
and installing the properties on it as normal GObject
properties.
Each GtkLayoutChild
instance storing the layout properties for a
specific child is created through the getLayoutChild(org.gnome.gtk.Widget)
method; a GtkLayoutManager
controls the creation of its GtkLayoutChild
instances by overriding the GtkLayoutManagerClass.create_layout_child()
virtual function. The typical implementation should look like:
static GtkLayoutChild *
create_layout_child (GtkLayoutManager *manager,
GtkWidget *container,
GtkWidget *child)
{
return g_object_new (your_layout_child_get_type (),
"layout-manager", manager,
"child-widget", child,
NULL);
}
The Gtk.LayoutChild:layout-manager
and
Gtk.LayoutChild:child-widget
properties
on the newly created GtkLayoutChild
instance are mandatory. The
GtkLayoutManager
will cache the newly created GtkLayoutChild
instance
until the widget is removed from its parent, or the parent removes the
layout manager.
Each GtkLayoutManager
instance creating a GtkLayoutChild
should use
getLayoutChild(org.gnome.gtk.Widget)
every time it needs to query
the layout properties; each GtkLayoutChild
instance should call
layoutChanged()
every time a property is
updated, in order to queue a new size measuring and allocation.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
LayoutManager.Builder<B extends LayoutManager.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.static class
TheGtkLayoutManagerClass
structure contains only private data, and should only be accessed through the provided API, or when subclassingGtkLayoutManager
.static class
The LayoutManagerImpl type represents a native instance of the abstract LayoutManager class.Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
-
Constructor Summary
ConstructorDescriptionLayoutManager
(MemorySegment address) Create a LayoutManager proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Assigns the givenwidth
,height
, andbaseline
to awidget
, and computes the position and sizes of the children of thewidget
using the layout management policy of this LayoutManager.protected LayoutManager
asParent()
Returns this instance as if it were its parent type.static LayoutManager.Builder
<? extends LayoutManager.Builder> builder()
ALayoutManager.Builder
object constructs aLayoutManager
with the specified properties.protected LayoutChild
createLayoutChild
(Widget widget, Widget forChild) Create aGtkLayoutChild
instance for the givenforChild
widget.getLayoutChild
(Widget child) Retrieves aGtkLayoutChild
instance for theGtkLayoutManager
, creating one if necessary.static MemoryLayout
The memory layout of the native struct.Retrieves the request mode of this LayoutManager.protected SizeRequestMode
getRequestMode
(Widget widget) a virtual function, used to return the preferred request mode for the layout manager; for instance, "width for height" or "height for width"; seeGtkSizeRequestMode
static Type
getType()
Get the GType of the LayoutManager classRetrieves theGtkWidget
using the givenGtkLayoutManager
.void
Queues a resize on theGtkWidget
using this LayoutManager, if any.void
measure
(Widget widget, Orientation orientation, int forSize, @Nullable Out<Integer> minimum, @Nullable Out<Integer> natural, @Nullable Out<Integer> minimumBaseline, @Nullable Out<Integer> naturalBaseline) Measures the size of thewidget
using this LayoutManager, for the givenorientation
and size.protected void
root()
a virtual function, called when the widget using the layout manager is attached to aGtkRoot
protected void
unroot()
a virtual function, called when the widget using the layout manager is detached from aGtkRoot
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, 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
-
Constructor Details
-
LayoutManager
Create a LayoutManager proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
-
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. -
allocate
Assigns the givenwidth
,height
, andbaseline
to awidget
, and computes the position and sizes of the children of thewidget
using the layout management policy of this LayoutManager.- Parameters:
widget
- theGtkWidget
using this LayoutManagerwidth
- the new width of thewidget
height
- the new height of thewidget
baseline
- the baseline position of thewidget
, or -1
-
getLayoutChild
Retrieves aGtkLayoutChild
instance for theGtkLayoutManager
, creating one if necessary.The
child
widget must be a child of the widget using this LayoutManager.The
GtkLayoutChild
instance is owned by theGtkLayoutManager
, and is guaranteed to exist as long aschild
is a child of theGtkWidget
using the givenGtkLayoutManager
.- Parameters:
child
- aGtkWidget
- Returns:
- a
GtkLayoutChild
-
getRequestMode
Retrieves the request mode of this LayoutManager.- Returns:
- a
GtkSizeRequestMode
-
getWidget
Retrieves theGtkWidget
using the givenGtkLayoutManager
.- Returns:
- a
GtkWidget
-
layoutChanged
public void layoutChanged()Queues a resize on theGtkWidget
using this LayoutManager, if any.This function should be called by subclasses of
GtkLayoutManager
in response to changes to their layout management policies. -
measure
public void measure(Widget widget, 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 the size of thewidget
using this LayoutManager, for the givenorientation
and size.See the
Widget
documentation on layout management for more details.- Parameters:
widget
- theGtkWidget
using this LayoutManagerorientation
- the orientation to measureforSize
- Size for the opposite oforientation
; for instance, if theorientation
isOrientation.HORIZONTAL
, this is the height of the widget; if theorientation
isOrientation.VERTICAL
, this is the width of the widget. This allows to measure the height for the given width, and the width for the given height. Use -1 if the size is not knownminimum
- the minimum size for the given size and orientationnatural
- the natural, or preferred size for the given size and orientationminimumBaseline
- the baseline position for the minimum sizenaturalBaseline
- the baseline position for the natural size
-
createLayoutChild
Create aGtkLayoutChild
instance for the givenforChild
widget.- Parameters:
widget
- the widget using the this LayoutManagerforChild
- the child ofwidget
- Returns:
- a
GtkLayoutChild
-
getRequestMode
a virtual function, used to return the preferred request mode for the layout manager; for instance, "width for height" or "height for width"; seeGtkSizeRequestMode
-
root
protected void root()a virtual function, called when the widget using the layout manager is attached to aGtkRoot
-
unroot
protected void unroot()a virtual function, called when the widget using the layout manager is detached from aGtkRoot
-
builder
ALayoutManager.Builder
object constructs aLayoutManager
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withLayoutManager.Builder.build()
.
-