diff options
author | Matthias Clasen <mclasen@redhat.com> | 2023-04-29 14:10:53 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2023-04-29 14:30:21 -0400 |
commit | 5b6f8d70021508a88efe9918de8a98226ec5bc0b (patch) | |
tree | 4f25c6e3766666cc5156bfa5c95abd692849dbbd | |
parent | 71a752490a9fe607db954d2f4b803dbfd0c85b68 (diff) | |
download | gtk+-5b6f8d70021508a88efe9918de8a98226ec5bc0b.tar.gz |
gtk4-demo: Stop using gtk_widget_get_allocated_size
-rw-r--r-- | demos/gtk-demo/dnd.c | 14 | ||||
-rw-r--r-- | demos/gtk-demo/fontplane.c | 12 | ||||
-rw-r--r-- | demos/gtk-demo/suggestionentry.c | 2 |
3 files changed, 17 insertions, 11 deletions
diff --git a/demos/gtk-demo/dnd.c b/demos/gtk-demo/dnd.c index 086836f16a..2373a71f12 100644 --- a/demos/gtk-demo/dnd.c +++ b/demos/gtk-demo/dnd.c @@ -109,15 +109,21 @@ static void apply_transform (CanvasItem *item) { GskTransform *transform; + graphene_rect_t bounds; double x, y; - x = gtk_widget_get_allocated_width (item->label) / 2.0; - y = gtk_widget_get_allocated_height (item->label) / 2.0; - item->r = sqrt (x*x + y*y); + /* Add css padding and margin */ + if (!gtk_widget_compute_bounds (item->label, item->label, &bounds)) + return; + + x = bounds.size.width / 2.; + y = bounds.size.height / 2.; + + item->r = sqrt (x * x + y * y); transform = gsk_transform_translate (NULL, &(graphene_point_t) { item->r, item->r }); transform = gsk_transform_rotate (transform, item->angle + item->delta); - transform = gsk_transform_translate (transform, &(graphene_point_t) { -x, -y }); + transform = gsk_transform_translate (transform, &GRAPHENE_POINT_INIT (-x, -y)); gtk_fixed_set_child_transform (GTK_FIXED (item->fixed), item->label, transform); gsk_transform_unref (transform); diff --git a/demos/gtk-demo/fontplane.c b/demos/gtk-demo/fontplane.c index b8c4f8c87d..038ae68f58 100644 --- a/demos/gtk-demo/fontplane.c +++ b/demos/gtk-demo/fontplane.c @@ -42,8 +42,8 @@ val_to_xy (GtkFontPlane *plane, double u, v; int width, height; - width = gtk_widget_get_allocated_width (GTK_WIDGET (plane)); - height = gtk_widget_get_allocated_height (GTK_WIDGET (plane)); + width = gtk_widget_get_width (GTK_WIDGET (plane)); + height = gtk_widget_get_height (GTK_WIDGET (plane)); u = adjustment_get_normalized_value (plane->width_adj); v = adjustment_get_normalized_value (plane->weight_adj); @@ -62,8 +62,8 @@ plane_snapshot (GtkWidget *widget, cairo_t *cr; val_to_xy (plane, &x, &y); - width = gtk_widget_get_allocated_width (widget); - height = gtk_widget_get_allocated_height (widget); + width = gtk_widget_get_width (widget); + height = gtk_widget_get_height (widget); cr = gtk_snapshot_append_cairo (snapshot, &GRAPHENE_RECT_INIT (0, 0, width, height)); @@ -131,8 +131,8 @@ update_value (GtkFontPlane *plane, GtkWidget *widget = GTK_WIDGET (plane); double u, v; - u = CLAMP (x * (1.0 / gtk_widget_get_allocated_width (widget)), 0, 1); - v = CLAMP (1 - y * (1.0 / gtk_widget_get_allocated_height (widget)), 0, 1); + u = CLAMP (x * (1.0 / gtk_widget_get_width (widget)), 0, 1); + v = CLAMP (1 - y * (1.0 / gtk_widget_get_height (widget)), 0, 1); adjustment_set_normalized_value (plane->width_adj, u); adjustment_set_normalized_value (plane->weight_adj, v); diff --git a/demos/gtk-demo/suggestionentry.c b/demos/gtk-demo/suggestionentry.c index f8a28c8375..d4dd418f20 100644 --- a/demos/gtk-demo/suggestionentry.c +++ b/demos/gtk-demo/suggestionentry.c @@ -471,7 +471,7 @@ suggestion_entry_size_allocate (GtkWidget *widget, &(GtkAllocation) { width - arrow_nat, 0, arrow_nat, height }, baseline); - gtk_widget_set_size_request (self->popup, gtk_widget_get_allocated_width (GTK_WIDGET (self)), -1); + gtk_widget_set_size_request (self->popup, gtk_widget_get_width (GTK_WIDGET (self)), -1); gtk_widget_queue_resize (self->popup); gtk_popover_present (GTK_POPOVER (self->popup)); |