summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2022-07-03 06:31:47 +0200
committerBenjamin Otte <otte@redhat.com>2022-07-05 07:37:56 +0200
commiteaa9fddfb0d4f421ccb6afe89d206dd8fdd52e9d (patch)
treebff443c2acc69117a94e112a2f442925dcf953eb
parente848ead629fa52d47815d09905cbbaa98885ee86 (diff)
downloadgtk+-eaa9fddfb0d4f421ccb6afe89d206dd8fdd52e9d.tar.gz
canvas: Change the way boxes work
Instead of normalized rectangles, make eval() return unnormalized ones. This means that we need to normalize before allocating - but it also means we can scale(-1) the widget if we want to. That is not implemented yet, but we can.
-rw-r--r--gtk/gtkcanvas.c35
-rw-r--r--gtk/gtkcanvasbox.c9
-rw-r--r--gtk/gtkcanvasitem.c34
-rw-r--r--gtk/gtkcanvasitemprivate.h6
4 files changed, 48 insertions, 36 deletions
diff --git a/gtk/gtkcanvas.c b/gtk/gtkcanvas.c
index 33a8a4973d..b85b7a4c48 100644
--- a/gtk/gtkcanvas.c
+++ b/gtk/gtkcanvas.c
@@ -261,7 +261,7 @@ gtk_canvas_allocate (GtkWidget *widget,
graphene_rect_t rect;
int x, y, w, h;
- if (child == NULL || gtk_canvas_item_has_allocation (ci, NULL))
+ if (child == NULL || gtk_canvas_item_has_allocation (ci))
continue;
bounds = gtk_canvas_item_get_bounds (ci);
@@ -282,24 +282,28 @@ gtk_canvas_allocate (GtkWidget *widget,
if (gtk_widget_get_request_mode (child) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH)
{
gtk_widget_measure (child, GTK_ORIENTATION_HORIZONTAL, -1, &w, NULL, NULL, NULL);
- w = MAX (w, ceil (rect.size.width));
+ w = MAX (w, ceil (ABS (rect.size.width)));
gtk_widget_measure (child, GTK_ORIENTATION_VERTICAL, w, &h, NULL, NULL, NULL);
- h = MAX (h, ceil (rect.size.height));
+ h = MAX (h, ceil (ABS (rect.size.height)));
}
else
{
gtk_widget_measure (child, GTK_ORIENTATION_VERTICAL, -1, &h, NULL, NULL, NULL);
- h = MAX (h, ceil (rect.size.height));
+ h = MAX (h, ceil (ABS (rect.size.height)));
gtk_widget_measure (child, GTK_ORIENTATION_HORIZONTAL, h, &w, NULL, NULL, NULL);
- w = MAX (w, ceil (rect.size.width));
+ w = MAX (w, ceil (ABS (rect.size.width)));
}
+ if (rect.size.width < 0)
+ w = -w;
+ if (rect.size.height < 0)
+ h = -h;
gtk_canvas_box_get_origin (bounds, &origin_x, &origin_y);
- if (w > rect.size.width)
+ if (ABS (w) > ABS (rect.size.width))
x = round (rect.origin.x + origin_x * (rect.size.width - w));
else
x = round (rect.origin.x);
- if (h > rect.size.height)
+ if (ABS (h) > ABS (rect.size.height))
y = round (rect.origin.y + origin_y * (rect.size.height - h));
else
y = round (rect.origin.y);
@@ -319,23 +323,8 @@ gtk_canvas_allocate (GtkWidget *widget,
for (i = 0; i < gtk_canvas_items_get_size (&self->items); i++)
{
GtkCanvasItem *ci = gtk_canvas_items_get (&self->items, i);
- GtkWidget *child = gtk_canvas_item_get_widget (ci);
- graphene_rect_t allocation;
- if (child == NULL)
- continue;
-
- if (!gtk_canvas_item_has_allocation (ci, &allocation))
- {
- g_assert_not_reached ();
- }
- gtk_widget_size_allocate (child,
- &(GtkAllocation) {
- allocation.origin.x,
- allocation.origin.y,
- allocation.size.width,
- allocation.size.height
- }, -1);
+ gtk_canvas_item_allocate_widget (ci, 0, 0);
}
}
diff --git a/gtk/gtkcanvasbox.c b/gtk/gtkcanvasbox.c
index 774be46110..715985ee31 100644
--- a/gtk/gtkcanvasbox.c
+++ b/gtk/gtkcanvasbox.c
@@ -191,11 +191,10 @@ gtk_canvas_box_eval (const GtkCanvasBox *self,
graphene_vec2_multiply (&self->origin, &size, &tmp);
graphene_vec2_subtract (&point, &tmp, &point);
- graphene_rect_init (rect,
- graphene_vec2_get_x (&point),
- graphene_vec2_get_y (&point),
- graphene_vec2_get_x (&size),
- graphene_vec2_get_y (&size));
+ *rect = GRAPHENE_RECT_INIT (graphene_vec2_get_x (&point),
+ graphene_vec2_get_y (&point),
+ graphene_vec2_get_x (&size),
+ graphene_vec2_get_y (&size));
return TRUE;
}
diff --git a/gtk/gtkcanvasitem.c b/gtk/gtkcanvasitem.c
index d911c66095..7272ca38dd 100644
--- a/gtk/gtkcanvasitem.c
+++ b/gtk/gtkcanvasitem.c
@@ -292,14 +292,36 @@ gtk_canvas_item_allocate (GtkCanvasItem *self,
graphene_vec2_init_from_vec2 (&self->allocation_var.origin, &self->bounds.origin);
}
-gboolean
-gtk_canvas_item_has_allocation (GtkCanvasItem *self,
- graphene_rect_t *rect)
+void
+gtk_canvas_item_allocate_widget (GtkCanvasItem *self,
+ float dx,
+ float dy)
{
- if (rect == NULL)
- return !gtk_canvas_vec2_is_invalid (gtk_canvas_vec2_get_variable (&self->allocation_var.point));
+ graphene_rect_t allocation;
+
+ if (self->widget == NULL)
+ return;
+
+ if (!gtk_canvas_box_eval (&self->allocation_var, &allocation))
+ {
+ /* gtkcanvas.c will not call this function otherwise */
+ g_assert_not_reached ();
+ }
+
+ graphene_rect_normalize (&allocation);
+ gtk_widget_size_allocate (self->widget,
+ &(GtkAllocation) {
+ allocation.origin.x - dx,
+ allocation.origin.y - dy,
+ allocation.size.width,
+ allocation.size.height
+ }, -1);
+}
- return gtk_canvas_box_eval (&self->allocation_var, rect);
+gboolean
+gtk_canvas_item_has_allocation (GtkCanvasItem *self)
+{
+ return !gtk_canvas_vec2_is_invalid (gtk_canvas_vec2_get_variable (&self->allocation_var.point));
}
const GtkCanvasVec2 *
diff --git a/gtk/gtkcanvasitemprivate.h b/gtk/gtkcanvasitemprivate.h
index d50c68a569..b829b02c13 100644
--- a/gtk/gtkcanvasitemprivate.h
+++ b/gtk/gtkcanvasitemprivate.h
@@ -14,8 +14,10 @@ GtkCanvasItem * gtk_canvas_item_new (GtkCanvas
void gtk_canvas_item_validate_variables (GtkCanvasItem *self);
void gtk_canvas_item_allocate (GtkCanvasItem *self,
graphene_rect_t *rect);
-gboolean gtk_canvas_item_has_allocation (GtkCanvasItem *self,
- graphene_rect_t *rect);
+void gtk_canvas_item_allocate_widget (GtkCanvasItem *self,
+ float dx,
+ float dy);
+gboolean gtk_canvas_item_has_allocation (GtkCanvasItem *self);
const GtkCanvasVec2 * gtk_canvas_item_get_measure_vec2 (GtkCanvasItem *self,
GtkCanvasItemMeasurement measure);