Class RoundedRect

All Implemented Interfaces:
PointerInterface

public class RoundedRect extends Record
A rectangular region with rounded corners.

Application code should normalize rectangles using
[method@Gsk.RoundedRect.normalize]; this function will ensure that
the bounds of the rectangle are normalized and ensure that the corner
values are positive and the corners do not overlap.

All functions taking a `GskRoundedRect` as an argument will internally
operate on a normalized copy; all functions returning a `GskRoundedRect`
will always return a normalized one.

The algorithm used for normalizing corner sizes is described in
[the CSS specification](https://drafts.csswg.org/css-backgrounds-3/#border-radius).

https://docs.gtk.org/gsk4/struct.RoundedRect.html

  • Field Details

  • Constructor Details

  • Method Details

    • getClassHandler

      public static ClassHandler getClassHandler()
    • containsPoint

      public boolean containsPoint(@Nonnull Point point)
      Checks if the given @point is inside the rounded rectangle.
      Parameters:
      point - the point to check
      Returns:
      %TRUE if the @point is inside the rounded rectangle
    • containsRect

      public boolean containsRect(@Nonnull Rect rect)
      Checks if the given @rect is contained inside the rounded rectangle.
      Parameters:
      rect - the rectangle to check
      Returns:
      %TRUE if the @rect is fully contained inside the rounded rectangle
    • init

      public RoundedRect init(@Nonnull Rect bounds, @Nonnull Size top_left, @Nonnull Size top_right, @Nonnull Size bottom_right, @Nonnull Size bottom_left)
      Initializes the given `GskRoundedRect` with the given values.

      This function will implicitly normalize the `GskRoundedRect`
      before returning.
      Parameters:
      bounds - a `graphene_rect_t` describing the bounds
      top_left - the rounding radius of the top left corner
      top_right - the rounding radius of the top right corner
      bottom_right - the rounding radius of the bottom right corner
      bottom_left - the rounding radius of the bottom left corner
      Returns:
      the initialized rectangle
    • initCopy

      public RoundedRect initCopy(@Nonnull RoundedRect src)
      Initializes @self using the given @src rectangle.

      This function will not normalize the `GskRoundedRect`,
      so make sure the source is normalized.
      Parameters:
      src - a `GskRoundedRect`
      Returns:
      the initialized rectangle
    • initFromRect

      public RoundedRect initFromRect(@Nonnull Rect bounds, float radius)
      Initializes @self to the given @bounds and sets the radius
      of all four corners to @radius.
      Parameters:
      bounds - a `graphene_rect_t`
      radius - the border radius
      Returns:
      the initialized rectangle
    • intersectsRect

      public boolean intersectsRect(@Nonnull Rect rect)
      Checks if part of the given @rect is contained inside the rounded rectangle.
      Parameters:
      rect - the rectangle to check
      Returns:
      %TRUE if the @rect intersects with the rounded rectangle
    • isRectilinear

      public boolean isRectilinear()
      Checks if all corners of @self are right angles and the
      rectangle covers all of its bounds.

      This information can be used to decide if [ctor@Gsk.ClipNode.new]
      or [ctor@Gsk.RoundedClipNode.new] should be called.
      Returns:
      %TRUE if the rectangle is rectilinear
    • normalize

      public RoundedRect normalize()
      Normalizes the passed rectangle.

      This function will ensure that the bounds of the rectangle
      are normalized and ensure that the corner values are positive
      and the corners do not overlap.
      Returns:
      the normalized rectangle
    • offset

      public RoundedRect offset(float dx, float dy)
      Offsets the bound's origin by @dx and @dy.

      The size and corners of the rectangle are unchanged.
      Parameters:
      dx - the horizontal offset
      dy - the vertical offset
      Returns:
      the offset rectangle
    • shrink

      public RoundedRect shrink(float top, float right, float bottom, float left)
      Shrinks (or grows) the given rectangle by moving the 4 sides
      according to the offsets given.

      The corner radii will be changed in a way that tries to keep
      the center of the corner circle intact. This emulates CSS behavior.

      This function also works for growing rectangles if you pass
      negative values for the @top, @right, @bottom or @left.
      Parameters:
      top - How far to move the top side downwards
      right - How far to move the right side to the left
      bottom - How far to move the bottom side upwards
      left - How far to move the left side to the right
      Returns:
      the resized `GskRoundedRect`