Why creating a GtkLayoutManager?

In some of my widgets I use a custom layout manager. Its function is only that of providing the three functions GtkLayoutManagerClass.get_request_mode(), GtkLayoutManagerClass.measure() and GtkLayoutManagerClass.allocate().

When I did it, I wrote a custom layout manager because I emulated what GTK does in many of its widgets. The same result however should be reachable using GtkWidgetClass.get_request_mode(), GtkWidgetClass.measure() and GtkWidgetClass.size_allocate().

If that is the case, why should a developer create a custom layout manager instead of using the default one?

And, more specifically, should I create a custom layout manager if I need only the three functions above?

Layout managers are delegate objects: GtkWidget delegates the layout logic to an ancillary object to contain the complexity somewhere else.

Additionally, GtkLayoutManager allows you to add things like layout properties; those properties apply only to a specific (widget, layout manager, child) tuple, so they can be set using UI definition files.

What does “using the default one” mean? You mean “using the GtkWidget virtual functions”? GTK checks if there’s a layout manager instance associated to a widget, and if there is, then the layout manager takes precedence over the virtual functions inside GtkWidget.

Thank you, Emmanuele.

I still don’t know if I should keep the custom layout manager or I should use instead GtkWidgetClass.get_request_mode(), GtkWidgetClass.measure() and GtkWidgetClass.size_allocate(). My layout manager does not use its own properties, and really it does nothing else other than providing the three functions above.

I will keep it for now. Time will tell.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.