Class LayoutManager
- All Implemented Interfaces:
Proxy
- Direct Known Subclasses:
BinLayout,BoxLayout,CenterLayout,ClampLayout,ConstraintLayout,FixedLayout,GridLayout,LayoutManager.LayoutManager$Impl,OverlayLayout,WrapLayout
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
Nested ClassesModifier and TypeClassDescriptionstatic classLayoutManager.Builder<B extends LayoutManager.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.static classThe LayoutManager$Impl type represents a native instance of the abstract LayoutManager class.static classTheGtkLayoutManagerClassstructure contains only private data, and should only be accessed through the provided API, or when subclassingGtkLayoutManager.Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new LayoutManager.LayoutManager(MemorySegment address) Create a LayoutManager proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionvoidAssigns the givenwidth,height,andbaselineto awidget,and computes the position and sizes of the children of thewidgetusing the layout management policy ofmanager.protected LayoutManagerasParent()Returns this instance as if it were its parent type.protected LayoutChildcreateLayoutChild(Widget widget, Widget forChild) Create aGtkLayoutChildinstance for the givenforChildwidget.getLayoutChild(Widget child) Retrieves aGtkLayoutChildinstance for theGtkLayoutManager, creating one if necessary.static MemoryLayoutThe memory layout of the native struct.Retrieves the request mode ofmanager.protected SizeRequestModegetRequestMode(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"; seeGtkSizeRequestModestatic @Nullable TypegetType()Get the GType of the LayoutManager class@Nullable WidgetRetrieves theGtkWidgetusing the givenGtkLayoutManager.voidQueues a resize on theGtkWidgetusingmanager,if any.voidmeasure(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 thewidgetusingmanager,for the givenorientationand size.protected voidroot()a virtual function, called when the widget using the layout manager is attached to aGtkRootprotected voidunroot()a virtual function, called when the widget using the layout manager is detached from aGtkRootMethods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, builder, 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, withPropertiesMethods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class org.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
-
LayoutManager
public LayoutManager()Creates a new LayoutManager.
-
-
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 Javasuperkeyword, 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,andbaselineto awidget,and computes the position and sizes of the children of thewidgetusing the layout management policy ofmanager.- Parameters:
widget- theGtkWidgetusing this LayoutManagerwidth- the new width of thewidgetheight- the new height of thewidgetbaseline- the baseline position of thewidget,or -1
-
getLayoutChild
Retrieves aGtkLayoutChildinstance for theGtkLayoutManager, creating one if necessary.The
childwidget must be a child of the widget usingmanager.The
GtkLayoutChildinstance is owned by theGtkLayoutManager, and is guaranteed to exist as long aschildis a child of theGtkWidgetusing the givenGtkLayoutManager.- Parameters:
child- aGtkWidget- Returns:
- a
GtkLayoutChild
-
getRequestMode
Retrieves the request mode ofmanager.- Returns:
- a
GtkSizeRequestMode
-
getWidget
Retrieves theGtkWidgetusing the givenGtkLayoutManager.- Returns:
- a
GtkWidget
-
layoutChanged
public void layoutChanged()Queues a resize on theGtkWidgetusingmanager,if any.This function should be called by subclasses of
GtkLayoutManagerin response to changes to their layout management policies. -
measure
public 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 thewidgetusingmanager,for the givenorientationand size.See the
Widgetdocumentation on layout management for more details.- Parameters:
widget- theGtkWidgetusing this LayoutManagerorientation- the orientation to measureforSize- Size for the opposite oforientation;for instance, if theorientationisOrientation.HORIZONTAL, this is the height of the widget; if theorientationisOrientation.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 aGtkLayoutChildinstance for the givenforChildwidget.- 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
-