Top | ![]() |
![]() |
![]() |
![]() |
GObject ╰── GtkLayoutManager ├── GtkBinLayout ├── GtkBoxLayout ├── GtkConstraintLayout ├── GtkFixedLayout ├── GtkGridLayout ╰── GtkCenterLayout
Layout managers are delegate classes that handle the preferred size and the allocation of a container widget.
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 gtk_widget_set_layout_manager()
.
A layout manager can expose properties for controlling the layout of each child, by creating an object type derived from GtkLayoutChild 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 gtk_layout_manager_get_layout_child()
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:
1 2 3 4 5 6 7 8 9 10 |
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 “layout-manager” and “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
gtk_layout_manager_get_layout_child()
every time it needs to query the
layout properties; each GtkLayoutChild instance should call
gtk_layout_manager_layout_changed()
every time a property is updated, in
order to queue a new size measuring and allocation.
void gtk_layout_manager_measure (GtkLayoutManager *manager
,GtkWidget *widget
,GtkOrientation orientation
,int for_size
,int *minimum
,int *natural
,int *minimum_baseline
,int *natural_baseline
);
Measures the size of the widget
using manager
, for the
given orientation
and size.
See GtkWidget's geometry management section for more details.
manager |
||
widget |
the GtkWidget using |
|
orientation |
the orientation to measure |
|
for_size |
Size for the opposite of |
|
minimum |
the minimum size for the given size and orientation. |
[out][optional] |
natural |
the natural, or preferred size for the given size and orientation. |
[out][optional] |
minimum_baseline |
the baseline position for the minimum size. |
[out][optional] |
natural_baseline |
the baseline position for the natural size. |
[out][optional] |
void gtk_layout_manager_allocate (GtkLayoutManager *manager
,GtkWidget *widget
,int width
,int height
,int baseline
);
This function assigns the given width
, height
, and baseline
to
a widget
, and computes the position and sizes of the children of
the widget
using the layout management policy of manager
.
manager |
||
widget |
the GtkWidget using |
|
width |
the new width of the |
|
height |
the new height of the |
|
baseline |
the baseline position of the |
GtkSizeRequestMode
gtk_layout_manager_get_request_mode (GtkLayoutManager *manager
);
Retrieves the request mode of manager
.
GtkWidget *
gtk_layout_manager_get_widget (GtkLayoutManager *manager
);
Retrieves the GtkWidget using the given GtkLayoutManager.
GtkLayoutChild * gtk_layout_manager_get_layout_child (GtkLayoutManager *manager
,GtkWidget *child
);
Retrieves a GtkLayoutChild instance for the GtkLayoutManager, creating one if necessary.
The child
widget must be a child of the widget using manager
.
The GtkLayoutChild instance is owned by the GtkLayoutManager, and is
guaranteed to exist as long as child
is a child of the GtkWidget using
the given GtkLayoutManager.
void
gtk_layout_manager_layout_changed (GtkLayoutManager *manager
);
Queues a resize on the GtkWidget using manager
, if any.
This function should be called by subclasses of GtkLayoutManager in response to changes to their layout management policies.