Class RoundedRect

All Implemented Interfaces:
Proxy

@Generated("org.javagi.JavaGI") public class RoundedRect extends ProxyInstance

A rectangular region with rounded corners.

Application code should normalize rectangles using 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.

  • Constructor Details

    • RoundedRect

      public RoundedRect(MemorySegment address)
      Create a RoundedRect proxy instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • RoundedRect

      public RoundedRect(Arena arena)
      Allocate a new RoundedRect.
      Parameters:
      arena - to control the memory allocation scope
    • RoundedRect

      public RoundedRect()
      Allocate a new RoundedRect. The memory is allocated with Arena.ofAuto().
    • RoundedRect

      public RoundedRect(Rect bounds, Size[] corner, Arena arena)
      Allocate a new RoundedRect with the fields set to the provided values.
      Parameters:
      bounds - value for the field bounds
      corner - value for the field corner
      arena - to control the memory allocation scope
    • RoundedRect

      public RoundedRect(Rect bounds, Size[] corner)
      Allocate a new RoundedRect with the fields set to the provided values. The memory is allocated with Arena.ofAuto().
      Parameters:
      bounds - value for the field bounds
      corner - value for the field corner
  • Method Details

    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • readBounds

      public @Nullable Rect readBounds()
      Read the value of the field bounds.
      Returns:
      The value of the field bounds
    • writeBounds

      public void writeBounds(@Nullable Rect bounds)
      Write a value in the field bounds.
      Parameters:
      bounds - The new value for the field bounds
    • readCorner

      public @Nullable Size @Nullable [] readCorner()
      Read the value of the field corner.
      Returns:
      The value of the field corner
    • writeCorner

      public void writeCorner(@Nullable Size @Nullable [] corner, Arena _arena)
      Write a value in the field corner.
      Parameters:
      corner - The new value for the field corner
    • containsPoint

      public boolean containsPoint(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(Rect rect)
      Checks if the given rectangle 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(Rect bounds, Size topLeft, Size topRight, Size bottomRight, Size bottomLeft)

      Initializes a rounded rectangle with the given values.

      This function will implicitly normalize the rounded rectangle before returning.

      Parameters:
      bounds - a graphene_rect_t describing the bounds
      topLeft - the rounding radius of the top left corner
      topRight - the rounding radius of the top right corner
      bottomRight - the rounding radius of the bottom right corner
      bottomLeft - the rounding radius of the bottom left corner
      Returns:
      the initialized rounded rectangle
    • initCopy

      public RoundedRect initCopy(RoundedRect src)

      Initializes a rounded rectangle with a copy.

      This function will not normalize the rounded rectangle, so make sure the source is normalized.

      Parameters:
      src - another rounded rectangle
      Returns:
      the initialized rounded rectangle
    • initFromRect

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

      public boolean intersectsRect(Rect rect)
      Checks if part a rectangle 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 a rounded rectangle are right angles and the rectangle covers all of its bounds.

      This information can be used to decide if ClipNode(RenderNode, Rect) or RoundedClipNode(RenderNode, RoundedRect) should be called.

      Returns:
      true if the rounded rectangle is rectilinear
    • normalize

      public RoundedRect normalize()

      Normalizes a rounded rectangle.

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

      Returns:
      the normalized rounded rectangle
    • offset

      public RoundedRect offset(float dx, float dy)

      Offsets the rounded rectangle's origin by dx and dy.

      The size and corners of the rounded rectangle are unchanged.

      Parameters:
      dx - the horizontal offset
      dy - the vertical offset
      Returns:
      the offset rounded rectangle
    • shrink

      public RoundedRect shrink(float top, float right, float bottom, float left)

      Shrinks (or grows) a rounded 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 rounded 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 rounded rectangle