layout managers: Handle native children

Add a convenience api to skip children
that should not be included in the layout,
and call gtk_native_check_resize on all
native children outside of the vfunc.
This commit is contained in:
Matthias Clasen 2019-06-10 18:01:59 +00:00
parent f03c7c379a
commit 21a5c7f0eb
9 changed files with 76 additions and 60 deletions

View File

@ -4552,6 +4552,7 @@ gtk_widget_insert_before
gtk_widget_insert_after
gtk_widget_set_layout_manager
gtk_widget_get_layout_manager
gtk_widget_should_layout
<SUBSECTION>
gtk_widget_get_path

View File

@ -57,7 +57,7 @@ gtk_bin_layout_measure (GtkLayoutManager *layout_manager,
child != NULL;
child = _gtk_widget_get_next_sibling (child))
{
if (gtk_widget_get_visible (child))
if (gtk_widget_should_layout (child))
{
int child_min = 0;
int child_nat = 0;
@ -92,7 +92,7 @@ gtk_bin_layout_allocate (GtkLayoutManager *layout_manager,
child != NULL;
child = _gtk_widget_get_next_sibling (child))
{
if (child && gtk_widget_get_visible (child))
if (child && gtk_widget_should_layout (child))
gtk_widget_allocate (child, width, height, baseline, NULL);
}
}

View File

@ -174,16 +174,13 @@ count_expand_children (GtkWidget *widget,
child != NULL;
child = _gtk_widget_get_next_sibling (child))
{
if (GTK_IS_NATIVE (child))
if (!gtk_widget_should_layout (child))
continue;
if (_gtk_widget_get_visible (child))
{
*visible_children += 1;
*visible_children += 1;
if (gtk_widget_compute_expand (child, orientation))
*expand_children += 1;
}
if (gtk_widget_compute_expand (child, orientation))
*expand_children += 1;
}
}
@ -223,10 +220,7 @@ gtk_box_layout_compute_size (GtkBoxLayout *self,
int child_min = 0;
int child_nat = 0;
if (GTK_IS_NATIVE (child))
continue;
if (!_gtk_widget_get_visible (child))
if (!gtk_widget_should_layout (child))
continue;
gtk_widget_measure (child, self->orientation,
@ -300,20 +294,17 @@ gtk_box_layout_compute_opposite_size (GtkBoxLayout *self,
child != NULL;
child = _gtk_widget_get_next_sibling (child))
{
if (GTK_IS_NATIVE (child))
if (!gtk_widget_should_layout (child))
continue;
if (_gtk_widget_get_visible (child))
{
gtk_widget_measure (child,
self->orientation,
-1,
&sizes[i].minimum_size, &sizes[i].natural_size,
NULL, NULL);
gtk_widget_measure (child,
self->orientation,
-1,
&sizes[i].minimum_size, &sizes[i].natural_size,
NULL, NULL);
children_minimum_size += sizes[i].minimum_size;
i += 1;
}
children_minimum_size += sizes[i].minimum_size;
i += 1;
}
if (self->homogeneous)
@ -351,11 +342,7 @@ gtk_box_layout_compute_opposite_size (GtkBoxLayout *self,
child != NULL;
child = _gtk_widget_get_next_sibling (child))
{
if (GTK_IS_NATIVE (child))
continue;
/* If widget is not visible, skip it. */
if (!_gtk_widget_get_visible (child))
if (!gtk_widget_should_layout (child))
continue;
/* Assign the child's size. */
@ -494,15 +481,6 @@ gtk_box_layout_allocate (GtkLayoutManager *layout_manager,
gint child_size;
gint spacing;
/* Handle native children first, and skip them in everything below */
for (child = _gtk_widget_get_first_child (widget);
child != NULL;
child = _gtk_widget_get_next_sibling (child))
{
if (GTK_IS_NATIVE (child))
gtk_native_check_resize (GTK_NATIVE (child));
}
count_expand_children (widget, self->orientation, &nvis_children, &nexpand_children);
/* If there is no visible child, simply return. */
@ -527,10 +505,7 @@ gtk_box_layout_allocate (GtkLayoutManager *layout_manager,
child != NULL;
child = _gtk_widget_get_next_sibling (child))
{
if (GTK_IS_NATIVE (child))
continue;
if (!_gtk_widget_get_visible (child))
if (!gtk_widget_should_layout (child))
continue;
gtk_widget_measure (child,
@ -581,11 +556,7 @@ gtk_box_layout_allocate (GtkLayoutManager *layout_manager,
child != NULL;
child = _gtk_widget_get_next_sibling (child))
{
if (GTK_IS_NATIVE (child))
continue;
/* If widget is not visible, skip it. */
if (!_gtk_widget_get_visible (child))
if (!gtk_widget_should_layout (child))
continue;
/* Assign the child's size. */
@ -689,11 +660,7 @@ gtk_box_layout_allocate (GtkLayoutManager *layout_manager,
child != NULL;
child = _gtk_widget_get_next_sibling (child))
{
if (GTK_IS_NATIVE (child))
continue;
/* If widget is not visible, skip it. */
if (!_gtk_widget_get_visible (child))
if (!gtk_widget_should_layout (child))
continue;
child_size = sizes[i].natural_size;

View File

@ -238,7 +238,7 @@ gtk_fixed_layout_measure (GtkLayoutManager *layout_manager,
int child_min_opp = 0, child_nat_opp = 0;
graphene_rect_t min_rect, nat_rect;
if (!gtk_widget_get_visible (child))
if (!gtk_widget_should_layout (child))
continue;
child_info = GTK_FIXED_LAYOUT_CHILD (gtk_layout_manager_get_layout_child (layout_manager, child));
@ -291,7 +291,7 @@ gtk_fixed_layout_allocate (GtkLayoutManager *layout_manager,
{
GtkRequisition child_req;
if (!gtk_widget_get_visible (child))
if (!gtk_widget_should_layout (child))
continue;
child_info = GTK_FIXED_LAYOUT_CHILD (gtk_layout_manager_get_layout_child (layout_manager, child));

View File

@ -640,7 +640,7 @@ grid_request_non_spanning (GridRequest *request,
GtkGridLayoutChild *grid_child = get_grid_child (request->layout, child);
GridChildAttach *attach;
if (!_gtk_widget_get_visible (child))
if (!gtk_widget_should_layout (child))
continue;
attach = &grid_child->attach[orientation];
@ -778,7 +778,7 @@ grid_request_spanning (GridRequest *request,
{
GtkGridLayoutChild *grid_child = get_grid_child (request->layout, child);
if (!_gtk_widget_get_visible (child))
if (!gtk_widget_should_layout (child))
continue;
attach = &grid_child->attach[orientation];
@ -917,7 +917,7 @@ grid_request_compute_expand (GridRequest *request,
{
GtkGridLayoutChild *grid_child = get_grid_child (request->layout, child);
if (!_gtk_widget_get_visible (child))
if (!gtk_widget_should_layout (child))
continue;
attach = &grid_child->attach[orientation];
@ -939,7 +939,7 @@ grid_request_compute_expand (GridRequest *request,
{
GtkGridLayoutChild *grid_child = get_grid_child (request->layout, child);
if (!_gtk_widget_get_visible (child))
if (!gtk_widget_should_layout (child))
continue;
attach = &grid_child->attach[orientation];
@ -1497,7 +1497,7 @@ grid_request_allocate_children (GridRequest *request,
{
GtkGridLayoutChild *grid_child = get_grid_child (request->layout, child);
if (!_gtk_widget_get_visible (child))
if (!gtk_widget_should_layout (child))
continue;
allocate_child (request, GTK_ORIENTATION_HORIZONTAL, child, grid_child, &x, &width, &ignore);

View File

@ -76,6 +76,7 @@
#include "gtklayoutmanagerprivate.h"
#include "gtklayoutchild.h"
#include "gtkwidgetprivate.h"
#include "gtknative.h"
#ifdef G_ENABLE_DEBUG
#define LAYOUT_MANAGER_WARN_NOT_IMPLEMENTED(m,method) G_STMT_START { \
@ -293,6 +294,20 @@ gtk_layout_manager_measure (GtkLayoutManager *manager,
*natural_baseline = nat_baseline;
}
static void
allocate_native_children (GtkWidget *widget)
{
GtkWidget *child;
for (child = _gtk_widget_get_first_child (widget);
child != NULL;
child = _gtk_widget_get_next_sibling (child))
{
if (GTK_IS_NATIVE (child))
gtk_native_check_resize (GTK_NATIVE (child));
}
}
/**
* gtk_layout_manager_allocate:
* @manager: a #GtkLayoutManager
@ -318,6 +333,8 @@ gtk_layout_manager_allocate (GtkLayoutManager *manager,
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (baseline >= -1);
allocate_native_children (widget);
klass = GTK_LAYOUT_MANAGER_GET_CLASS (manager);
klass->allocate (manager, widget, width, height, baseline);

View File

@ -252,6 +252,9 @@ gtk_overlay_layout_measure (GtkLayoutManager *layout_manager,
child != NULL;
child = _gtk_widget_get_next_sibling (child))
{
if (!gtk_widget_should_layout (child))
continue;
child_info = GTK_OVERLAY_LAYOUT_CHILD (gtk_layout_manager_get_layout_child (layout_manager, child));
if (child == main_widget || child_info->measure)
@ -376,7 +379,7 @@ gtk_overlay_child_allocate (GtkOverlay *overlay,
{
GtkAllocation child_allocation;
if (!gtk_widget_get_visible (widget))
if (!gtk_widget_should_layout (widget))
return;
gtk_overlay_compute_child_allocation (overlay, widget, child, &child_allocation);

View File

@ -13454,3 +13454,28 @@ gtk_widget_get_layout_manager (GtkWidget *widget)
return priv->layout_manager;
}
/**
* gtk_widget_should_layout:
* @widget: a widget
*
* Returns whether @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.
*
* Returns: %TRUE if child should be included in
* measuring and allocating
*/
gboolean
gtk_widget_should_layout (GtkWidget *widget)
{
if (!_gtk_widget_get_visible (widget))
return FALSE;
if (GTK_IS_NATIVE (widget))
return FALSE;
return TRUE;
}

View File

@ -1026,6 +1026,9 @@ GDK_AVAILABLE_IN_ALL
void gtk_widget_snapshot_child (GtkWidget *widget,
GtkWidget *child,
GtkSnapshot *snapshot);
GDK_AVAILABLE_IN_ALL
gboolean gtk_widget_should_layout (GtkWidget *widget);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkWidget, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkRequisition, gtk_requisition_free)