[gtk] roundedrect: Mke sure shrinking borders works
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk] roundedrect: Mke sure shrinking borders works
- Date: Thu, 2 May 2019 17:36:11 +0000 (UTC)
commit 8915d6090040f23e3380d0f019884013ae64f12c
Author: Benjamin Otte <otte redhat com>
Date: Thu May 2 19:16:16 2019 +0200
roundedrect: Mke sure shrinking borders works
Previously, when borders were too big - ie when a 100x100 rect had only
one 100x100 border, like the black part of ◔ - and then shrinking this
rect by 25px on either side, we'd end up with a 50x50 rect with a 75x75
border, and that's obviously not correct.
gsk/gskroundedrect.c | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)
---
diff --git a/gsk/gskroundedrect.c b/gsk/gskroundedrect.c
index 6498a7c48c..9a389b2eb7 100644
--- a/gsk/gskroundedrect.c
+++ b/gsk/gskroundedrect.c
@@ -197,9 +197,10 @@ gsk_rounded_rect_offset (GskRoundedRect *self,
}
static void
-border_radius_shrink (graphene_size_t *corner,
- double width,
- double height)
+border_radius_shrink (graphene_size_t *corner,
+ double width,
+ double height,
+ const graphene_size_t *max)
{
if (corner->width > 0)
corner->width -= width;
@@ -211,6 +212,11 @@ border_radius_shrink (graphene_size_t *corner,
corner->width = 0;
corner->height = 0;
}
+ else
+ {
+ corner->width = MIN (corner->width, max->width);
+ corner->height = MIN (corner->height, max->height);
+ }
}
/**
@@ -260,10 +266,10 @@ gsk_rounded_rect_shrink (GskRoundedRect *self,
self->bounds.size.height -= top + bottom;
}
- border_radius_shrink (&self->corner[GSK_CORNER_TOP_LEFT], left, top);
- border_radius_shrink (&self->corner[GSK_CORNER_TOP_RIGHT], right, top);
- border_radius_shrink (&self->corner[GSK_CORNER_BOTTOM_RIGHT], right, bottom);
- border_radius_shrink (&self->corner[GSK_CORNER_BOTTOM_LEFT], left, bottom);
+ border_radius_shrink (&self->corner[GSK_CORNER_TOP_LEFT], left, top, &self->bounds.size);
+ border_radius_shrink (&self->corner[GSK_CORNER_TOP_RIGHT], right, top, &self->bounds.size);
+ border_radius_shrink (&self->corner[GSK_CORNER_BOTTOM_RIGHT], right, bottom, &self->bounds.size);
+ border_radius_shrink (&self->corner[GSK_CORNER_BOTTOM_LEFT], left, bottom, &self->bounds.size);
return self;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]