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.
This commit is contained in:
Benjamin Otte 2019-05-02 19:16:16 +02:00
parent ed52c029a0
commit 8915d60900

View File

@ -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;
}