[gtk/layout-avoid-native] layout managers: Handle native children
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/layout-avoid-native] layout managers: Handle native children
- Date: Mon, 10 Jun 2019 18:05:39 +0000 (UTC)
commit 0c3740410e77425a9287d0500a64702e16c279e4
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Jun 10 18:01:59 2019 +0000
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.
gtk/gtkbinlayout.c | 4 +--
gtk/gtkboxlayout.c | 69 +++++++++++++-------------------------------------
gtk/gtkfixedlayout.c | 4 +--
gtk/gtkgridlayout.c | 10 ++++----
gtk/gtklayoutmanager.c | 41 ++++++++++++++++++++++++++++++
gtk/gtklayoutmanager.h | 2 ++
gtk/gtkoverlaylayout.c | 5 +++-
7 files changed, 74 insertions(+), 61 deletions(-)
---
diff --git a/gtk/gtkbinlayout.c b/gtk/gtkbinlayout.c
index cbc3510892..627e1cd483 100644
--- a/gtk/gtkbinlayout.c
+++ b/gtk/gtkbinlayout.c
@@ -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_layout_manager_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_layout_manager_should_layout (child))
gtk_widget_allocate (child, width, height, baseline, NULL);
}
}
diff --git a/gtk/gtkboxlayout.c b/gtk/gtkboxlayout.c
index 98d87701eb..86b23b3ffa 100644
--- a/gtk/gtkboxlayout.c
+++ b/gtk/gtkboxlayout.c
@@ -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_layout_manager_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_layout_manager_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_layout_manager_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);
-
- children_minimum_size += sizes[i].minimum_size;
- i += 1;
- }
+ 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;
}
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_layout_manager_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_layout_manager_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_layout_manager_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_layout_manager_should_layout (child))
continue;
child_size = sizes[i].natural_size;
diff --git a/gtk/gtkfixedlayout.c b/gtk/gtkfixedlayout.c
index 77e923add0..dbb14c542a 100644
--- a/gtk/gtkfixedlayout.c
+++ b/gtk/gtkfixedlayout.c
@@ -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_layout_manager_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_layout_manager_should_layout (child))
continue;
child_info = GTK_FIXED_LAYOUT_CHILD (gtk_layout_manager_get_layout_child (layout_manager, child));
diff --git a/gtk/gtkgridlayout.c b/gtk/gtkgridlayout.c
index aa7bc69ed1..e8f7104015 100644
--- a/gtk/gtkgridlayout.c
+++ b/gtk/gtkgridlayout.c
@@ -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_layout_manager_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_layout_manager_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_layout_manager_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_layout_manager_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_layout_manager_should_layout (child))
continue;
allocate_child (request, GTK_ORIENTATION_HORIZONTAL, child, grid_child, &x, &width, &ignore);
diff --git a/gtk/gtklayoutmanager.c b/gtk/gtklayoutmanager.c
index 1325c339ba..36548a32d8 100644
--- a/gtk/gtklayoutmanager.c
+++ b/gtk/gtklayoutmanager.c
@@ -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);
@@ -477,3 +494,27 @@ gtk_layout_manager_get_layout_child (GtkLayoutManager *manager,
return res;
}
+
+/**
+ * gtk_layout_manager_should_layout:
+ * @child: a child of @manager's widget
+ *
+ * Returns whether @child should be included
+ * in measuring and allocating. 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_layout_manager_should_layout (GtkWidget *child)
+{
+ if (!_gtk_widget_get_visible (child))
+ return FALSE;
+
+ if (GTK_IS_NATIVE (child))
+ return FALSE;
+
+ return TRUE;
+}
diff --git a/gtk/gtklayoutmanager.h b/gtk/gtklayoutmanager.h
index 06659ee70e..1a0e07f3d6 100644
--- a/gtk/gtklayoutmanager.h
+++ b/gtk/gtklayoutmanager.h
@@ -108,5 +108,7 @@ void gtk_layout_manager_layout_changed (GtkLayoutManage
GDK_AVAILABLE_IN_ALL
GtkLayoutChild * gtk_layout_manager_get_layout_child (GtkLayoutManager *manager,
GtkWidget *child);
+GDK_AVAILABLE_IN_ALL
+gboolean gtk_layout_manager_should_layout (GtkWidget *child);
G_END_DECLS
diff --git a/gtk/gtkoverlaylayout.c b/gtk/gtkoverlaylayout.c
index 4fa4f12dd8..5b55e3a16c 100644
--- a/gtk/gtkoverlaylayout.c
+++ b/gtk/gtkoverlaylayout.c
@@ -252,6 +252,9 @@ gtk_overlay_layout_measure (GtkLayoutManager *layout_manager,
child != NULL;
child = _gtk_widget_get_next_sibling (child))
{
+ if (!gtk_layout_manager_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_layout_manager_should_layout (widget))
return;
gtk_overlay_compute_child_allocation (overlay, widget, child, &child_allocation);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]